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-07-14 00:55:31 +03:00
|
|
|
use egui::Context;
|
2023-04-27 01:28:55 +03:00
|
|
|
|
2023-07-14 00:55:31 +03:00
|
|
|
use crate::gui::Colors;
|
2023-04-27 01:28:55 +03:00
|
|
|
use crate::gui::platform::PlatformCallbacks;
|
2023-07-14 00:55:31 +03:00
|
|
|
use crate::gui::views::Root;
|
2023-04-19 02:14:39 +03:00
|
|
|
|
2023-07-14 00:55:31 +03:00
|
|
|
/// Implements ui entry point and contains platform-specific callbacks.
|
2023-04-18 16:19:43 +03:00
|
|
|
pub struct PlatformApp<Platform> {
|
2023-07-14 00:55:31 +03:00
|
|
|
/// Platform specific callbacks handler.
|
2023-04-18 16:19:43 +03:00
|
|
|
pub(crate) platform: Platform,
|
2023-07-13 03:54:27 +03:00
|
|
|
/// Main ui content.
|
2023-07-14 00:55:31 +03:00
|
|
|
root: Root
|
2023-07-11 23:36:48 +03:00
|
|
|
}
|
|
|
|
|
2023-07-14 00:55:31 +03:00
|
|
|
impl<Platform> PlatformApp<Platform> {
|
|
|
|
pub fn new(platform: Platform) -> Self {
|
|
|
|
Self { platform, root: Root::default() }
|
2023-07-11 23:36:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 00:55:31 +03:00
|
|
|
impl<Platform: PlatformCallbacks> eframe::App for PlatformApp<Platform> {
|
|
|
|
fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
|
|
|
|
// Show main content.
|
2023-04-22 21:16:17 +03:00
|
|
|
egui::CentralPanel::default()
|
2023-06-02 02:05:34 +03:00
|
|
|
.frame(egui::Frame {
|
2023-07-14 03:51:06 +03:00
|
|
|
fill: Colors::YELLOW,
|
2023-07-03 21:17:49 +03:00
|
|
|
..Default::default()
|
2023-04-21 23:59:59 +03:00
|
|
|
})
|
2023-04-22 21:16:17 +03:00
|
|
|
.show(ctx, |ui| {
|
2023-07-14 00:55:31 +03:00
|
|
|
self.root.ui(ui, frame, &self.platform);
|
2023-06-02 21:19:34 +03:00
|
|
|
});
|
2023-04-19 02:14:39 +03:00
|
|
|
}
|
2023-04-21 03:45:59 +03:00
|
|
|
|
2023-07-14 00:55:31 +03:00
|
|
|
fn on_close_event(&mut self) -> bool {
|
|
|
|
Root::show_exit_modal();
|
|
|
|
self.root.exit_allowed
|
2023-07-11 23:36:48 +03:00
|
|
|
}
|
2023-07-14 00:55:31 +03:00
|
|
|
}
|
2023-07-11 23:36:48 +03:00
|
|
|
|
2023-07-14 00:55:31 +03:00
|
|
|
|
|
|
|
|