gui: initial environment to draw content

This commit is contained in:
ardocrat
2023-04-19 02:14:39 +03:00
parent 18e0d6d500
commit a5ba9660b3
9 changed files with 143 additions and 296 deletions
+1 -1
View File
@@ -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))
)));
+34 -2
View File
@@ -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<Platform> {
pub(crate) root: egui_demo_lib::DemoWindows,
// root: super::views::main
pub(crate) screens: Screens,
pub(crate) platform: Platform,
}
pub struct Screens {
screens: Vec<Box<dyn Screen>>,
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<Box<dyn Screen>>) -> Self {
let current = screens[0].name().to_string();
Self {
screens,
current,
}
}
pub fn ui(&mut self, ctx: &Context, frame: &mut Frame, cb: &dyn PlatformCallbacks) {
}
}
+14 -3
View File
@@ -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;
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;
}
+41 -46
View File
@@ -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<Android> {
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<Android> {
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<Android> {
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<Android> {
.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<Android> {
.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<Android> {
.show(ctx, |ui| {});
egui::CentralPanel::default().show(ctx, |ui| {
self.root.ui(ctx);
self.screens.ui(ctx, frame, &self.platform);
});
}
}
+2 -1
View File
@@ -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;
@@ -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;
}
@@ -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"
}
}