mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
add global scale, add 3 panels with sizing: top/bottom, mid
This commit is contained in:
parent
14a5538173
commit
6a1db35c10
2 changed files with 125 additions and 99 deletions
|
@ -2,6 +2,7 @@
|
||||||
* [Structure](#Structure)
|
* [Structure](#Structure)
|
||||||
* [Bootstrap](#Bootstrap)
|
* [Bootstrap](#Bootstrap)
|
||||||
* [State](#State)
|
* [State](#State)
|
||||||
|
* [Scale](#Scale)
|
||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
| File/Folder | Purpose |
|
| File/Folder | Purpose |
|
||||||
|
@ -48,3 +49,14 @@ Internal state is saved in the "OS data folder" as `gupax.toml`, using the [TOML
|
||||||
| Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Roaming\Gupax\gupax.toml |
|
| Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Roaming\Gupax\gupax.toml |
|
||||||
| macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support/Gupax/gupax.toml |
|
| macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support/Gupax/gupax.toml |
|
||||||
| Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share/gupax/gupax.toml |
|
| Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share/gupax/gupax.toml |
|
||||||
|
|
||||||
|
## Scale
|
||||||
|
Every frame, the max available `[width, height]` are calculated, and those are used as a baseline for the Top/Bottom bars, containing the tabs and status bar. After that, all available space is given to the middle ui elements. The scale is calculated every frame so that all elements can scale immediately as the user adjusts it; this doesn't take as much CPU as you might think since frames are only rendered on user interaction. Some elements are subtracted a fixed number because the `ui.seperator()`s add some fixed space which needs to be accounted for.
|
||||||
|
|
||||||
|
```
|
||||||
|
Main [App] outer frame (default: [1280.0, 720.0])
|
||||||
|
├─ Inner frame (1264.0, 704.0)
|
||||||
|
├─ TopPanel = [width: (max-90.0)/5.0, height: max/10.0]
|
||||||
|
├─ BottomPanel = [width: max, height: max/15.0]
|
||||||
|
├─ CentralPanel = [width: (max/8.0), height: the rest
|
||||||
|
```
|
||||||
|
|
108
src/main.rs
108
src/main.rs
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Imports
|
//---------------------------------------------------------------------------------------------------- Imports
|
||||||
// egui/eframe
|
// egui/eframe
|
||||||
|
use egui::Ui;
|
||||||
use egui::TextStyle::*;
|
use egui::TextStyle::*;
|
||||||
use egui::color::Color32;
|
use egui::color::Color32;
|
||||||
use egui::FontFamily::Proportional;
|
use egui::FontFamily::Proportional;
|
||||||
|
@ -62,6 +63,8 @@ pub struct App {
|
||||||
ping: bool, // Was the ping button clicked?
|
ping: bool, // Was the ping button clicked?
|
||||||
pinging: Arc<Mutex<bool>>, // Is a ping in progress?
|
pinging: Arc<Mutex<bool>>, // Is a ping in progress?
|
||||||
node: Arc<Mutex<NodeStruct>>, // Data on community nodes
|
node: Arc<Mutex<NodeStruct>>, // Data on community nodes
|
||||||
|
width: f32, // Top-level width
|
||||||
|
height: f32, // Top-level height
|
||||||
// State:
|
// State:
|
||||||
// og = Old state to compare against
|
// og = Old state to compare against
|
||||||
// state = Working state (current settings)
|
// state = Working state (current settings)
|
||||||
|
@ -105,6 +108,8 @@ impl App {
|
||||||
quit_confirm: false,
|
quit_confirm: false,
|
||||||
ping: false,
|
ping: false,
|
||||||
pinging: Arc::new(Mutex::new(false)),
|
pinging: Arc::new(Mutex::new(false)),
|
||||||
|
width: 1280.0,
|
||||||
|
height: 720.0,
|
||||||
node: Arc::new(Mutex::new(NodeStruct::default())),
|
node: Arc::new(Mutex::new(NodeStruct::default())),
|
||||||
og: State::default(),
|
og: State::default(),
|
||||||
state: State::default(),
|
state: State::default(),
|
||||||
|
@ -336,19 +341,45 @@ impl eframe::App for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||||
|
// This sets the top level Ui dimensions.
|
||||||
|
// Used as a reference for other uis.
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| { self.width = ui.available_width(); self.height = ui.available_height(); });
|
||||||
|
// This sets fonts globally depending on the width.
|
||||||
|
init_text_styles(ctx, self.width);
|
||||||
|
|
||||||
// Close confirmation.
|
// Close confirmation.
|
||||||
if self.quit {
|
if self.quit {
|
||||||
|
egui::TopBottomPanel::bottom("quit").show(ctx, |ui| {
|
||||||
|
let width = self.width;
|
||||||
|
let height = self.height/8.0;
|
||||||
|
ui.group(|ui| {
|
||||||
|
if ui.add_sized([width, height], egui::Button::new("Yes")).clicked() {
|
||||||
|
if self.state.gupax.save_before_quit {
|
||||||
|
info!("Saving before quit...");
|
||||||
|
match self.state.save() {
|
||||||
|
Err(err) => { error!("{}", err); exit(1); },
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
info!("Quit confirmation = yes ... goodbye!");
|
||||||
|
self.quit_confirm = true;
|
||||||
|
exit(0);
|
||||||
|
} else if ui.add_sized([width, height], egui::Button::new("No")).clicked() {
|
||||||
|
self.quit = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
init_text_styles(ctx, ui.available_width());
|
let width = self.width;
|
||||||
let width = ui.available_width();
|
|
||||||
let width = width - 10.0;
|
|
||||||
let height = ui.available_height();
|
let height = ui.available_height();
|
||||||
|
let ten = height/10.0;
|
||||||
// Detect processes or update
|
// Detect processes or update
|
||||||
|
ui.add_space(ten);
|
||||||
if self.p2pool || self.xmrig || self.updating {
|
if self.p2pool || self.xmrig || self.updating {
|
||||||
ui.add_sized([width, height/6.0], Label::new("Are you sure you want to quit?"));
|
ui.add_sized([width, height/4.0], Label::new("Are you sure you want to quit?"));
|
||||||
if self.updating { ui.add_sized([width, height/9.0], Label::new("Update is in progress...!")); }
|
if self.updating { ui.add_sized([width, ten], Label::new("Update is in progress...!")); }
|
||||||
if self.p2pool { ui.add_sized([width, height/9.0], Label::new("P2Pool is online...!")); }
|
if self.p2pool { ui.add_sized([width, ten], Label::new("P2Pool is online...!")); }
|
||||||
if self.xmrig { ui.add_sized([width, height/9.0], Label::new("XMRig is online...!")); }
|
if self.xmrig { ui.add_sized([width, ten], Label::new("XMRig is online...!")); }
|
||||||
// Else, just quit
|
// Else, just quit
|
||||||
} else {
|
} else {
|
||||||
if self.state.gupax.save_before_quit {
|
if self.state.gupax.save_before_quit {
|
||||||
|
@ -361,46 +392,15 @@ impl eframe::App for App {
|
||||||
info!("No processes or update in progress ... goodbye!");
|
info!("No processes or update in progress ... goodbye!");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
egui::TopBottomPanel::bottom("quit").show(ctx, |ui| {
|
|
||||||
ui.group(|ui| {
|
|
||||||
if ui.add_sized([width, height/8.0], egui::Button::new("Yes")).clicked() {
|
|
||||||
if self.state.gupax.save_before_quit {
|
|
||||||
info!("Saving before quit...");
|
|
||||||
match self.state.save() {
|
|
||||||
Err(err) => { error!("{}", err); exit(1); },
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
info!("Quit confirmation = yes ... goodbye!");
|
|
||||||
self.quit_confirm = true;
|
|
||||||
exit(0);
|
|
||||||
} else if ui.add_sized([width, height/8.0], egui::Button::new("No")).clicked() {
|
|
||||||
self.quit = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If ping was pressed, start thread
|
|
||||||
if self.ping {
|
|
||||||
self.ping = false;
|
|
||||||
self.pinging = Arc::new(Mutex::new(true));
|
|
||||||
let node_clone = Arc::clone(&self.node);
|
|
||||||
let pinging_clone = Arc::clone(&self.pinging);
|
|
||||||
thread::spawn(move|| {
|
|
||||||
let result = NodeStruct::ping();
|
|
||||||
*node_clone.lock().unwrap() = result.nodes;
|
|
||||||
*pinging_clone.lock().unwrap() = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top: Tabs
|
// Top: Tabs
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::TopBottomPanel::top("top").show(ctx, |ui| {
|
||||||
init_text_styles(ctx, ui.available_width());
|
let width = (self.width - 95.0)/5.0;
|
||||||
let width = (ui.available_width() - 90.0) / 5.0;
|
let height = self.height/10.0;
|
||||||
let height = ui.available_height() / 10.0;
|
ui.group(|ui| {
|
||||||
ui.add_space(4.0);
|
ui.add_space(4.0);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.style_mut().override_text_style = Some(Name("Tab".into()));
|
ui.style_mut().override_text_style = Some(Name("Tab".into()));
|
||||||
|
@ -420,17 +420,17 @@ impl eframe::App for App {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.add_sized([width, height], egui::SelectableLabel::new(self.tab == Tab::Xmrig, "XMRig")).clicked() { self.tab = Tab::Xmrig; }
|
if ui.add_sized([width, height], egui::SelectableLabel::new(self.tab == Tab::Xmrig, "XMRig")).clicked() { self.tab = Tab::Xmrig; }
|
||||||
});
|
});
|
||||||
ui.add_space(3.0);
|
ui.add_space(4.0);
|
||||||
ui.separator();
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
let height = height / 2.0;
|
|
||||||
// Bottom: app info + state/process buttons
|
// Bottom: app info + state/process buttons
|
||||||
egui::TopBottomPanel::bottom("bottom").show(ctx, |ui| {
|
egui::TopBottomPanel::bottom("bottom").show(ctx, |ui| {
|
||||||
|
let width = self.width/8.0;
|
||||||
|
let height = self.height/15.0;
|
||||||
ui.style_mut().override_text_style = Some(Name("Bottom".into()));
|
ui.style_mut().override_text_style = Some(Name("Bottom".into()));
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = width / 2.0;
|
|
||||||
ui.add_sized([width, height], Label::new(&*self.name_version));
|
ui.add_sized([width, height], Label::new(&*self.name_version));
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.add_sized([width, height], Label::new(self.os));
|
ui.add_sized([width, height], Label::new(self.os));
|
||||||
|
@ -502,6 +502,20 @@ impl eframe::App for App {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If ping was pressed, start thread
|
||||||
|
if self.ping {
|
||||||
|
self.ping = false;
|
||||||
|
self.pinging = Arc::new(Mutex::new(true));
|
||||||
|
let node_clone = Arc::clone(&self.node);
|
||||||
|
let pinging_clone = Arc::clone(&self.pinging);
|
||||||
|
thread::spawn(move|| {
|
||||||
|
let result = NodeStruct::ping();
|
||||||
|
*node_clone.lock().unwrap() = result.nodes;
|
||||||
|
*pinging_clone.lock().unwrap() = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Body);
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Body);
|
||||||
match self.tab {
|
match self.tab {
|
||||||
Tab::About => {
|
Tab::About => {
|
||||||
|
|
Loading…
Reference in a new issue