From b91bc2f7e7e8e018d5120f2be1d20326107a7e36 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 15 Jun 2023 23:54:41 +0300 Subject: [PATCH] build: optimize imports --- src/gui/app.rs | 7 +++++++ src/gui/navigator.rs | 9 ++++----- src/gui/platform/android/mod.rs | 1 - src/gui/screens/root.rs | 2 +- src/gui/views/modal.rs | 6 ++---- src/gui/views/network.rs | 5 ++--- src/gui/views/network_metrics.rs | 3 +-- src/gui/views/network_node.rs | 6 ++---- src/gui/views/views.rs | 5 ++--- 9 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/gui/app.rs b/src/gui/app.rs index a229169..0f2e265 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -20,17 +20,20 @@ use crate::gui::platform::PlatformCallbacks; use crate::gui::screens::Root; use crate::node::Node; +/// To be implemented by platform-specific application. pub struct PlatformApp { pub(crate) app: App, pub(crate) platform: Platform, } #[derive(Default)] +/// Contains main screen panel and ui setup. pub struct App { root: Root, } impl App { + /// Draw content on main screen panel. pub fn ui(&mut self, ctx: &Context, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) { egui::CentralPanel::default() .frame(egui::Frame { @@ -42,6 +45,7 @@ impl App { }); } + /// Exit from the app. pub fn exit(frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) { match OperatingSystem::from_target_os() { OperatingSystem::Android => { @@ -58,6 +62,7 @@ impl App { } } + /// Setup application styles. pub fn setup_visuals(ctx: &Context) { // Setup style let mut style = (*ctx.style()).clone(); @@ -78,6 +83,7 @@ impl App { ctx.set_visuals(visuals); } + /// Setup application fonts. pub fn setup_fonts(ctx: &Context) { use egui::FontFamily::Proportional; @@ -137,6 +143,7 @@ impl App { #[cfg(target_os = "android")] #[allow(non_snake_case)] #[no_mangle] +/// Calling when back button is pressed on Android. pub extern "C" fn Java_mw_gri_android_MainActivity_onBackButtonPress( _env: jni::JNIEnv, _class: jni::objects::JObject, diff --git a/src/gui/navigator.rs b/src/gui/navigator.rs index b85b8d1..be39d75 100644 --- a/src/gui/navigator.rs +++ b/src/gui/navigator.rs @@ -154,15 +154,14 @@ impl Navigator { } // Check if Modal is open. - let mut is_open = false; - { + let is_open = { let r_nav = NAVIGATOR_STATE.read().unwrap(); - is_open = match location { + match location { ModalLocation::Global => { r_nav.global_modal.as_ref().unwrap().is_open() } ModalLocation::SidePanel => { r_nav.side_panel_modal.as_ref().unwrap().is_open() } ModalLocation::Screen => {r_nav.screen_modal.as_ref().unwrap().is_open() } - }; - } + } + }; // If Modal is not open, remove it from navigator state. if !is_open { diff --git a/src/gui/platform/android/mod.rs b/src/gui/platform/android/mod.rs index 94909d8..fdb5a97 100644 --- a/src/gui/platform/android/mod.rs +++ b/src/gui/platform/android/mod.rs @@ -13,7 +13,6 @@ // limitations under the License. use std::sync::atomic::{AtomicI32, Ordering}; -use eframe::epaint::Stroke; use lazy_static::lazy_static; use winit::platform::android::activity::AndroidApp; diff --git a/src/gui/screens/root.rs b/src/gui/screens/root.rs index 762ba24..90f118b 100644 --- a/src/gui/screens/root.rs +++ b/src/gui/screens/root.rs @@ -14,7 +14,7 @@ use std::cmp::min; -use egui::{RichText, Spinner, Widget}; +use egui::{Spinner, Widget}; use crate::gui::{App, Colors, Navigator}; use crate::gui::platform::PlatformCallbacks; diff --git a/src/gui/views/modal.rs b/src/gui/views/modal.rs index c274b3e..b106ee0 100644 --- a/src/gui/views/modal.rs +++ b/src/gui/views/modal.rs @@ -15,12 +15,10 @@ use std::cmp::min; use std::sync::atomic::{AtomicBool, Ordering}; -use egui::{Align2, RichText, Rounding, Sense, Separator, Stroke, Vec2, Widget}; +use egui::{Align2, RichText, Rounding, Sense, Stroke, Vec2}; use egui::epaint::RectShape; -use egui::style::Margin; -use egui_extras::{Size, StripBuilder}; -use crate::gui::Colors; +use crate::gui::Colors; use crate::gui::views::View; /// Identifier for [`Modal`] content to draw at [`Modal::ui`]. diff --git a/src/gui/views/network.rs b/src/gui/views/network.rs index 51fb30b..949998b 100644 --- a/src/gui/views/network.rs +++ b/src/gui/views/network.rs @@ -18,10 +18,9 @@ use egui::{Color32, lerp, Rgba, RichText, Stroke}; use egui::style::Margin; use egui_extras::{Size, StripBuilder}; use grin_chain::SyncStatus; -use grin_core::global::ChainTypes; -use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, PLUGS, POWER}; use crate::gui::{Colors, Navigator}; +use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, POWER}; use crate::gui::platform::PlatformCallbacks; use crate::gui::views::{NetworkTab, View}; use crate::gui::views::network_metrics::NetworkMetrics; @@ -244,7 +243,7 @@ impl Network { ui.add_space(10.0); View::button(ui, format!("{} {}", POWER, t!("network.enable")), Colors::GOLD, || { - Node::start(ChainTypes::Mainnet); + Node::start(); }); }); } diff --git a/src/gui/views/network_metrics.rs b/src/gui/views/network_metrics.rs index 561cf61..adec76d 100644 --- a/src/gui/views/network_metrics.rs +++ b/src/gui/views/network_metrics.rs @@ -15,11 +15,10 @@ use chrono::{DateTime, NaiveDateTime, Utc}; use eframe::epaint::{Color32, Rounding, Stroke}; use egui::{RichText, ScrollArea, Spinner, Widget}; -use grin_core::global::ChainTypes; use grin_servers::DiffBlock; use crate::gui::Colors; -use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, PLUGS, POWER, TIMER}; +use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER}; use crate::gui::views::{Network, NetworkTab, View}; use crate::node::Node; diff --git a/src/gui/views/network_node.rs b/src/gui/views/network_node.rs index 59996ec..32183ea 100644 --- a/src/gui/views/network_node.rs +++ b/src/gui/views/network_node.rs @@ -14,12 +14,10 @@ use eframe::epaint::Stroke; use egui::{Color32, RichText, Rounding, ScrollArea, Spinner, Widget}; -use egui_extras::{Size, StripBuilder}; -use grin_core::global::ChainTypes; use grin_servers::PeerStats; -use crate::gui::Colors; -use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS, PLUGS_CONNECTED, POWER, SHARE_NETWORK}; +use crate::gui::Colors; +use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK}; use crate::gui::views::{Network, NetworkTab, View}; use crate::node::Node; diff --git a/src/gui/views/views.rs b/src/gui/views/views.rs index ef3ee17..f4a0991 100644 --- a/src/gui/views/views.rs +++ b/src/gui/views/views.rs @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use egui::{Button, PointerState, Response, RichText, Sense, Vec2, Widget}; +use egui::{Button, PointerState, Response, RichText, Sense, Widget}; use egui::epaint::{Color32, FontId, RectShape, Rounding, Stroke}; use egui::epaint::text::TextWrapping; use egui::text::{LayoutJob, TextFormat}; -use egui_extras::{Size, StripBuilder}; use crate::gui::Colors; @@ -127,7 +126,7 @@ impl View { /// | VALUE | /// | label | pub fn rounded_box(ui: &mut egui::Ui, value: String, label: String, r: [bool; 4]) { - let mut rect = ui.available_rect_before_wrap(); + let rect = ui.available_rect_before_wrap(); // Create background shape. let mut bg_shape = RectShape {