From a5ba9660b36b7079a19139ec5b05d17e436d55ad Mon Sep 17 00:00:00 2001 From: ardocrat Date: Wed, 19 Apr 2023 02:14:39 +0300 Subject: [PATCH] gui: initial environment to draw content --- Cargo.lock | 253 +----------------- app/src/main/AndroidManifest.xml | 2 +- src/grim.rs | 2 +- src/gui/app.rs | 36 ++- src/gui/mod.rs | 17 +- src/gui/platform/android/mod.rs | 87 +++--- src/gui/platform/mod.rs | 3 +- src/gui/{views => screens}/mod.rs | 8 +- src/gui/{views/main.rs => screens/wallets.rs} | 31 +++ 9 files changed, 143 insertions(+), 296 deletions(-) rename src/gui/{views => screens}/mod.rs (85%) rename src/gui/{views/main.rs => screens/wallets.rs} (51%) diff --git a/Cargo.lock b/Cargo.lock index 27a5475..61feb9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,57 +26,7 @@ checksum = "3083ac5a97521e35388ca80cf365b6be5210962cc59f11ee238cd92ac2fa9524" dependencies = [ "enumset", "kurbo", -] - -[[package]] -name = "accesskit_consumer" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f47393f706a2d2f9d1ebd109351f886afd256a09d2308861a6dec0853a625e2" -dependencies = [ - "accesskit", - "parking_lot 0.12.1", -] - -[[package]] -name = "accesskit_macos" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabafb94d8a4dd6b20fe4112f943756ff8dc9778e3d742fb5478bf7f000a3282" -dependencies = [ - "accesskit", - "accesskit_consumer", - "objc2", - "once_cell", - "parking_lot 0.12.1", -] - -[[package]] -name = "accesskit_windows" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662496f45a2e2ddff05e28d0a9fc2b319cc4f886d3664e3469c3d30800598962" -dependencies = [ - "accesskit", - "accesskit_consumer", - "arrayvec 0.7.2", - "once_cell", - "parking_lot 0.12.1", - "paste", - "windows 0.42.0", -] - -[[package]] -name = "accesskit_winit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f270416d033ab5b2a8fa72a976dfdad0db1ea194721f16cadbdb45ff219779f" -dependencies = [ - "accesskit", - "accesskit_macos", - "accesskit_windows", - "parking_lot 0.12.1", - "winit", + "serde", ] [[package]] @@ -113,6 +63,7 @@ checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ "cfg-if 1.0.0", "once_cell", + "serde", "version_check", ] @@ -395,25 +346,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-sys" -version = "0.1.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" -dependencies = [ - "objc-sys", -] - -[[package]] -name = "block2" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" -dependencies = [ - "block-sys", - "objc2-encode", -] - [[package]] name = "built" version = "0.6.0" @@ -535,15 +467,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" -[[package]] -name = "cgl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" -dependencies = [ - "libc", -] - [[package]] name = "chrono" version = "0.4.24" @@ -1024,6 +947,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b601108bca3af7650440ace4ca55b2daf52c36f2635be3587d77b16efd8d0691" dependencies = [ "bytemuck", + "serde", ] [[package]] @@ -1036,9 +960,6 @@ dependencies = [ "egui", "egui-wgpu", "egui-winit", - "egui_glow", - "glow", - "glutin", "js-sys", "percent-encoding", "raw-window-handle 0.5.2", @@ -1060,6 +981,7 @@ dependencies = [ "ahash 0.8.3", "epaint", "nohash-hasher", + "serde", "tracing", ] @@ -1084,7 +1006,6 @@ version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5696bdbe60898b81157f07ae34fe02dbfd522174bd6e620942c269cd7307901f" dependencies = [ - "accesskit_winit", "arboard", "egui", "instant", @@ -1103,6 +1024,7 @@ dependencies = [ "egui", "egui_extras", "enum-map", + "serde", "tracing", "unicode_names2", ] @@ -1117,21 +1039,6 @@ dependencies = [ "serde", ] -[[package]] -name = "egui_glow" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d4b5960cb1bae1c403a6c9027a745210a41913433b10c73b6e7d76a1017f8b4" -dependencies = [ - "bytemuck", - "egui", - "glow", - "memoffset", - "tracing", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "emath" version = "0.20.0" @@ -1139,6 +1046,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5277249c8c3430e7127e4f2c40a77485e7baf11ae132ce9b3253a8ed710df0a0" dependencies = [ "bytemuck", + "serde", ] [[package]] @@ -1178,6 +1086,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19be8061a06ab6f3a6cf21106c873578bf01bd42ad15e0311a9c76161cb1c753" dependencies = [ "enumset_derive", + "serde", ] [[package]] @@ -1232,6 +1141,7 @@ dependencies = [ "emath", "nohash-hasher", "parking_lot 0.12.1", + "serde", ] [[package]] @@ -1596,17 +1506,6 @@ dependencies = [ "url", ] -[[package]] -name = "gl_generator" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" -dependencies = [ - "khronos_api", - "log", - "xml-rs", -] - [[package]] name = "glob" version = "0.3.1" @@ -1625,58 +1524,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "glutin" -version = "0.30.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89bab9ec7715de13d5d5402238e66f48e3a5ae636ebb45aba4013c962e2ff15" -dependencies = [ - "bitflags 1.3.2", - "cfg_aliases", - "cgl", - "core-foundation 0.9.3", - "dispatch", - "glutin_egl_sys", - "glutin_glx_sys", - "glutin_wgl_sys", - "libloading", - "objc2", - "once_cell", - "raw-window-handle 0.5.2", - "wayland-sys 0.30.1", - "windows-sys 0.45.0", - "x11-dl", -] - -[[package]] -name = "glutin_egl_sys" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5aaf0abb5c4148685b33101ae326a207946b4d3764d6cdc79f8316cdaa8367d" -dependencies = [ - "gl_generator", - "windows-sys 0.45.0", -] - -[[package]] -name = "glutin_glx_sys" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b53cb5fe568964aa066a3ba91eac5ecbac869fb0842cd0dc9e412434f1a1494" -dependencies = [ - "gl_generator", - "x11-dl", -] - -[[package]] -name = "glutin_wgl_sys" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef89398e90033fc6bc65e9bd42fd29bbbfd483bda5b56dc5562f455550618165" -dependencies = [ - "gl_generator", -] - [[package]] name = "gpu-alloc" version = "0.5.3" @@ -2189,7 +2036,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows 0.48.0", + "windows", ] [[package]] @@ -2358,12 +2205,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "khronos_api" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" - [[package]] name = "kurbo" version = "0.8.3" @@ -2371,6 +2212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a53776d271cfb873b17c618af0298445c88afc52837f3e948fa3fafd131f449" dependencies = [ "arrayvec 0.7.2", + "serde", ] [[package]] @@ -2959,32 +2801,6 @@ dependencies = [ "objc_id", ] -[[package]] -name = "objc-sys" -version = "0.2.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" - -[[package]] -name = "objc2" -version = "0.3.0-beta.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe31e5425d3d0b89a15982c024392815da40689aceb34bad364d58732bcfd649" -dependencies = [ - "block2", - "objc-sys", - "objc2-encode", -] - -[[package]] -name = "objc2-encode" -version = "2.0.0-pre.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" -dependencies = [ - "objc-sys", -] - [[package]] name = "objc_exception" version = "0.1.2" @@ -3140,12 +2956,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - [[package]] name = "pbkdf2" version = "0.8.0" @@ -4528,7 +4338,7 @@ dependencies = [ "scoped-tls", "wayland-commons", "wayland-scanner", - "wayland-sys 0.29.5", + "wayland-sys", ] [[package]] @@ -4540,7 +4350,7 @@ dependencies = [ "nix 0.24.3", "once_cell", "smallvec", - "wayland-sys 0.29.5", + "wayland-sys", ] [[package]] @@ -4588,18 +4398,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "wayland-sys" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b2a02ac608e07132978689a6f9bf4214949c85998c247abadd4f4129b1aa06" -dependencies = [ - "dlib", - "lazy_static", - "log", - "pkg-config", -] - [[package]] name = "web-sys" version = "0.3.61" @@ -4792,22 +4590,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0286ba339aa753e70765d521bb0242cc48e1194562bfa2a2ad7ac8a6de28f5d5" -dependencies = [ - "windows-implement", - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows" version = "0.48.0" @@ -4817,17 +4599,6 @@ dependencies = [ "windows-targets 0.48.0", ] -[[package]] -name = "windows-implement" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9539b6bd3eadbd9de66c9666b22d802b833da7e996bc06896142e09854a61767" -dependencies = [ - "proc-macro2 1.0.56", - "quote 1.0.26", - "syn 1.0.109", -] - [[package]] name = "windows-sys" version = "0.36.1" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2a4053a..4c12508 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ diff --git a/src/grim.rs b/src/grim.rs index 568f4fc..84c8c25 100644 --- a/src/grim.rs +++ b/src/grim.rs @@ -39,7 +39,7 @@ unsafe fn android_main(app: AndroidApp) { builder.with_android_app(app); })); - use crate::gui::platform::app::Android; + use crate::gui::platform::Android; start(options, Box::new(|_cc| Box::new( PlatformApp::new(_cc, Android::new(_app)) ))); diff --git a/src/gui/app.rs b/src/gui/app.rs index dddeebe..afc74af 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -12,8 +12,40 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::any::Any; +use eframe::Frame; +use egui::Context; +use crate::gui::PlatformCallbacks; +use crate::gui::screens::{Screen}; + pub struct PlatformApp { - pub(crate) root: egui_demo_lib::DemoWindows, - // root: super::views::main + pub(crate) screens: Screens, pub(crate) platform: Platform, +} + +pub struct Screens { + screens: Vec>, + current: String, +} + +impl Default for Screens { + fn default() -> Self { + Self::from_screens(vec![ + Box::new(super::screens::Wallets::default()) + ]) + } +} + +impl Screens { + pub fn from_screens(screens: Vec>) -> Self { + let current = screens[0].name().to_string(); + Self { + screens, + current, + } + } + + pub fn ui(&mut self, ctx: &Context, frame: &mut Frame, cb: &dyn PlatformCallbacks) { + + } } \ No newline at end of file diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 3ebb6ee..226acda 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -13,7 +13,18 @@ // limitations under the License. mod app; -pub use crate::gui::app::PlatformApp; +pub use app::PlatformApp; -pub mod views; -pub mod platform; \ No newline at end of file +pub mod screens; +pub mod platform; + +pub trait Ui { + fn ui(&mut self, ui: &mut egui::Ui); +} + +pub trait PlatformCallbacks { + fn show_keyboard(&mut self); + fn hide_keyboard(&mut self); + fn copy_string_to_buffer(&mut self, data: String); + fn get_string_from_buffer(&mut self) -> String; +} \ No newline at end of file diff --git a/src/gui/platform/android/mod.rs b/src/gui/platform/android/mod.rs index d5d7f34..4c351a7 100644 --- a/src/gui/platform/android/mod.rs +++ b/src/gui/platform/android/mod.rs @@ -14,11 +14,14 @@ use egui::{Color32, FontTweak, Visuals}; use egui::epaint::Shadow; -use jni::objects::{JObject, JPrimitiveArray}; -use crate::gui::PlatformApp; +use jni::objects::{JObject, JPrimitiveArray}; use winit::platform::android::activity::AndroidApp; +use crate::gui::{PlatformApp, PlatformCallbacks}; +use crate::gui::app::Screens; + +#[derive(Clone)] pub struct Android { pub android_app: AndroidApp, pub cutouts: [i32; 4], @@ -27,7 +30,7 @@ pub struct Android { impl Android { pub fn new(app: AndroidApp) -> Self { - Android { + Self { android_app: app, cutouts: Default::default(), window_size: Default::default() @@ -35,35 +38,29 @@ impl Android { } } +impl PlatformCallbacks for Android { + fn show_keyboard(&mut self) { + self.android_app.show_soft_input(true); + } + + fn hide_keyboard(&mut self) { + self.android_app.hide_soft_input(true); + } + + fn copy_string_to_buffer(&mut self, data: String) { + + } + + fn get_string_from_buffer(&mut self) -> String { + "".to_string() + } +} + impl PlatformApp { pub fn new(cc: &eframe::CreationContext<'_>, platform: Android) -> Self { setup_fonts(&cc.egui_ctx); - // cc.egui_ctx.set_visuals(Visuals { - // dark_mode: false, - // override_text_color: None, - // widgets: Default::default(), - // selection: Default::default(), - // hyperlink_color: Default::default(), - // faint_bg_color: Default::default(), - // extreme_bg_color: Default::default(), - // code_bg_color: Default::default(), - // warn_fg_color: Default::default(), - // error_fg_color: Default::default(), - // window_rounding: Default::default(), - // window_shadow: Default::default(), - // window_fill: Default::default(), - // window_stroke: Default::default(), - // panel_fill: Default::default(), - // popup_shadow: Default::default(), - // resize_corner_size: 0.0, - // text_cursor_width: 0.0, - // text_cursor_preview: false, - // clip_rect_margin: 0.0, - // button_frame: false, - // collapsing_header_frame: false, - // }); Self { - root: Default::default(), + screens: Screens::default(), platform, } } @@ -91,9 +88,6 @@ fn setup_fonts(ctx: &egui::Context) { impl eframe::App for PlatformApp { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { - println!("12345 - X {}", frame.info().window_info.size.x); - println!("12345 - Y {}", frame.info().window_info.size.y); - let _x = frame.info().window_info.size.x; let _y = frame.info().window_info.size.y; if _x != self.platform.window_size[0] || _y != self.platform.window_size[1] { @@ -102,10 +96,11 @@ impl eframe::App for PlatformApp { self.platform.cutouts = get_display_cutouts(&self.platform.android_app); } + let is_dark = ctx.style().visuals.dark_mode; egui::TopBottomPanel::top("top_padding_panel") .frame(egui::Frame { shadow: Shadow::NONE, - fill: Color32::TRANSPARENT, + fill: if is_dark {Color32::BLACK} else {Color32::WHITE}, ..Default::default() }) .show_separator_line(false) @@ -113,21 +108,10 @@ impl eframe::App for PlatformApp { .exact_height(self.platform.cutouts[0] as f32) .show(ctx, |ui| {}); - egui::SidePanel::right("right_padding_panel") - .frame(egui::Frame { - shadow: Shadow::NONE, - fill: Color32::TRANSPARENT, - ..Default::default() - }) - .show_separator_line(false) - .resizable(false) - .default_width(self.platform.cutouts[1] as f32) - .show(ctx, |ui| {}); - egui::TopBottomPanel::bottom("bottom_padding_panel") .frame(egui::Frame { shadow: Shadow::NONE, - fill: Color32::TRANSPARENT, + fill: if is_dark {Color32::BLACK} else {Color32::WHITE}, ..Default::default() }) .show_separator_line(false) @@ -135,10 +119,21 @@ impl eframe::App for PlatformApp { .exact_height(self.platform.cutouts[2] as f32) .show(ctx, |ui| {}); + egui::SidePanel::right("right_padding_panel") + .frame(egui::Frame { + shadow: Shadow::NONE, + fill: if is_dark {Color32::BLACK} else {Color32::WHITE}, + ..Default::default() + }) + .show_separator_line(false) + .resizable(false) + .default_width(self.platform.cutouts[1] as f32) + .show(ctx, |ui| {}); + egui::SidePanel::left("left_padding_panel") .frame(egui::Frame { shadow: Shadow::NONE, - fill: Color32::TRANSPARENT, + fill: if is_dark {Color32::BLACK} else {Color32::WHITE}, ..Default::default() }) .show_separator_line(false) @@ -147,7 +142,7 @@ impl eframe::App for PlatformApp { .show(ctx, |ui| {}); egui::CentralPanel::default().show(ctx, |ui| { - self.root.ui(ctx); + self.screens.ui(ctx, frame, &self.platform); }); } } diff --git a/src/gui/platform/mod.rs b/src/gui/platform/mod.rs index 81f07e5..7af878b 100644 --- a/src/gui/platform/mod.rs +++ b/src/gui/platform/mod.rs @@ -11,10 +11,11 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +pub use self::platform::*; #[cfg(target_os = "android")] #[path = "android/mod.rs"] -pub mod app; +pub mod platform; #[cfg(not(target_os = "android"))] #[path = "desktop/mod.rs"] pub mod app; diff --git a/src/gui/views/mod.rs b/src/gui/screens/mod.rs similarity index 85% rename from src/gui/views/mod.rs rename to src/gui/screens/mod.rs index 81e68b2..92447da 100644 --- a/src/gui/views/mod.rs +++ b/src/gui/screens/mod.rs @@ -11,4 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -pub mod main; + +mod wallets; +pub use wallets::Wallets; + +pub trait Screen { + fn name(&self) -> &'static str; +} diff --git a/src/gui/views/main.rs b/src/gui/screens/wallets.rs similarity index 51% rename from src/gui/views/main.rs rename to src/gui/screens/wallets.rs index 6ddbed9..ec8b8bb 100644 --- a/src/gui/views/main.rs +++ b/src/gui/screens/wallets.rs @@ -12,3 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. +use egui::ScrollArea; +use crate::gui::Ui; + +pub struct Wallets { +} + +impl Default for Wallets { + fn default() -> Self { + Self { + + } + } +} + +impl Ui for Wallets { + fn ui(&mut self, ui: &mut egui::Ui) { + ScrollArea::vertical() + .auto_shrink([false; 2]) + .show(ui, |ui| { + for item in 1..=50 { + ui.heading(format!("This is future Wallet {}", item)); + } + }); + } +} + +impl super::Screen for Wallets { + fn name(&self) -> &'static str { + "Wallets" + } +} \ No newline at end of file