ui: node content max width

This commit is contained in:
ardocrat 2024-04-22 17:37:58 +03:00
parent cd89b879c6
commit 4b98ce364e
5 changed files with 273 additions and 238 deletions

View file

@ -16,7 +16,7 @@ use egui::{Margin, RichText, ScrollArea, Stroke};
use crate::AppConfig; use crate::AppConfig;
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, PLUS_CIRCLE, POWER}; use crate::gui::icons::{BRIEFCASE, CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, PLUS_CIRCLE, POWER};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{ConnectionsContent, NetworkMetrics, NetworkMining, NetworkNode, NetworkSettings, Root, TitlePanel, View}; use crate::gui::views::{ConnectionsContent, NetworkMetrics, NetworkMining, NetworkNode, NetworkSettings, Root, TitlePanel, View};
use crate::gui::views::network::types::{NetworkTab, NetworkTabType}; use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
@ -64,8 +64,13 @@ impl NetworkContent {
..Default::default() ..Default::default()
}) })
.show_animated_inside(ui, !show_connections, |ui| { .show_animated_inside(ui, !show_connections, |ui| {
ui.vertical_centered(|ui| {
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
// Show tabs content.
self.tabs_ui(ui); self.tabs_ui(ui);
}); });
});
});
// Show current node tab content. // Show current node tab content.
egui::SidePanel::right("node_tab_content_panel") egui::SidePanel::right("node_tab_content_panel")
@ -89,6 +94,7 @@ impl NetworkContent {
..Default::default() ..Default::default()
}) })
.show_inside(ui, |ui| { .show_inside(ui, |ui| {
// Draw node tab content.
self.node_tab_content.ui(ui, frame, cb); self.node_tab_content.ui(ui, frame, cb);
}); });
}); });
@ -148,7 +154,7 @@ impl NetworkContent {
/// Draw tab buttons in the bottom of the screen. /// Draw tab buttons in the bottom of the screen.
fn tabs_ui(&mut self, ui: &mut egui::Ui) { fn tabs_ui(&mut self, ui: &mut egui::Ui) {
ui.scope(|ui| { ui.vertical_centered(|ui| {
// Setup spacing between tabs. // Setup spacing between tabs.
ui.style_mut().spacing.item_spacing = egui::vec2(4.0, 0.0); ui.style_mut().spacing.item_spacing = egui::vec2(4.0, 0.0);
// Setup vertical padding inside tab button. // Setup vertical padding inside tab button.
@ -213,7 +219,7 @@ impl NetworkContent {
} }
}, |ui, frame| { }, |ui, frame| {
if !Root::is_dual_panel_mode(ui) { if !Root::is_dual_panel_mode(ui) {
View::title_button(ui, CARDHOLDER, || { View::title_button(ui, BRIEFCASE, || {
Root::toggle_network_panel(); Root::toggle_network_panel();
}); });
} }

View file

@ -13,12 +13,12 @@
// limitations under the License. // limitations under the License.
use egui::{RichText, Rounding, ScrollArea, vec2}; use egui::{RichText, Rounding, ScrollArea, vec2};
use grin_servers::DiffBlock; use grin_servers::{DiffBlock, ServerStats};
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER}; use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{NetworkContent, View}; use crate::gui::views::{NetworkContent, Root, View};
use crate::gui::views::network::types::{NetworkTab, NetworkTabType}; use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
use crate::node::Node; use crate::node::Node;
@ -56,10 +56,23 @@ impl NetworkTab for NetworkMetrics {
return; return;
} }
let stats = server_stats.as_ref().unwrap();
ui.add_space(1.0); ui.add_space(1.0);
ui.vertical_centered(|ui| {
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
let stats = server_stats.as_ref().unwrap();
// Show emission and difficulty info.
info_ui(ui, stats);
// Show difficulty adjustment window blocks.
blocks_ui(ui, stats);
});
});
}
}
const BLOCK_ITEM_HEIGHT: f32 = 77.0;
/// Draw emission and difficulty info.
fn info_ui(ui: &mut egui::Ui, stats: &ServerStats) {
// Show emission info. // Show emission info.
View::sub_title(ui, format!("{} {}", COINS, t!("network_metrics.emission"))); View::sub_title(ui, format!("{} {}", COINS, t!("network_metrics.emission")));
ui.columns(3, |columns| { ui.columns(3, |columns| {
@ -113,10 +126,12 @@ impl NetworkTab for NetworkMetrics {
[false, true, false, true]); [false, true, false, true]);
}); });
}); });
ui.add_space(4.0); }
// Show difficulty adjustment window blocks. /// Draw difficulty adjustment window blocks content.
fn blocks_ui(ui: &mut egui::Ui, stats: &ServerStats) {
let blocks_size = stats.diff_stats.last_blocks.len(); let blocks_size = stats.diff_stats.last_blocks.len();
ui.add_space(4.0);
ScrollArea::vertical() ScrollArea::vertical()
.id_source("difficulty_scroll") .id_source("difficulty_scroll")
.auto_shrink([false; 2]) .auto_shrink([false; 2])
@ -136,11 +151,8 @@ impl NetworkTab for NetworkMetrics {
} }
}, },
); );
}
} }
const BLOCK_ITEM_HEIGHT: f32 = 77.0;
/// Draw block difficulty item. /// Draw block difficulty item.
fn block_item_ui(ui: &mut egui::Ui, db: &DiffBlock, rounding: Rounding) { fn block_item_ui(ui: &mut egui::Ui, db: &DiffBlock, rounding: Rounding) {
let mut rect = ui.available_rect_before_wrap(); let mut rect = ui.available_rect_before_wrap();

View file

@ -19,7 +19,7 @@ use grin_servers::WorkerStats;
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::{BARBELL, CLOCK_AFTERNOON, CPU, CUBE, FADERS, FOLDER_DASHED, FOLDER_SIMPLE_MINUS, FOLDER_SIMPLE_PLUS, HARD_DRIVES, PLUGS, PLUGS_CONNECTED, POLYGON}; use crate::gui::icons::{BARBELL, CLOCK_AFTERNOON, CPU, CUBE, FADERS, FOLDER_DASHED, FOLDER_SIMPLE_MINUS, FOLDER_SIMPLE_PLUS, HARD_DRIVES, PLUGS, PLUGS_CONNECTED, POLYGON};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{NetworkContent, View}; use crate::gui::views::{NetworkContent, Root, View};
use crate::gui::views::network::setup::StratumSetup; use crate::gui::views::network::setup::StratumSetup;
use crate::gui::views::network::types::{NetworkTab, NetworkTabType}; use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
use crate::node::{Node, NodeConfig}; use crate::node::{Node, NodeConfig};
@ -73,8 +73,12 @@ impl NetworkTab for NetworkMining {
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.add_space(1.0); ui.add_space(1.0);
ui.vertical_centered(|ui| {
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
self.stratum_server_setup.ui(ui, frame, cb); self.stratum_server_setup.ui(ui, frame, cb);
}); });
});
});
return; return;
} }

