build: optimize imports

This commit is contained in:
ardocrat 2023-06-15 23:54:41 +03:00
parent ba4c1da1f4
commit b91bc2f7e7
9 changed files with 21 additions and 23 deletions

View file

@ -20,17 +20,20 @@ use crate::gui::platform::PlatformCallbacks;
use crate::gui::screens::Root; use crate::gui::screens::Root;
use crate::node::Node; use crate::node::Node;
/// To be implemented by platform-specific application.
pub struct PlatformApp<Platform> { pub struct PlatformApp<Platform> {
pub(crate) app: App, pub(crate) app: App,
pub(crate) platform: Platform, pub(crate) platform: Platform,
} }
#[derive(Default)] #[derive(Default)]
/// Contains main screen panel and ui setup.
pub struct App { pub struct App {
root: Root, root: Root,
} }
impl App { impl App {
/// Draw content on main screen panel.
pub fn ui(&mut self, ctx: &Context, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) { pub fn ui(&mut self, ctx: &Context, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(egui::Frame { .frame(egui::Frame {
@ -42,6 +45,7 @@ impl App {
}); });
} }
/// Exit from the app.
pub fn exit(frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) { pub fn exit(frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
match OperatingSystem::from_target_os() { match OperatingSystem::from_target_os() {
OperatingSystem::Android => { OperatingSystem::Android => {
@ -58,6 +62,7 @@ impl App {
} }
} }
/// Setup application styles.
pub fn setup_visuals(ctx: &Context) { pub fn setup_visuals(ctx: &Context) {
// Setup style // Setup style
let mut style = (*ctx.style()).clone(); let mut style = (*ctx.style()).clone();
@ -78,6 +83,7 @@ impl App {
ctx.set_visuals(visuals); ctx.set_visuals(visuals);
} }
/// Setup application fonts.
pub fn setup_fonts(ctx: &Context) { pub fn setup_fonts(ctx: &Context) {
use egui::FontFamily::Proportional; use egui::FontFamily::Proportional;
@ -137,6 +143,7 @@ impl App {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[no_mangle] #[no_mangle]
/// Calling when back button is pressed on Android.
pub extern "C" fn Java_mw_gri_android_MainActivity_onBackButtonPress( pub extern "C" fn Java_mw_gri_android_MainActivity_onBackButtonPress(
_env: jni::JNIEnv, _env: jni::JNIEnv,
_class: jni::objects::JObject, _class: jni::objects::JObject,

View file

@ -154,15 +154,14 @@ impl Navigator {
} }
// Check if Modal is open. // Check if Modal is open.
let mut is_open = false; let is_open = {
{
let r_nav = NAVIGATOR_STATE.read().unwrap(); 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::Global => { r_nav.global_modal.as_ref().unwrap().is_open() }
ModalLocation::SidePanel => { r_nav.side_panel_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() } ModalLocation::Screen => {r_nav.screen_modal.as_ref().unwrap().is_open() }
}; }
} };
// If Modal is not open, remove it from navigator state. // If Modal is not open, remove it from navigator state.
if !is_open { if !is_open {

View file

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
use std::sync::atomic::{AtomicI32, Ordering}; use std::sync::atomic::{AtomicI32, Ordering};
use eframe::epaint::Stroke;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use winit::platform::android::activity::AndroidApp; use winit::platform::android::activity::AndroidApp;

View file

@ -14,7 +14,7 @@
use std::cmp::min; use std::cmp::min;
use egui::{RichText, Spinner, Widget}; use egui::{Spinner, Widget};
use crate::gui::{App, Colors, Navigator}; use crate::gui::{App, Colors, Navigator};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;

View file

@ -15,12 +15,10 @@
use std::cmp::min; use std::cmp::min;
use std::sync::atomic::{AtomicBool, Ordering}; 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::epaint::RectShape;
use egui::style::Margin;
use egui_extras::{Size, StripBuilder};
use crate::gui::Colors;
use crate::gui::Colors;
use crate::gui::views::View; use crate::gui::views::View;
/// Identifier for [`Modal`] content to draw at [`Modal::ui`]. /// Identifier for [`Modal`] content to draw at [`Modal::ui`].

View file

@ -18,10 +18,9 @@ use egui::{Color32, lerp, Rgba, RichText, Stroke};
use egui::style::Margin; use egui::style::Margin;
use egui_extras::{Size, StripBuilder}; use egui_extras::{Size, StripBuilder};
use grin_chain::SyncStatus; 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::{Colors, Navigator};
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, POWER};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{NetworkTab, View}; use crate::gui::views::{NetworkTab, View};
use crate::gui::views::network_metrics::NetworkMetrics; use crate::gui::views::network_metrics::NetworkMetrics;
@ -244,7 +243,7 @@ impl Network {
ui.add_space(10.0); ui.add_space(10.0);
View::button(ui, format!("{} {}", POWER, t!("network.enable")), Colors::GOLD, || { View::button(ui, format!("{} {}", POWER, t!("network.enable")), Colors::GOLD, || {
Node::start(ChainTypes::Mainnet); Node::start();
}); });
}); });
} }

View file

@ -15,11 +15,10 @@
use chrono::{DateTime, NaiveDateTime, Utc}; use chrono::{DateTime, NaiveDateTime, Utc};
use eframe::epaint::{Color32, Rounding, Stroke}; use eframe::epaint::{Color32, Rounding, Stroke};
use egui::{RichText, ScrollArea, Spinner, Widget}; use egui::{RichText, ScrollArea, Spinner, Widget};
use grin_core::global::ChainTypes;
use grin_servers::DiffBlock; use grin_servers::DiffBlock;
use crate::gui::Colors; 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::gui::views::{Network, NetworkTab, View};
use crate::node::Node; use crate::node::Node;

View file

@ -14,12 +14,10 @@
use eframe::epaint::Stroke; use eframe::epaint::Stroke;
use egui::{Color32, RichText, Rounding, ScrollArea, Spinner, Widget}; use egui::{Color32, RichText, Rounding, ScrollArea, Spinner, Widget};
use egui_extras::{Size, StripBuilder};
use grin_core::global::ChainTypes;
use grin_servers::PeerStats; 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::gui::views::{Network, NetworkTab, View};
use crate::node::Node; use crate::node::Node;

View file

@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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::{Color32, FontId, RectShape, Rounding, Stroke};
use egui::epaint::text::TextWrapping; use egui::epaint::text::TextWrapping;
use egui::text::{LayoutJob, TextFormat}; use egui::text::{LayoutJob, TextFormat};
use egui_extras::{Size, StripBuilder};
use crate::gui::Colors; use crate::gui::Colors;
@ -127,7 +126,7 @@ impl View {
/// | VALUE | /// | VALUE |
/// | label | /// | label |
pub fn rounded_box(ui: &mut egui::Ui, value: String, label: String, r: [bool; 4]) { 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. // Create background shape.
let mut bg_shape = RectShape { let mut bg_shape = RectShape {