Custom window title #8

Merged
ardocrat merged 29 commits from custom_window_title into master 2024-07-03 13:44:26 +03:00
3 changed files with 26 additions and 9 deletions
Showing only changes of commit 7ab64da9ee - Show all commits

View file

@ -83,6 +83,7 @@ impl<Platform: PlatformCallbacks> App<Platform> {
} else { } else {
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(egui::Frame { .frame(egui::Frame {
stroke: Stroke::NONE,
..Default::default() ..Default::default()
}) })
.show(ctx, |ui| { .show(ctx, |ui| {
@ -110,11 +111,9 @@ fn custom_window_frame(ctx: &Context, add_contents: impl FnOnce(&mut egui::Ui))
rounding: Rounding { rounding: Rounding {
nw: 8.0, nw: 8.0,
ne: 8.0, ne: 8.0,
sw: 0.0, sw: 8.0,
se: 0.0, se: 8.0,
}, },
// stroke: ctx.style().visuals.widgets.noninteractive.fg_stroke,
// outer_margin: 0.5.into(), // so the stroke is within the bounds
..Default::default() ..Default::default()
}; };
@ -130,7 +129,12 @@ fn custom_window_frame(ctx: &Context, add_contents: impl FnOnce(&mut egui::Ui))
let window_title_bg = RectShape { let window_title_bg = RectShape {
rect: window_title_rect, rect: window_title_rect,
rounding: panel_frame.rounding, rounding: Rounding {
nw: 8.0,
ne: 8.0,
sw: 0.0,
se: 0.0,
},
fill: Colors::yellow_dark(), fill: Colors::yellow_dark(),
stroke: Stroke::NONE, stroke: Stroke::NONE,
fill_texture_id: Default::default(), fill_texture_id: Default::default(),
@ -157,6 +161,15 @@ fn custom_window_frame(ctx: &Context, add_contents: impl FnOnce(&mut egui::Ui))
}; };
let bg_idx = ui.painter().add(title_bar_bg); let bg_idx = ui.painter().add(title_bar_bg);
// Draw line to support title panel.
ui.painter().line_segment(
[
title_bar_rect.left_bottom() + egui::vec2(0.0, 0.5),
title_bar_rect.right_bottom() + egui::vec2(0.0, 0.5),
],
View::item_stroke(),
);
// Draw main content. // Draw main content.
let mut content_rect = { let mut content_rect = {
let mut rect = app_rect; let mut rect = app_rect;
@ -164,17 +177,17 @@ fn custom_window_frame(ctx: &Context, add_contents: impl FnOnce(&mut egui::Ui))
rect rect
}; };
content_rect.min += egui::emath::vec2(4.0, 0.0); content_rect.min += egui::emath::vec2(4.0, 0.0);
content_rect.max -= egui::emath::vec2(4.0, 4.0); content_rect.max -= egui::emath::vec2(4.0, 2.0);
let mut content_ui = ui.child_ui(content_rect, *ui.layout()); let mut content_ui = ui.child_ui(content_rect, *ui.layout());
add_contents(&mut content_ui); add_contents(&mut content_ui);
// Setup title bar background. // Setup title panel background.
ui.painter().set(bg_idx, title_bar_bg); ui.painter().set(bg_idx, title_bar_bg);
}); });
} }
/// Draw custom window title content. /// Draw custom window title content.
fn window_title_ui(ui: &mut egui::Ui, title_bar_rect: egui::epaint::Rect) { fn window_title_ui(ui: &mut egui::Ui, title_bar_rect: Rect) {
let painter = ui.painter(); let painter = ui.painter();
let title_bar_response = ui.interact( let title_bar_response = ui.interact(
@ -192,7 +205,7 @@ fn window_title_ui(ui: &mut egui::Ui, title_bar_rect: egui::epaint::Rect) {
egui::Color32::from_gray(60), egui::Color32::from_gray(60),
); );
// Interact with the title bar (drag to move window): // Interact with the window title (drag to move window):
if title_bar_response.double_clicked() { if title_bar_response.double_clicked() {
let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false)); let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
ui.ctx() ui.ctx()

View file

@ -55,6 +55,7 @@ impl NetworkContent {
egui::TopBottomPanel::bottom("node_tabs_panel") egui::TopBottomPanel::bottom("node_tabs_panel")
.resizable(false) .resizable(false)
.frame(egui::Frame { .frame(egui::Frame {
stroke: Stroke::NONE,
fill: Colors::fill(), fill: Colors::fill(),
inner_margin: Margin { inner_margin: Margin {
left: View::get_left_inset() + 4.0, left: View::get_left_inset() + 4.0,
@ -82,6 +83,7 @@ impl NetworkContent {
.resizable(false) .resizable(false)
.exact_width(ui.available_width()) .exact_width(ui.available_width())
.frame(egui::Frame { .frame(egui::Frame {
stroke: Stroke::NONE,
..Default::default() ..Default::default()
}) })
.show_animated_inside(ui, !show_connections, |ui| { .show_animated_inside(ui, !show_connections, |ui| {

View file

@ -109,6 +109,7 @@ impl Root {
.resizable(false) .resizable(false)
.exact_width(panel_width) .exact_width(panel_width)
.frame(egui::Frame { .frame(egui::Frame {
stroke: egui::Stroke::NONE,
fill: Colors::white_or_black(false), fill: Colors::white_or_black(false),
..Default::default() ..Default::default()
}) })
@ -119,6 +120,7 @@ impl Root {
// Show wallets content. // Show wallets content.
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(egui::Frame { .frame(egui::Frame {
stroke: egui::Stroke::NONE,
fill: Colors::fill_deep(), fill: Colors::fill_deep(),
..Default::default() ..Default::default()
}) })