From 6ef6d48b4a53f63ea83d1f9958f4e29f541ca11f Mon Sep 17 00:00:00 2001 From: ardocrat Date: Mon, 1 Jul 2024 22:28:09 +0300 Subject: [PATCH] ui: fullscreen support, default window height --- src/gui/app.rs | 52 +++++++++++++++++++++++++++++------------- src/gui/views/modal.rs | 21 +++++++++++++---- src/gui/views/root.rs | 5 +++- src/settings/config.rs | 2 +- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/gui/app.rs b/src/gui/app.rs index 5480eae..5edd974 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -91,10 +91,20 @@ impl App { /// Draw custom resizeable window content. fn desktop_window_ui(&mut self, ui: &mut egui::Ui) { + let is_fullscreen = ui.ctx().input(|i| { + i.viewport().fullscreen.unwrap_or(false) + }); + let title_stroke_rect = { - let mut rect = ui.max_rect().shrink(Root::WINDOW_FRAME_MARGIN); - rect.max.y = Root::WINDOW_FRAME_MARGIN + Root::WINDOW_TITLE_HEIGHT + - TitlePanel::DEFAULT_HEIGHT + 0.5; + let mut rect = ui.max_rect(); + if !is_fullscreen { + rect = rect.shrink(Root::WINDOW_FRAME_MARGIN); + } + rect.max.y = if !is_fullscreen { + Root::WINDOW_FRAME_MARGIN + } else { + 0.0 + } + Root::WINDOW_TITLE_HEIGHT + TitlePanel::DEFAULT_HEIGHT + 0.5; rect }; let title_stroke = RectShape { @@ -118,7 +128,10 @@ impl App { ui.painter().add(title_stroke); let content_stroke_rect = { - let mut rect = ui.max_rect().shrink(Root::WINDOW_FRAME_MARGIN); + let mut rect = ui.max_rect(); + if !is_fullscreen { + rect = rect.shrink(Root::WINDOW_FRAME_MARGIN); + } let top = Root::WINDOW_TITLE_HEIGHT + TitlePanel::DEFAULT_HEIGHT + 0.5; rect.min += egui::vec2(0.0, top); rect @@ -139,20 +152,25 @@ impl App { ui.painter().add(content_stroke); // Draw window content. - let content_rect = ui.max_rect().shrink(Root::WINDOW_FRAME_MARGIN); + let mut content_rect = ui.max_rect(); + if !is_fullscreen { + content_rect = content_rect.shrink(Root::WINDOW_FRAME_MARGIN); + } ui.allocate_ui_at_rect(content_rect, |ui| { self.window_content(ui); }); // Setup resize areas. - self.resize_area_ui(ui, ResizeDirection::North); - self.resize_area_ui(ui, ResizeDirection::East); - self.resize_area_ui(ui, ResizeDirection::South); - self.resize_area_ui(ui, ResizeDirection::West); - self.resize_area_ui(ui, ResizeDirection::NorthWest); - self.resize_area_ui(ui, ResizeDirection::NorthEast); - self.resize_area_ui(ui, ResizeDirection::SouthEast); - self.resize_area_ui(ui, ResizeDirection::SouthWest); + if !is_fullscreen { + self.resize_area_ui(ui, ResizeDirection::North); + self.resize_area_ui(ui, ResizeDirection::East); + self.resize_area_ui(ui, ResizeDirection::South); + self.resize_area_ui(ui, ResizeDirection::West); + self.resize_area_ui(ui, ResizeDirection::NorthWest); + self.resize_area_ui(ui, ResizeDirection::NorthEast); + self.resize_area_ui(ui, ResizeDirection::SouthEast); + self.resize_area_ui(ui, ResizeDirection::SouthWest); + } } /// Draw window content for desktop. @@ -212,7 +230,9 @@ impl App { let interact_rect = { let mut rect = title_rect; - rect.min.y += Root::WINDOW_FRAME_MARGIN; + if !is_fullscreen { + rect.min.y += Root::WINDOW_FRAME_MARGIN; + } rect }; let title_resp = ui.interact( @@ -247,11 +267,11 @@ impl App { ); // Interact with the window title (drag to move window): - if title_resp.double_clicked() { + if !is_fullscreen && title_resp.double_clicked() { ui.ctx().send_viewport_cmd(ViewportCommand::Fullscreen(!is_fullscreen)); } - if title_resp.drag_started_by(egui::PointerButton::Primary) { + if !is_fullscreen && title_resp.drag_started_by(egui::PointerButton::Primary) { ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag); } diff --git a/src/gui/views/modal.rs b/src/gui/views/modal.rs index 42fc37a..3c7dd77 100644 --- a/src/gui/views/modal.rs +++ b/src/gui/views/modal.rs @@ -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 }; diff --git a/src/gui/views/root.rs b/src/gui/views/root.rs index 0e7701a..16ac38a 100644 --- a/src/gui/views/root.rs +++ b/src/gui/views/root.rs @@ -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 diff --git a/src/settings/config.rs b/src/settings/config.rs index 8829a24..0f93df4 100644 --- a/src/settings/config.rs +++ b/src/settings/config.rs @@ -75,7 +75,7 @@ impl AppConfig { /// Default desktop window width. pub const DEFAULT_WIDTH: f32 = Root::SIDE_PANEL_WIDTH * 3.0 + Self::FRAME_MARGIN; /// Default desktop window height. - pub const DEFAULT_HEIGHT: f32 = 698.0 + Root::WINDOW_TITLE_HEIGHT + Self::FRAME_MARGIN; + pub const DEFAULT_HEIGHT: f32 = 706.0; /// Minimal desktop window width. pub const MIN_WIDTH: f32 = Root::SIDE_PANEL_WIDTH + Self::FRAME_MARGIN; /// Minimal desktop window height.