fix: XvB tab fix UI overlapping, better placement of widget.

This commit is contained in:
Louis-Marie Baer 2024-03-19 13:16:34 +01:00
parent 255c183c10
commit 05d4a1141f

View file

@ -1,9 +1,8 @@
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use egui::TextStyle::{self, Name}; use egui::TextStyle::{self, Name};
use egui::{vec2, Hyperlink, Image, RichText, TextEdit, Ui, Vec2}; use egui::{vec2, Image, RichText, TextEdit, Ui, Vec2};
use log::debug; use log::debug;
use readable::byte::Byte;
use readable::num::Float; use readable::num::Float;
use crate::helper::xvb::PubXvbApi; use crate::helper::xvb::PubXvbApi;
@ -32,22 +31,24 @@ impl crate::disk::state::Xvb {
) { ) {
let website_height = size.y / 10.0; let website_height = size.y / 10.0;
let width = size.x; let width = size.x;
let height = size.y;
let space_h = height / 48.0;
// logo and website link // logo and website link
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.add_sized( ui.add_sized(
[width, website_height], [width, website_height],
Image::from_bytes("bytes:/xvb.png", BYTES_XVB), Image::from_bytes("bytes:/xvb.png", BYTES_XVB),
); );
ui.add_sized( ui.style_mut().override_text_style = Some(TextStyle::Heading);
[width / 8.0, website_height], ui.add_space(space_h);
Hyperlink::from_label_and_url("XMRvsBeast", XVB_URL), ui.hyperlink_to("XMRvsBeast", XVB_URL);
); ui.add_space(space_h);
}); });
// console output for log // console output for log
debug!("XvB Tab | Rendering [Console]"); debug!("XvB Tab | Rendering [Console]");
ui.group(|ui| { ui.group(|ui| {
let height = size.y / 2.8; let height = size.y / 2.8;
let width = size.x - SPACE; let width = size.x - space_h;
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| { egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into())); ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
egui::ScrollArea::vertical() egui::ScrollArea::vertical()
@ -83,37 +84,42 @@ impl crate::disk::state::Xvb {
RED, RED,
) )
}; };
ui.add_space(SPACE * 2.0); ui.add_space(space_h);
ui.group(|ui| { ui.horizontal(|ui| {
ui.colored_label(color, text); ui.group(|ui| {
ui.add( ui.colored_label(color, text);
TextEdit::singleline(&mut self.token) ui.add(
.char_limit(XVB_TOKEN_LEN) TextEdit::singleline(&mut self.token)
.desired_width(ui.text_style_height(&TextStyle::Small) * XVB_TOKEN_LEN as f32) .char_limit(9)
.vertical_align(egui::Align::Center), .desired_width(ui.text_style_height(&TextStyle::Body) * 9.0)
); .vertical_align(egui::Align::Center),
}) )
.response .on_hover_text_at_pointer(XVB_HELP)
.on_hover_text_at_pointer(XVB_HELP); })
ui.add_space(SPACE * 2.0); .response
ui.checkbox(&mut self.hero, "Hero") .on_hover_text_at_pointer(XVB_HELP);
.on_hover_text(XVB_HERO_SELECT); ui.add_space(height / 48.0);
// need to warn the user if no address is set in p2pool tab ui.style_mut().spacing.icon_width_inner = width / 45.0;
ui.style_mut().spacing.icon_width = width / 35.0;
ui.style_mut().spacing.icon_spacing = space_h;
ui.checkbox(&mut self.hero, "Hero Mode").on_hover_text(XVB_HERO_SELECT);
// need to warn the user if no address is set in p2pool tab
if !Regexes::addr_ok(address) { if !Regexes::addr_ok(address) {
ui.add_space(width / 16.0);
debug!("XvB Tab | Rendering warning text"); debug!("XvB Tab | Rendering warning text");
ui.label(RichText::new("You don't have any payout address set in the P2pool Tab !\nXvB process needs one to function properly.") ui.horizontal_wrapped(|ui|{
ui.label(RichText::new("You don't have any payout address set in the P2pool Tab ! XvB process needs one to function properly.")
.color(ORANGE)); .color(ORANGE));
});
} }
});
// private stats // private stats
let priv_stats = &lock!(api).stats_priv; ui.add_space(space_h);
// ui.vertical_centered(|ui| {
ui.add_enabled_ui(private_stats, |ui| { ui.add_enabled_ui(private_stats, |ui| {
ui.add_space(SPACE * 2.0);
ui.horizontal(|ui| { ui.horizontal(|ui| {
// widget takes a third less space for two separator. let priv_stats = &lock!(api).stats_priv;
let width_stat = (ui.available_width() / 5.0) let width_stat = (ui.available_width() - SPACE * 4.0) / 5.0;
- ((24.0 + ui.style().spacing.item_spacing.x + SPACE) / 5.0);
// 0.0 means minimum
let height_stat = 0.0; let height_stat = 0.0;
let size_stat = vec2(width_stat, height_stat); let size_stat = vec2(width_stat, height_stat);
let round = match &priv_stats.round_participate { let round = match &priv_stats.round_participate {
@ -192,10 +198,12 @@ impl crate::disk::state::Xvb {
}); });
}); });
// Rules link help // Rules link help
ui.add_space(ui.available_height() / 2.0); ui.horizontal_centered(|ui| {
ui.vertical_centered(|ui| { // can't have horizontal and vertical centering work together so fix by this.
ui.add_space((width /2.0)-(ui.text_style_height( &TextStyle::Heading) * 1.5 ));
ui.style_mut().override_text_style = Some(TextStyle::Heading);
ui.hyperlink_to("Rules", XVB_URL_RULES) ui.hyperlink_to("Rules", XVB_URL_RULES)
.on_hover_text("Click here to read the rules and understand how the raffle works."); .on_hover_text("Click here to read the rules and understand how the raffle works.");
}); });
} }
} }