View file

@ -18,7 +18,7 @@ use grin_servers::PeerStats;
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK}; use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{NetworkContent, View}; use crate::gui::views::{NetworkContent, Root, View};
use crate::gui::views::network::types::{NetworkTab, NetworkTabType}; use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
use crate::node::Node; use crate::node::Node;
@ -45,13 +45,25 @@ impl NetworkTab for NetworkNode {
return; return;
} }
let stats = server_stats.as_ref().unwrap();
ScrollArea::vertical() ScrollArea::vertical()
.id_source("integrated_node") .id_source("integrated_node")
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.add_space(2.0); ui.add_space(2.0);
ui.vertical_centered(|ui| {
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
// Show node stats content.
node_stats_ui(ui);
});
});
});
}
}
/// Draw node statistics content.
fn node_stats_ui(ui: &mut egui::Ui) {
let server_stats = Node::get_stats();
let stats = server_stats.as_ref().unwrap();
// Show header info. // Show header info.
View::sub_title(ui, format!("{} {}", FLOW_ARROW, t!("network_node.header"))); View::sub_title(ui, format!("{} {}", FLOW_ARROW, t!("network_node.header")));
@ -175,8 +187,6 @@ impl NetworkTab for NetworkNode {
} }
} }
} }
});
}
} }
/// Draw connected peer info item. /// Draw connected peer info item.

View file

@ -17,7 +17,7 @@ use egui::{RichText, ScrollArea};
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::ARROW_COUNTER_CLOCKWISE; use crate::gui::icons::ARROW_COUNTER_CLOCKWISE;
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View}; use crate::gui::views::{Modal, Root, View};
use crate::gui::views::network::setup::{DandelionSetup, NodeSetup, P2PSetup, PoolSetup, StratumSetup}; use crate::gui::views::network::setup::{DandelionSetup, NodeSetup, P2PSetup, PoolSetup, StratumSetup};
use crate::gui::views::network::types::{NetworkTab, NetworkTabType}; use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
use crate::gui::views::types::{ModalContainer, ModalPosition}; use crate::gui::views::types::{ModalContainer, ModalPosition};
@ -89,7 +89,8 @@ impl NetworkTab for NetworkSettings {
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.add_space(1.0); ui.add_space(1.0);
ui.vertical_centered(|ui| {
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
// Draw node setup section. // Draw node setup section.
self.node.ui(ui, frame, cb); self.node.ui(ui, frame, cb);
@ -128,6 +129,8 @@ impl NetworkTab for NetworkSettings {
// Draw reset settings content. // Draw reset settings content.
reset_settings_ui(ui); reset_settings_ui(ui);
}); });
});
});
} }
} }