Custom window title #8
4 changed files with 58 additions and 22 deletions
|
@ -91,10 +91,20 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
|
||||
/// 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<Platform: PlatformCallbacks> App<Platform> {
|
|||
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,12 +152,16 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
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.
|
||||
if !is_fullscreen {
|
||||
self.resize_area_ui(ui, ResizeDirection::North);
|
||||
self.resize_area_ui(ui, ResizeDirection::East);
|
||||
self.resize_area_ui(ui, ResizeDirection::South);
|
||||
|
@ -154,6 +171,7 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
self.resize_area_ui(ui, ResizeDirection::SouthEast);
|
||||
self.resize_area_ui(ui, ResizeDirection::SouthWest);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw window content for desktop.
|
||||
fn window_content(&mut self, ui: &mut egui::Ui) {
|
||||
|
@ -212,7 +230,9 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
|
||||
let interact_rect = {
|
||||
let mut rect = title_rect;
|
||||
if !is_fullscreen {
|
||||
rect.min.y += Root::WINDOW_FRAME_MARGIN;
|
||||
}
|
||||
rect
|
||||
};
|
||||
let title_resp = ui.interact(
|
||||
|
@ -247,11 +267,11 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue