mirror of
https://github.com/jwinterm/grim.git
synced 2026-11-16 10:43:53 +01:00
android + ui: display cutouts (insets) refactoring, optimize platform-specific app, reorganize views
This commit is contained in:
@@ -17,13 +17,13 @@ use crate::gui::icons::{GLOBE, PLUS};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Root, TitleAction, TitlePanel, View};
|
||||
|
||||
/// Accounts central panel content.
|
||||
pub struct AccountsContent {
|
||||
/// Accounts content.
|
||||
pub struct Accounts {
|
||||
/// List of accounts.
|
||||
list: Vec<String>
|
||||
}
|
||||
|
||||
impl Default for AccountsContent {
|
||||
impl Default for Accounts {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
list: vec![],
|
||||
@@ -31,11 +31,11 @@ impl Default for AccountsContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl AccountsContent {
|
||||
impl Accounts {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
TitlePanel::ui(t!("accounts.title"), if !Root::is_dual_panel_mode(frame) {
|
||||
TitleAction::new(GLOBE, || {
|
||||
Root::toggle_network_panel();
|
||||
Root::toggle_side_panel();
|
||||
})
|
||||
} else {
|
||||
None
|
||||
@@ -12,5 +12,5 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod content;
|
||||
pub use content::*;
|
||||
mod accounts;
|
||||
pub use accounts::*;
|
||||
@@ -20,7 +20,7 @@ use crate::gui::Colors;
|
||||
use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::network::{NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::{Modal, NetworkContent, View};
|
||||
use crate::gui::views::{Modal, Network, View};
|
||||
use crate::node::Node;
|
||||
|
||||
/// Chain metrics tab content.
|
||||
@@ -40,7 +40,7 @@ impl NetworkTab for NetworkMetrics {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show message to enable node when it's not running.
|
||||
if !Node::is_running() {
|
||||
NetworkContent::disabled_node_ui(ui);
|
||||
Network::disabled_node_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ use grin_servers::WorkerStats;
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{BARBELL, CLOCK_AFTERNOON, CPU, CUBE, FADERS, FOLDER_DASHED, FOLDER_NOTCH_MINUS, FOLDER_NOTCH_PLUS, HARD_DRIVES, PLUGS, PLUGS_CONNECTED, POLYGON};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, NetworkContent, View};
|
||||
use crate::gui::views::{Modal, Network, View};
|
||||
use crate::gui::views::network::{NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::network::setup::stratum::StratumSetup;
|
||||
use crate::gui::views::network::setup::StratumSetup;
|
||||
use crate::node::{Node, NodeConfig};
|
||||
|
||||
/// Mining tab content.
|
||||
@@ -41,7 +41,7 @@ impl NetworkTab for NetworkMining {
|
||||
|
||||
// Show message to enable node when it's not running.
|
||||
if !Node::is_running() {
|
||||
NetworkContent::disabled_node_ui(ui);
|
||||
Network::disabled_node_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,20 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod content;
|
||||
mod metrics;
|
||||
mod mining;
|
||||
mod settings;
|
||||
mod node;
|
||||
mod setup;
|
||||
pub use metrics::*;
|
||||
|
||||
pub use content::*;
|
||||
mod mining;
|
||||
pub use mining::*;
|
||||
|
||||
mod settings;
|
||||
pub use settings::*;
|
||||
|
||||
mod node;
|
||||
pub use node::*;
|
||||
|
||||
mod setup;
|
||||
pub use setup::*;
|
||||
|
||||
mod network;
|
||||
pub use network::*;
|
||||
@@ -21,16 +21,8 @@ use crate::AppConfig;
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, POWER};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalContainer, Root, TitlePanel, View};
|
||||
use crate::gui::views::network::setup::dandelion::DandelionSetup;
|
||||
use crate::gui::views::network::setup::node::NodeSetup;
|
||||
use crate::gui::views::network::setup::p2p::P2PSetup;
|
||||
use crate::gui::views::network::setup::pool::PoolSetup;
|
||||
use crate::gui::views::network::setup::stratum::StratumSetup;
|
||||
use crate::gui::views::network::metrics::NetworkMetrics;
|
||||
use crate::gui::views::network::mining::NetworkMining;
|
||||
use crate::gui::views::network::node::NetworkNode;
|
||||
use crate::gui::views::network::settings::NetworkSettings;
|
||||
use crate::gui::views::{Modal, ModalContainer, NetworkMetrics, NetworkMining, NetworkNode, NetworkSettings, Root, TitleAction, TitleContent, TitlePanel, View};
|
||||
use crate::gui::views::network::setup::{DandelionSetup, NodeSetup, P2PSetup, PoolSetup, StratumSetup};
|
||||
use crate::node::Node;
|
||||
|
||||
pub trait NetworkTab {
|
||||
@@ -59,15 +51,15 @@ impl NetworkTabType {
|
||||
}
|
||||
}
|
||||
|
||||
/// Network side panel content.
|
||||
pub struct NetworkContent {
|
||||
/// Network content.
|
||||
pub struct Network {
|
||||
/// Current tab view to show at ui.
|
||||
current_tab: Box<dyn NetworkTab>,
|
||||
/// [`Modal`] ids allowed at this ui container.
|
||||
modal_ids: Vec<&'static str>,
|
||||
}
|
||||
|
||||
impl Default for NetworkContent {
|
||||
impl Default for Network {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
current_tab: Box::new(NetworkNode::default()),
|
||||
@@ -110,13 +102,13 @@ impl Default for NetworkContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl ModalContainer for NetworkContent {
|
||||
impl ModalContainer for Network {
|
||||
fn modal_ids(&self) -> &Vec<&'static str> {
|
||||
self.modal_ids.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkContent {
|
||||
impl Network {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
// Show modal content if it's opened.
|
||||
if self.can_draw_modal() {
|
||||
@@ -140,7 +132,8 @@ impl NetworkContent {
|
||||
|
||||
egui::TopBottomPanel::bottom("network_tabs")
|
||||
.frame(egui::Frame {
|
||||
outer_margin: Margin::same(4.0),
|
||||
fill: Colors::FILL,
|
||||
inner_margin: Margin::same(4.0),
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
@@ -201,31 +194,43 @@ impl NetworkContent {
|
||||
|
||||
/// Draw title content.
|
||||
fn title_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::exact(52.0))
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(52.0))
|
||||
.horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, DOTS_THREE_OUTLINE_VERTICAL, || {
|
||||
//TODO: Show connections
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
self.title_text_ui(builder);
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
if !Root::is_dual_panel_mode(frame) {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, CARDHOLDER, || {
|
||||
Root::toggle_network_panel();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
let title_content = TitleContent::Custom("network_title".to_string(), Box::new(|ui| {
|
||||
}));
|
||||
TitlePanel::test_ui(title_content, TitleAction::new(DOTS_THREE_OUTLINE_VERTICAL, || {
|
||||
//TODO: Show connections
|
||||
}), if !Root::is_dual_panel_mode(frame) {
|
||||
TitleAction::new(CARDHOLDER, || {
|
||||
Root::toggle_side_panel();
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}, ui);
|
||||
|
||||
// StripBuilder::new(ui)
|
||||
// .size(Size::exact(52.0))
|
||||
// .size(Size::remainder())
|
||||
// .size(Size::exact(52.0))
|
||||
// .horizontal(|mut strip| {
|
||||
// strip.cell(|ui| {
|
||||
// ui.centered_and_justified(|ui| {
|
||||
// View::title_button(ui, DOTS_THREE_OUTLINE_VERTICAL, || {
|
||||
// //TODO: Show connections
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// strip.strip(|builder| {
|
||||
// self.title_text_ui(builder);
|
||||
// });
|
||||
// strip.cell(|ui| {
|
||||
// if !Root::is_dual_panel_mode(frame) {
|
||||
// ui.centered_and_justified(|ui| {
|
||||
// View::title_button(ui, CARDHOLDER, || {
|
||||
// Root::toggle_side_panel();
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
}
|
||||
|
||||
/// Draw title text.
|
||||
@@ -20,7 +20,7 @@ use crate::gui::Colors;
|
||||
use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, View};
|
||||
use crate::gui::views::network::{NetworkContent, NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::network::{Network, NetworkTab, NetworkTabType};
|
||||
use crate::node::Node;
|
||||
|
||||
/// Integrated node tab content.
|
||||
@@ -36,7 +36,7 @@ impl NetworkTab for NetworkNode {
|
||||
let server_stats = Node::get_stats();
|
||||
// Show message to enable node when it's not running.
|
||||
if !Node::is_running() {
|
||||
NetworkContent::disabled_node_ui(ui);
|
||||
Network::disabled_node_ui(ui);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,7 @@ use crate::gui::icons::ARROW_COUNTER_CLOCKWISE;
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalPosition, View};
|
||||
use crate::gui::views::network::{NetworkTab, NetworkTabType};
|
||||
use crate::gui::views::network::setup::dandelion::DandelionSetup;
|
||||
use crate::gui::views::network::setup::node::NodeSetup;
|
||||
use crate::gui::views::network::setup::p2p::P2PSetup;
|
||||
use crate::gui::views::network::setup::pool::PoolSetup;
|
||||
use crate::gui::views::network::setup::stratum::StratumSetup;
|
||||
use crate::gui::views::network::setup::{DandelionSetup, NodeSetup, P2PSetup, PoolSetup, StratumSetup};
|
||||
use crate::node::{Node, NodeConfig};
|
||||
|
||||
/// Integrated node settings tab content.
|
||||
|
||||
@@ -12,8 +12,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub mod stratum;
|
||||
pub mod node;
|
||||
pub mod p2p;
|
||||
pub mod pool;
|
||||
pub mod dandelion;
|
||||
mod node;
|
||||
pub use node::NodeSetup;
|
||||
|
||||
mod p2p;
|
||||
pub use p2p::P2PSetup;
|
||||
|
||||
mod pool;
|
||||
pub use pool::PoolSetup;
|
||||
|
||||
mod dandelion;
|
||||
pub use dandelion::DandelionSetup;
|
||||
|
||||
mod stratum;
|
||||
pub use stratum::StratumSetup;
|
||||
@@ -21,7 +21,7 @@ use crate::AppConfig;
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{CLIPBOARD_TEXT, CLOCK_CLOCKWISE, COMPUTER_TOWER, COPY, PLUG, POWER, SHIELD, SHIELD_SLASH};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Modal, ModalPosition, NetworkContent, View};
|
||||
use crate::gui::views::{Modal, ModalPosition, Network, View};
|
||||
use crate::gui::views::network::settings::NetworkSettings;
|
||||
use crate::node::{Node, NodeConfig};
|
||||
|
||||
@@ -115,7 +115,7 @@ impl NodeSetup {
|
||||
// Autorun node setup.
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(6.0);
|
||||
NetworkContent::autorun_node_ui(ui);
|
||||
Network::autorun_node_ui(ui);
|
||||
if Node::is_running() {
|
||||
ui.add_space(2.0);
|
||||
ui.label(RichText::new(t!("network_settings.restart_node_required"))
|
||||
|
||||
+163
-28
@@ -14,84 +14,216 @@
|
||||
|
||||
use std::cmp::min;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use egui::os::OperatingSystem;
|
||||
use egui::RichText;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use crate::gui::App;
|
||||
use crate::gui::app::{get_left_display_cutout, get_right_display_cutout};
|
||||
use crate::gui::Colors;
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{AccountsContent, Modal, NetworkContent};
|
||||
use crate::gui::views::{Accounts, Modal, ModalContainer, Network, View};
|
||||
use crate::node::Node;
|
||||
|
||||
lazy_static! {
|
||||
/// To check if side panel is open from any part of ui.
|
||||
static ref NETWORK_PANEL_OPEN: AtomicBool = AtomicBool::new(false);
|
||||
static ref SIDE_PANEL_OPEN: AtomicBool = AtomicBool::new(false);
|
||||
}
|
||||
|
||||
/// Main ui content, handles network panel state modal state.
|
||||
#[derive(Default)]
|
||||
/// Contains main ui content, handles side panel state.
|
||||
pub struct Root {
|
||||
network: NetworkContent,
|
||||
accounts: AccountsContent,
|
||||
/// Side panel content.
|
||||
side_panel: Network,
|
||||
/// Central panel content.
|
||||
central_content: Accounts,
|
||||
|
||||
/// Check if app exit is allowed on close event of [`eframe::App`] platform implementation.
|
||||
pub(crate) exit_allowed: bool,
|
||||
|
||||
/// Flag to show exit progress at [`Modal`].
|
||||
show_exit_progress: bool,
|
||||
|
||||
/// List of allowed [`Modal`] ids for this [`ModalContainer`].
|
||||
allowed_modal_ids: Vec<&'static str>
|
||||
}
|
||||
|
||||
impl Default for Root {
|
||||
fn default() -> Self {
|
||||
// Exit from eframe only for non-mobile platforms.
|
||||
let os = OperatingSystem::from_target_os();
|
||||
let exit_allowed = os == OperatingSystem::Android || os == OperatingSystem::IOS;
|
||||
Self {
|
||||
side_panel: Network::default(),
|
||||
central_content: Accounts::default(),
|
||||
exit_allowed,
|
||||
show_exit_progress: false,
|
||||
allowed_modal_ids: vec![
|
||||
Self::EXIT_MODAL_ID
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModalContainer for Root {
|
||||
fn modal_ids(&self) -> &Vec<&'static str> {
|
||||
&self.allowed_modal_ids
|
||||
}
|
||||
}
|
||||
|
||||
impl Root {
|
||||
/// Identifier for exit confirmation [`Modal`].
|
||||
pub const EXIT_MODAL_ID: &'static str = "exit_confirmation";
|
||||
|
||||
/// Default width of side panel at application UI.
|
||||
pub const SIDE_PANEL_MIN_WIDTH: i64 = 400;
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
// Show opened exit confirmation Modal content.
|
||||
if self.can_draw_modal() {
|
||||
self.exit_modal_content(ui, frame, cb);
|
||||
}
|
||||
|
||||
// Show network content on side panel.
|
||||
let (is_panel_open, panel_width) = Self::side_panel_state_width(frame);
|
||||
egui::SidePanel::left("network_panel")
|
||||
.resizable(false)
|
||||
.exact_width(panel_width)
|
||||
.frame(egui::Frame::default())
|
||||
.frame(egui::Frame::none())
|
||||
.show_animated_inside(ui, is_panel_open, |ui| {
|
||||
self.network.ui(ui, frame, cb);
|
||||
self.side_panel.ui(ui, frame, cb);
|
||||
});
|
||||
|
||||
// Show accounts content on central panel.
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame::default())
|
||||
.frame(egui::Frame::none())
|
||||
.show_inside(ui, |ui| {
|
||||
self.accounts.ui(ui, frame, cb);
|
||||
self.central_content.ui(ui, frame, cb);
|
||||
});
|
||||
}
|
||||
|
||||
/// Get side panel state and width.
|
||||
fn side_panel_state_width(frame: &mut eframe::Frame) -> (bool, f32) {
|
||||
let dual_panel_mode = Self::is_dual_panel_mode(frame);
|
||||
let is_panel_open = dual_panel_mode || Self::is_network_panel_open();
|
||||
let is_panel_open = dual_panel_mode || Self::is_side_panel_open();
|
||||
let side_cutouts = get_left_display_cutout() + get_right_display_cutout();
|
||||
let panel_width = if dual_panel_mode {
|
||||
min(frame.info().window_info.size.x as i64, Self::SIDE_PANEL_MIN_WIDTH) as f32
|
||||
let available_width = (frame.info().window_info.size.x - side_cutouts) as i64;
|
||||
min(available_width, Self::SIDE_PANEL_MIN_WIDTH) as f32
|
||||
} else {
|
||||
frame.info().window_info.size.x
|
||||
frame.info().window_info.size.x - side_cutouts
|
||||
};
|
||||
(is_panel_open, panel_width)
|
||||
}
|
||||
|
||||
/// Check if ui can show [`NetworkContent`] and [`AccountsContent`] at same time.
|
||||
/// Check if ui can show [`Network`] and [`Accounts`] at same time.
|
||||
pub fn is_dual_panel_mode(frame: &mut eframe::Frame) -> bool {
|
||||
let w = frame.info().window_info.size.x;
|
||||
let h = frame.info().window_info.size.y;
|
||||
// Screen is wide if width is greater than height or just 20% smaller.
|
||||
let is_wide_screen = w > h || w + (w * 0.2) >= h;
|
||||
// Dual panel mode is available when window is wide and its width is at least 2 times
|
||||
// greater than minimal width of the side panel.
|
||||
is_wide_screen && w >= Self::SIDE_PANEL_MIN_WIDTH as f32 * 2.0
|
||||
// greater than minimal width of the side panel plus display cutouts from both sides.
|
||||
let side_cutouts = get_left_display_cutout() + get_right_display_cutout();
|
||||
is_wide_screen && w >= (Self::SIDE_PANEL_MIN_WIDTH as f32 * 2.0) + side_cutouts
|
||||
}
|
||||
|
||||
/// Toggle [`Network`] panel state.
|
||||
pub fn toggle_network_panel() {
|
||||
let is_open = NETWORK_PANEL_OPEN.load(Ordering::Relaxed);
|
||||
NETWORK_PANEL_OPEN.store(!is_open, Ordering::Relaxed);
|
||||
pub fn toggle_side_panel() {
|
||||
let is_open = SIDE_PANEL_OPEN.load(Ordering::Relaxed);
|
||||
SIDE_PANEL_OPEN.store(!is_open, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Check if side panel is open.
|
||||
pub fn is_network_panel_open() -> bool {
|
||||
NETWORK_PANEL_OPEN.load(Ordering::Relaxed)
|
||||
pub fn is_side_panel_open() -> bool {
|
||||
SIDE_PANEL_OPEN.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Handle back button press event.
|
||||
fn on_back() {
|
||||
/// Show exit confirmation modal.
|
||||
pub fn show_exit_modal() {
|
||||
let exit_modal = Modal::new(Self::EXIT_MODAL_ID).title(t!("modal_exit.exit"));
|
||||
Modal::show(exit_modal);
|
||||
}
|
||||
|
||||
/// Draw exit confirmation modal content.
|
||||
fn exit_modal_content(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
frame: &mut eframe::Frame,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
Modal::ui(ui, |ui, modal| {
|
||||
if self.show_exit_progress {
|
||||
if !Node::is_running() {
|
||||
self.exit(frame, cb);
|
||||
modal.close();
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
View::small_loading_spinner(ui);
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new(t!("sync_status.shutdown"))
|
||||
.size(18.0)
|
||||
.color(Colors::TEXT));
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
} else {
|
||||
ui.add_space(8.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new(t!("modal_exit.description"))
|
||||
.size(18.0)
|
||||
.color(Colors::TEXT));
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
|
||||
// Show modal buttons.
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between buttons.
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal_exit.exit"), Colors::WHITE, || {
|
||||
if !Node::is_running() {
|
||||
self.exit(frame, cb);
|
||||
modal.close();
|
||||
} else {
|
||||
Node::stop(true);
|
||||
modal.disable_closing();
|
||||
self.show_exit_progress = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||
modal.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Platform-specific exit from the application.
|
||||
fn exit(&mut self, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
match OperatingSystem::from_target_os() {
|
||||
OperatingSystem::Android => {
|
||||
cb.exit();
|
||||
}
|
||||
OperatingSystem::IOS => {
|
||||
//TODO: exit on iOS.
|
||||
}
|
||||
OperatingSystem::Nix | OperatingSystem::Mac | OperatingSystem::Windows => {
|
||||
self.exit_allowed = true;
|
||||
frame.close();
|
||||
}
|
||||
OperatingSystem::Unknown => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle platform-specific Back key code event.
|
||||
pub fn on_back() {
|
||||
if Modal::on_back() {
|
||||
App::show_exit_modal()
|
||||
Self::show_exit_modal()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,11 +232,14 @@ impl Root {
|
||||
#[cfg(target_os = "android")]
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
/// Handle back button press event from Android.
|
||||
pub extern "C" fn Java_mw_gri_android_MainActivity_onBackButtonPress(
|
||||
/// Handle Back key code event from Android.
|
||||
pub extern "C" fn Java_mw_gri_android_MainActivity_onBack(
|
||||
_env: jni::JNIEnv,
|
||||
_class: jni::objects::JObject,
|
||||
_activity: jni::objects::JObject,
|
||||
) {
|
||||
Root::on_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,20 +30,64 @@ impl TitleAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents title content, can be text or callback to draw custom title.
|
||||
pub enum TitleContent {
|
||||
Text(String),
|
||||
/// First argument is identifier for panel.
|
||||
Custom(String, Box<dyn Fn(&mut egui::Ui)>)
|
||||
}
|
||||
|
||||
pub struct TitlePanel;
|
||||
|
||||
impl TitlePanel {
|
||||
pub const DEFAULT_HEIGHT: f32 = 52.0;
|
||||
|
||||
pub fn test_ui(title: TitleContent, l: Option<TitleAction>, r: Option<TitleAction>, ui: &mut egui::Ui) {
|
||||
let id = match &title {
|
||||
TitleContent::Text(text) => Id::from(text.clone()),
|
||||
TitleContent::Custom(text, _) => Id::from(text.clone())
|
||||
};
|
||||
egui::TopBottomPanel::top(id)
|
||||
.resizable(false)
|
||||
.exact_height(Self::DEFAULT_HEIGHT)
|
||||
.frame(egui::Frame {
|
||||
outer_margin: Margin::same(-1.0),
|
||||
fill: Colors::YELLOW,
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::exact(Self::DEFAULT_HEIGHT))
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(Self::DEFAULT_HEIGHT))
|
||||
.horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
Self::draw_action(ui, l);
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
match title {
|
||||
TitleContent::Text(text) => {
|
||||
Self::draw_title(ui, text);
|
||||
}
|
||||
TitleContent::Custom(_, cb) => {
|
||||
(cb)(ui);
|
||||
}
|
||||
}
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
Self::draw_action(ui, r);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn ui(title: String, l: Option<TitleAction>, r: Option<TitleAction>, ui: &mut egui::Ui) {
|
||||
egui::TopBottomPanel::top(Id::from(title.clone()))
|
||||
.resizable(false)
|
||||
.exact_height(Self::DEFAULT_HEIGHT)
|
||||
.frame(egui::Frame {
|
||||
outer_margin: Margin::same(-1.0),
|
||||
fill: Colors::YELLOW,
|
||||
inner_margin: Margin::same(0.0),
|
||||
outer_margin: Margin::same(0.0),
|
||||
stroke: egui::Stroke::NONE,
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
|
||||
Reference in New Issue
Block a user