fix: modal padding and window border on desktop
This commit is contained in:
parent
5c8b9c40be
commit
75cf7edc96
3 changed files with 35 additions and 29 deletions
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use egui::{Align, Context, CursorIcon, Layout, Modifiers, ResizeDirection, Rounding, UiBuilder, ViewportCommand};
|
use egui::{Align, Context, CursorIcon, Layout, Modifiers, ResizeDirection, Rounding, Stroke, UiBuilder, ViewportCommand};
|
||||||
use egui::epaint::{RectShape};
|
use egui::epaint::{RectShape};
|
||||||
use egui::os::OperatingSystem;
|
use egui::os::OperatingSystem;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
} else {
|
} else {
|
||||||
self.window_title_ui(ui, is_fullscreen);
|
self.window_title_ui(ui, is_fullscreen);
|
||||||
ui.add_space(-1.0);
|
ui.add_space(-1.0);
|
||||||
Self::title_panel_bg(ui, is_fullscreen);
|
Self::title_panel_bg(ui);
|
||||||
self.content.ui(ui, &self.platform);
|
self.content.ui(ui, &self.platform);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -138,29 +138,24 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
|
|
||||||
/// Draw mobile platform window content.
|
/// Draw mobile platform window content.
|
||||||
fn mobile_window_ui(&mut self, ui: &mut egui::Ui) {
|
fn mobile_window_ui(&mut self, ui: &mut egui::Ui) {
|
||||||
Self::title_panel_bg(ui, true);
|
Self::title_panel_bg(ui);
|
||||||
self.content.ui(ui, &self.platform);
|
self.content.ui(ui, &self.platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw desktop platform window content.
|
/// Draw desktop platform window content.
|
||||||
fn desktop_window_ui(&mut self, ui: &mut egui::Ui, is_fullscreen: bool) {
|
fn desktop_window_ui(&mut self, ui: &mut egui::Ui, is_fullscreen: bool) {
|
||||||
Self::title_panel_bg(ui, is_fullscreen);
|
|
||||||
let rect = ui.max_rect();
|
|
||||||
|
|
||||||
let content_bg_rect = {
|
let content_bg_rect = {
|
||||||
let mut r = rect.clone();
|
let mut r = ui.max_rect();
|
||||||
if !is_fullscreen {
|
if !is_fullscreen {
|
||||||
r = r.shrink(Content::WINDOW_FRAME_MARGIN);
|
r = r.shrink(Content::WINDOW_FRAME_MARGIN);
|
||||||
}
|
}
|
||||||
let top = Content::WINDOW_TITLE_HEIGHT + TitlePanel::HEIGHT + if !is_fullscreen {
|
r.min.y += Content::WINDOW_TITLE_HEIGHT + TitlePanel::HEIGHT;
|
||||||
Content::WINDOW_FRAME_MARGIN
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
};
|
|
||||||
r.min.y = top;
|
|
||||||
r
|
r
|
||||||
};
|
};
|
||||||
let content_bg = RectShape::filled(content_bg_rect, Rounding::ZERO, Colors::fill_lite());
|
let content_bg = RectShape::new(content_bg_rect,
|
||||||
|
Rounding::ZERO,
|
||||||
|
Colors::fill_lite(),
|
||||||
|
View::default_stroke());
|
||||||
// Draw content background.
|
// Draw content background.
|
||||||
ui.painter().add(content_bg);
|
ui.painter().add(content_bg);
|
||||||
|
|
||||||
|
@ -172,6 +167,10 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
ui.allocate_new_ui(UiBuilder::new().max_rect(content_rect), |ui| {
|
ui.allocate_new_ui(UiBuilder::new().max_rect(content_rect), |ui| {
|
||||||
// Draw window title.
|
// Draw window title.
|
||||||
self.window_title_ui(ui, is_fullscreen);
|
self.window_title_ui(ui, is_fullscreen);
|
||||||
|
ui.add_space(-1.0);
|
||||||
|
|
||||||
|
// Draw title panel background.
|
||||||
|
Self::title_panel_bg(ui);
|
||||||
|
|
||||||
let content_rect = {
|
let content_rect = {
|
||||||
let mut rect = ui.max_rect();
|
let mut rect = ui.max_rect();
|
||||||
|
@ -199,15 +198,11 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw title panel background.
|
/// Draw title panel background.
|
||||||
fn title_panel_bg(ui: &mut egui::Ui, is_fullscreen: bool) {
|
fn title_panel_bg(ui: &mut egui::Ui) {
|
||||||
let title_rect = {
|
let title_rect = {
|
||||||
let mut rect = ui.max_rect();
|
let mut rect = ui.max_rect();
|
||||||
if View::is_desktop() {
|
if View::is_desktop() {
|
||||||
let is_mac = OperatingSystem::from_target_os() == OperatingSystem::Mac;
|
rect.min.y += Content::WINDOW_TITLE_HEIGHT - 0.5;
|
||||||
if !is_mac && !is_fullscreen {
|
|
||||||
rect = rect.shrink(Content::WINDOW_FRAME_MARGIN)
|
|
||||||
}
|
|
||||||
rect.min.y += Content::WINDOW_TITLE_HEIGHT;
|
|
||||||
}
|
}
|
||||||
rect.max.y = rect.min.y + View::get_top_inset() + TitlePanel::HEIGHT;
|
rect.max.y = rect.min.y + View::get_top_inset() + TitlePanel::HEIGHT;
|
||||||
rect
|
rect
|
||||||
|
@ -224,8 +219,13 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
rect
|
rect
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let title_bg_rect = {
|
||||||
|
let mut r = title_rect.clone();
|
||||||
|
r.max.y += TitlePanel::HEIGHT - 1.0;
|
||||||
|
r
|
||||||
|
};
|
||||||
let is_mac = OperatingSystem::from_target_os() == OperatingSystem::Mac;
|
let is_mac = OperatingSystem::from_target_os() == OperatingSystem::Mac;
|
||||||
let window_title_bg = RectShape::filled(title_rect, if is_fullscreen || is_mac {
|
let window_title_bg = RectShape::new(title_bg_rect, if is_fullscreen || is_mac {
|
||||||
Rounding::ZERO
|
Rounding::ZERO
|
||||||
} else {
|
} else {
|
||||||
Rounding {
|
Rounding {
|
||||||
|
@ -234,7 +234,7 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
sw: 0.0,
|
sw: 0.0,
|
||||||
se: 0.0,
|
se: 0.0,
|
||||||
}
|
}
|
||||||
}, Colors::yellow_dark());
|
}, Colors::yellow_dark(), Stroke::new(1.0, Colors::STROKE));
|
||||||
// Draw title background.
|
// Draw title background.
|
||||||
ui.painter().add(window_title_bg);
|
ui.painter().add(window_title_bg);
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ const TITLE_DARK: Color32 = Color32::from_gray(205);
|
||||||
const GRAY: Color32 = Color32::from_gray(120);
|
const GRAY: Color32 = Color32::from_gray(120);
|
||||||
const GRAY_DARK: Color32 = Color32::from_gray(145);
|
const GRAY_DARK: Color32 = Color32::from_gray(145);
|
||||||
|
|
||||||
const STROKE: Color32 = Color32::from_gray(200);
|
|
||||||
const STROKE_DARK: Color32 = Color32::from_gray(50);
|
const STROKE_DARK: Color32 = Color32::from_gray(50);
|
||||||
|
|
||||||
const INACTIVE_TEXT: Color32 = Color32::from_gray(150);
|
const INACTIVE_TEXT: Color32 = Color32::from_gray(150);
|
||||||
|
@ -86,6 +85,7 @@ fn use_dark() -> bool {
|
||||||
|
|
||||||
impl Colors {
|
impl Colors {
|
||||||
pub const TRANSPARENT: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 0);
|
pub const TRANSPARENT: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 0);
|
||||||
|
pub const STROKE: Color32 = Color32::from_gray(200);
|
||||||
|
|
||||||
pub fn white_or_black(black_in_white: bool) -> Color32 {
|
pub fn white_or_black(black_in_white: bool) -> Color32 {
|
||||||
if use_dark() {
|
if use_dark() {
|
||||||
|
@ -219,7 +219,7 @@ impl Colors {
|
||||||
if use_dark() {
|
if use_dark() {
|
||||||
STROKE_DARK
|
STROKE_DARK
|
||||||
} else {
|
} else {
|
||||||
STROKE
|
Self::STROKE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,10 +185,11 @@ impl Modal {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup background rect.
|
// Setup background rect.
|
||||||
let bg_rect = if View::is_desktop() && !is_fullscreen {
|
let bg_rect = if View::is_desktop() {
|
||||||
let mut r = ctx.screen_rect();
|
let mut r = ctx.screen_rect();
|
||||||
if OperatingSystem::Mac != OperatingSystem::from_target_os() {
|
let is_mac = OperatingSystem::Mac == OperatingSystem::from_target_os();
|
||||||
r = r.shrink(Content::WINDOW_FRAME_MARGIN);
|
if !is_mac && !is_fullscreen {
|
||||||
|
r = r.shrink(Content::WINDOW_FRAME_MARGIN - 1.0);
|
||||||
}
|
}
|
||||||
r.min.y += Content::WINDOW_TITLE_HEIGHT;
|
r.min.y += Content::WINDOW_TITLE_HEIGHT;
|
||||||
r
|
r
|
||||||
|
@ -253,12 +254,17 @@ impl Modal {
|
||||||
};
|
};
|
||||||
|
|
||||||
let x_align = View::get_left_inset() - View::get_right_inset();
|
let x_align = View::get_left_inset() - View::get_right_inset();
|
||||||
|
let is_mac = OperatingSystem::Mac == OperatingSystem::from_target_os();
|
||||||
let extra_y = if View::is_desktop() {
|
let extra_y = if View::is_desktop() {
|
||||||
Content::WINDOW_TITLE_HEIGHT - Self::DEFAULT_MARGIN / 2.0
|
Content::WINDOW_TITLE_HEIGHT + if !is_mac {
|
||||||
|
Content::WINDOW_FRAME_MARGIN
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
let y_align = View::get_top_inset() + Self::DEFAULT_MARGIN + extra_y;
|
let y_align = View::get_top_inset() + Self::DEFAULT_MARGIN / 2.0 + extra_y;
|
||||||
|
|
||||||
let offset = match self.position {
|
let offset = match self.position {
|
||||||
ModalPosition::CenterTop => Vec2::new(x_align, y_align),
|
ModalPosition::CenterTop => Vec2::new(x_align, y_align),
|
||||||
|
|
Loading…
Reference in a new issue