2023-04-27 01:28:55 +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.
|
|
|
|
|
|
|
|
use egui::style::Margin;
|
|
|
|
use egui_extras::{Size, StripBuilder};
|
2023-05-04 20:09:26 +03:00
|
|
|
|
2023-06-03 11:22:51 +03:00
|
|
|
use crate::gui::Colors;
|
2023-05-18 03:53:38 +03:00
|
|
|
use crate::gui::views::View;
|
2023-04-27 01:28:55 +03:00
|
|
|
|
2023-07-04 01:28:27 +03:00
|
|
|
pub struct TitleAction {
|
2023-07-03 21:17:49 +03:00
|
|
|
pub(crate) icon: Box<&'static str>,
|
2023-05-23 23:45:16 +03:00
|
|
|
pub(crate) on_click: Box<dyn Fn()>,
|
|
|
|
}
|
|
|
|
|
2023-07-04 01:28:27 +03:00
|
|
|
impl TitleAction {
|
2023-07-03 21:17:49 +03:00
|
|
|
pub fn new(icon: &'static str, on_click: fn()) -> Option<Self> {
|
2023-06-02 02:05:34 +03:00
|
|
|
Option::from(Self { icon: Box::new(icon), on_click: Box::new(on_click) })
|
2023-05-23 23:45:16 +03:00
|
|
|
}
|
2023-04-27 01:28:55 +03:00
|
|
|
}
|
|
|
|
|
2023-07-04 01:28:27 +03:00
|
|
|
pub struct TitlePanel;
|
2023-04-27 01:28:55 +03:00
|
|
|
|
2023-05-23 23:45:16 +03:00
|
|
|
impl TitlePanel {
|
2023-07-04 01:28:27 +03:00
|
|
|
pub const DEFAULT_HEIGHT: f32 = 52.0;
|
2023-04-27 21:49:37 +03:00
|
|
|
|
2023-07-04 01:28:27 +03:00
|
|
|
pub fn ui(title: String, l: Option<TitleAction>, r: Option<TitleAction>, ui: &mut egui::Ui) {
|
2023-04-27 01:28:55 +03:00
|
|
|
egui::TopBottomPanel::top("title_panel")
|
|
|
|
.resizable(false)
|
|
|
|
.frame(egui::Frame {
|
2023-06-03 11:22:51 +03:00
|
|
|
fill: Colors::YELLOW,
|
2023-04-27 01:28:55 +03:00
|
|
|
inner_margin: Margin::same(0.0),
|
|
|
|
outer_margin: Margin::same(0.0),
|
2023-06-02 02:05:34 +03:00
|
|
|
stroke: egui::Stroke::NONE,
|
2023-04-27 01:28:55 +03:00
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.show_inside(ui, |ui| {
|
|
|
|
StripBuilder::new(ui)
|
2023-07-04 01:28:27 +03:00
|
|
|
.size(Size::exact(Self::DEFAULT_HEIGHT))
|
2023-04-27 01:28:55 +03:00
|
|
|
.vertical(|mut strip| {
|
|
|
|
strip.strip(|builder| {
|
|
|
|
builder
|
2023-07-04 01:28:27 +03:00
|
|
|
.size(Size::exact(Self::DEFAULT_HEIGHT))
|
2023-04-27 01:28:55 +03:00
|
|
|
.size(Size::remainder())
|
2023-07-04 01:28:27 +03:00
|
|
|
.size(Size::exact(Self::DEFAULT_HEIGHT))
|
2023-04-27 01:28:55 +03:00
|
|
|
.horizontal(|mut strip| {
|
|
|
|
strip.cell(|ui| {
|
2023-07-04 01:28:27 +03:00
|
|
|
Self::draw_action(ui, l);
|
2023-04-27 01:28:55 +03:00
|
|
|
});
|
2023-06-02 02:05:34 +03:00
|
|
|
strip.cell(|ui| {
|
2023-07-04 01:28:27 +03:00
|
|
|
Self::draw_title(ui, title);
|
2023-04-27 01:28:55 +03:00
|
|
|
});
|
|
|
|
strip.cell(|ui| {
|
2023-07-04 01:28:27 +03:00
|
|
|
Self::draw_action(ui, r);
|
2023-04-27 01:28:55 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2023-05-04 20:09:26 +03:00
|
|
|
|
2023-07-04 01:28:27 +03:00
|
|
|
fn draw_action(ui: &mut egui::Ui, action: Option<TitleAction>) {
|
2023-06-03 11:22:51 +03:00
|
|
|
if action.is_some() {
|
|
|
|
let action = action.unwrap();
|
|
|
|
ui.centered_and_justified(|ui| {
|
|
|
|
View::title_button(ui, &action.icon, || {
|
|
|
|
(action.on_click)();
|
|
|
|
});
|
2023-05-17 00:36:59 +03:00
|
|
|
});
|
2023-06-03 11:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-04 01:28:27 +03:00
|
|
|
fn draw_title(ui: &mut egui::Ui, title: String) {
|
2023-07-07 03:50:08 +03:00
|
|
|
ui.add_space(2.0);
|
2023-06-03 11:22:51 +03:00
|
|
|
ui.centered_and_justified(|ui| {
|
2023-07-04 01:28:27 +03:00
|
|
|
View::ellipsize_text(ui, title.to_uppercase(), 20.0, Colors::TITLE);
|
2023-05-18 03:53:38 +03:00
|
|
|
});
|
2023-05-17 00:36:59 +03:00
|
|
|
}
|
2023-05-18 03:53:38 +03:00
|
|
|
}
|