ui: fullscreen support, default window height

This commit is contained in:
ardocrat
2024-07-01 22:28:09 +03:00
parent 8b0bb2b771
commit 6ef6d48b4a
4 changed files with 58 additions and 22 deletions
+17 -4
View File
@@ -160,9 +160,18 @@ impl Modal {
/// Draw [`egui::Window`] with provided content.
fn window_ui(&self, ctx: &egui::Context, add_content: impl FnOnce(&mut egui::Ui, &Modal)) {
let is_fullscreen = ctx.input(|i| {
i.viewport().fullscreen.unwrap_or(false)
});
let mut rect = ctx.screen_rect();
if View::is_desktop() {
rect = rect.shrink(Root::WINDOW_FRAME_MARGIN - 0.5);
let margin = if !is_fullscreen {
Root::WINDOW_FRAME_MARGIN
} else {
0.0
};
rect = rect.shrink(margin - 0.5);
rect.min += egui::vec2(0.0, Root::WINDOW_TITLE_HEIGHT + 0.5);
rect.max.x += 0.5;
}
@@ -185,7 +194,7 @@ impl Modal {
let width = f32::min(available_width, Self::DEFAULT_WIDTH);
// Show main content Window at given position.
let (content_align, content_offset) = self.modal_position();
let (content_align, content_offset) = self.modal_position(is_fullscreen);
let layer_id = egui::Window::new(format!("modal_window_{}", self.id))
.title_bar(false)
.resizable(false)
@@ -217,14 +226,18 @@ impl Modal {
}
/// Get [`egui::Window`] position based on [`ModalPosition`].
fn modal_position(&self) -> (Align2, Vec2) {
fn modal_position(&self, is_fullscreen: bool) -> (Align2, Vec2) {
let align = match self.position {
ModalPosition::CenterTop => Align2::CENTER_TOP,
ModalPosition::Center => Align2::CENTER_CENTER
};
let x_align = View::get_left_inset() - View::get_right_inset();
let y_align = View::get_top_inset() + Self::DEFAULT_MARGIN + if View::is_desktop() {
Root::WINDOW_TITLE_HEIGHT + Root::WINDOW_FRAME_MARGIN
Root::WINDOW_TITLE_HEIGHT + if !is_fullscreen {
Root::WINDOW_FRAME_MARGIN
} else {
0.0
}
} else {
0.0
};
+4 -1
View File
@@ -150,7 +150,10 @@ impl Root {
let panel_width = if dual_panel {
Self::SIDE_PANEL_WIDTH + View::get_left_inset()
} else {
View::window_size(ui).0 - if View::is_desktop() {
let is_fullscreen = ui.ctx().input(|i| {
i.viewport().fullscreen.unwrap_or(false)
});
View::window_size(ui).0 - if View::is_desktop() && !is_fullscreen {
Self::WINDOW_FRAME_MARGIN * 2.0
} else {
0.0