grim/src/gui/app.rs

102 lines
3.2 KiB
Rust
Raw Normal View History

2023-04-12 21:52:35 +03:00
// Copyright 2023 The Grim Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
2023-04-27 01:28:55 +03:00
use std::cmp::min;
use eframe::Frame;
2023-04-27 01:28:55 +03:00
use egui::{Color32, Context, Stroke};
use egui::epaint::Shadow;
use egui::style::Margin;
use wgpu::Color;
2023-04-27 01:28:55 +03:00
use crate::gui::COLOR_YELLOW;
use crate::gui::platform::PlatformCallbacks;
use crate::gui::screens::{Root, Screen};
2023-04-18 16:19:43 +03:00
pub struct PlatformApp<Platform> {
2023-04-27 01:28:55 +03:00
pub(crate) app: App,
2023-04-18 16:19:43 +03:00
pub(crate) platform: Platform,
}
2023-04-27 01:28:55 +03:00
pub struct App {
root: Root,
network_panel_open: bool
}
2023-04-27 01:28:55 +03:00
impl Default for App {
fn default() -> Self {
2023-04-27 01:28:55 +03:00
Self {
root: Root::default(),
network_panel_open: false
}
}
2023-04-27 01:28:55 +03:00
}
2023-04-27 01:28:55 +03:00
impl App {
pub fn ui(&mut self, ctx: &Context, frame: &mut Frame, cb: &dyn PlatformCallbacks) {
2023-04-27 01:28:55 +03:00
let network_panel_open = self.network_panel_open || dual_panel_available(frame);
egui::CentralPanel::default()
2023-04-21 23:59:59 +03:00
.frame(egui::Frame {
inner_margin: Margin::same(0.0),
outer_margin: Margin::same(0.0),
fill: COLOR_YELLOW,
.. Default::default()
2023-04-21 23:59:59 +03:00
})
.show(ctx, |ui| {
2023-04-27 01:28:55 +03:00
egui::SidePanel::left("network_panel")
.resizable(false)
2023-04-27 01:28:55 +03:00
.exact_width(if dual_panel_available(frame) {
min(frame.info().window_info.size.x as i64, 500) as f32
} else {
2023-04-27 01:28:55 +03:00
frame.info().window_info.size.x
})
.frame(egui::Frame {
inner_margin: Margin::same(0.0),
outer_margin: Margin::same(0.0),
rounding: Default::default(),
shadow: Shadow::NONE,
fill: COLOR_YELLOW,
stroke: Stroke::NONE,
})
2023-04-27 01:28:55 +03:00
.show_animated_inside(ui, network_panel_open, |ui| {
//TODO: Network content
ui.vertical_centered(|ui| {
ui.heading("🖧 Node");
});
2023-04-21 23:59:59 +03:00
ui.separator();
});
2023-04-21 23:59:59 +03:00
2023-04-27 01:28:55 +03:00
egui::CentralPanel::default().frame(egui::containers::Frame {
inner_margin: Margin::same(3.0),
stroke: Stroke::new(1.0, Color32::from_gray(5)),
..Default::default()
}).show_inside(ui, |ui| {
2023-04-27 02:05:07 +03:00
self.root.ui(ui, cb);
2023-04-27 01:28:55 +03:00
});
});
}
}
2023-04-27 01:28:55 +03:00
pub fn dual_panel_available(frame: &mut Frame) -> bool {
is_landscape(frame) && frame.info().window_info.size.x > 500.0
}
pub fn is_landscape(frame: &mut Frame) -> bool {
return frame.info().window_info.size.x > frame.info().window_info.size.y
}