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

View file

@ -91,10 +91,20 @@ impl<Platform: PlatformCallbacks> App<Platform> {
/// Draw custom resizeable window content. /// Draw custom resizeable window content.
fn desktop_window_ui(&mut self, ui: &mut egui::Ui) { 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 title_stroke_rect = {
let mut rect = ui.max_rect().shrink(Root::WINDOW_FRAME_MARGIN); let mut rect = ui.max_rect();
rect.max.y = Root::WINDOW_FRAME_MARGIN + Root::WINDOW_TITLE_HEIGHT + if !is_fullscreen {
TitlePanel::DEFAULT_HEIGHT + 0.5; 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 rect
}; };
let title_stroke = RectShape { let title_stroke = RectShape {
@ -118,7 +128,10 @@ impl<Platform: PlatformCallbacks> App<Platform> {
ui.painter().add(title_stroke); ui.painter().add(title_stroke);
let content_stroke_rect = { 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; let top = Root::WINDOW_TITLE_HEIGHT + TitlePanel::DEFAULT_HEIGHT + 0.5;
rect.min += egui::vec2(0.0, top); rect.min += egui::vec2(0.0, top);
rect rect
@ -139,20 +152,25 @@ impl<Platform: PlatformCallbacks> App<Platform> {
ui.painter().add(content_stroke); ui.painter().add(content_stroke);
// Draw window content. // 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| { ui.allocate_ui_at_rect(content_rect, |ui| {
self.window_content(ui); self.window_content(ui);
}); });
// Setup resize areas. // Setup resize areas.
self.resize_area_ui(ui, ResizeDirection::North); if !is_fullscreen {
self.resize_area_ui(ui, ResizeDirection::East); self.resize_area_ui(ui, ResizeDirection::North);
self.resize_area_ui(ui, ResizeDirection::South); self.resize_area_ui(ui, ResizeDirection::East);
self.resize_area_ui(ui, ResizeDirection::West); self.resize_area_ui(ui, ResizeDirection::South);
self.resize_area_ui(ui, ResizeDirection::NorthWest); self.resize_area_ui(ui, ResizeDirection::West);
self.resize_area_ui(ui, ResizeDirection::NorthEast); self.resize_area_ui(ui, ResizeDirection::NorthWest);
self.resize_area_ui(ui, ResizeDirection::SouthEast); self.resize_area_ui(ui, ResizeDirection::NorthEast);
self.resize_area_ui(ui, ResizeDirection::SouthWest); self.resize_area_ui(ui, ResizeDirection::SouthEast);
self.resize_area_ui(ui, ResizeDirection::SouthWest);
}
} }
/// Draw window content for desktop. /// Draw window content for desktop.
@ -212,7 +230,9 @@ impl<Platform: PlatformCallbacks> App<Platform> {
let interact_rect = { let interact_rect = {
let mut rect = title_rect; let mut rect = title_rect;
rect.min.y += Root::WINDOW_FRAME_MARGIN; if !is_fullscreen {
rect.min.y += Root::WINDOW_FRAME_MARGIN;
}
rect rect
}; };
let title_resp = ui.interact( let title_resp = ui.interact(
@ -247,11 +267,11 @@ impl<Platform: PlatformCallbacks> App<Platform> {
); );
// Interact with the window title (drag to move window): // 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)); 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); ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag);
} }

View file

@ -160,9 +160,18 @@ impl Modal {
/// Draw [`egui::Window`] with provided content. /// Draw [`egui::Window`] with provided content.
fn window_ui(&self, ctx: &egui::Context, add_content: impl FnOnce(&mut egui::Ui, &Modal)) { 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(); let mut rect = ctx.screen_rect();
if View::is_desktop() { 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.min += egui::vec2(0.0, Root::WINDOW_TITLE_HEIGHT + 0.5);
rect.max.x += 0.5; rect.max.x += 0.5;
} }
@ -185,7 +194,7 @@ impl Modal {
let width = f32::min(available_width, Self::DEFAULT_WIDTH); let width = f32::min(available_width, Self::DEFAULT_WIDTH);
// Show main content Window at given position. // 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)) let layer_id = egui::Window::new(format!("modal_window_{}", self.id))
.title_bar(false) .title_bar(false)
.resizable(false) .resizable(false)
@ -217,14 +226,18 @@ impl Modal {
} }
/// Get [`egui::Window`] position based on [`ModalPosition`]. /// 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 { let align = match self.position {
ModalPosition::CenterTop => Align2::CENTER_TOP, ModalPosition::CenterTop => Align2::CENTER_TOP,
ModalPosition::Center => Align2::CENTER_CENTER ModalPosition::Center => Align2::CENTER_CENTER
}; };
let x_align = View::get_left_inset() - View::get_right_inset(); 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() { 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 { } else {
0.0 0.0
}; };

View file

@ -150,7 +150,10 @@ impl Root {
let panel_width = if dual_panel { let panel_width = if dual_panel {
Self::SIDE_PANEL_WIDTH + View::get_left_inset() Self::SIDE_PANEL_WIDTH + View::get_left_inset()
} else { } 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 Self::WINDOW_FRAME_MARGIN * 2.0
} else { } else {
0.0 0.0

View file

@ -75,7 +75,7 @@ impl AppConfig {
/// Default desktop window width. /// Default desktop window width.
pub const DEFAULT_WIDTH: f32 = Root::SIDE_PANEL_WIDTH * 3.0 + Self::FRAME_MARGIN; pub const DEFAULT_WIDTH: f32 = Root::SIDE_PANEL_WIDTH * 3.0 + Self::FRAME_MARGIN;
/// Default desktop window height. /// 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. /// Minimal desktop window width.
pub const MIN_WIDTH: f32 = Root::SIDE_PANEL_WIDTH + Self::FRAME_MARGIN; pub const MIN_WIDTH: f32 = Root::SIDE_PANEL_WIDTH + Self::FRAME_MARGIN;
/// Minimal desktop window height. /// Minimal desktop window height.