From a764b0d23f9be3f938a37bbf7d7e6ee496d92cb8 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 26 Aug 2020 20:40:25 +0200 Subject: [PATCH] [window] visually indicate which windows can be resized --- egui/src/containers/resize.rs | 21 ++++++++++++--------- egui/src/containers/window.rs | 16 ++++++++++++++++ egui/src/style.rs | 3 +++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index e82537af..9a7a71a1 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -151,7 +151,7 @@ impl Resize { let corner_interact = if self.resizable { // Resize-corner: - let corner_size = Vec2::splat(16.0); // TODO: style + let corner_size = Vec2::splat(ui.style().resize_corner_size); let corner_rect = Rect::from_min_size( position + state.desired_size + self.handle_offset - corner_size, corner_size, @@ -274,21 +274,24 @@ impl Resize { } } -fn paint_resize_corner(ui: &mut Ui, interact: &InteractInfo) { +use crate::paint::LineStyle; + +pub fn paint_resize_corner(ui: &mut Ui, interact: &InteractInfo) { let color = ui.style().interact(interact).stroke_color; let width = ui.style().interact(interact).stroke_width; + paint_resize_corner_with_style(ui, &interact.rect, LineStyle::new(width, color)); +} +pub fn paint_resize_corner_with_style(ui: &mut Ui, rect: &Rect, style: LineStyle) { let painter = ui.painter(); - - let corner = painter.round_pos_to_pixels(interact.rect.right_bottom()); + let corner = painter.round_pos_to_pixels(rect.right_bottom()); let mut w = 2.0; while w < 12.0 { - painter.add(paint::PaintCmd::line_segment( - [pos2(corner.x - w, corner.y), pos2(corner.x, corner.y - w)], - color, - width, - )); + painter.add(paint::PaintCmd::LineSegment { + points: [pos2(corner.x - w, corner.y), pos2(corner.x, corner.y - w)], + style, + }); w += 4.0; } } diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index bedfce38..e1c22d45 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -235,6 +235,7 @@ impl<'open> Window<'open> { { // BEGIN FRAME -------------------------------- + let frame_outline = frame.outline; let mut frame = frame.begin(&mut area_content_ui); let default_expanded = true; @@ -269,6 +270,12 @@ impl<'open> Window<'open> { .map(|ri| ri.1); let outer_rect = frame.end(&mut area_content_ui); + + if possible.resizable { + // TODO: draw BEHIND contents ? + paint_resize_corner(&mut area_content_ui, outer_rect, frame_outline); + } + // END FRAME -------------------------------- title_bar.ui( @@ -307,6 +314,15 @@ impl<'open> Window<'open> { } } +fn paint_resize_corner(ui: &mut Ui, outer_rect: Rect, frame_outline: Option) { + let corner_size = Vec2::splat(ui.style().resize_corner_size); + let handle_offset = -Vec2::splat(2.0); + let corner_rect = + Rect::from_min_size(outer_rect.max - corner_size + handle_offset, corner_size); + let outline = frame_outline.unwrap_or_else(|| LineStyle::new(1.0, color::GRAY)); + crate::resize::paint_resize_corner_with_style(ui, &corner_rect, outline); +} + // ---------------------------------------------------------------------------- #[derive(Clone, Copy, Debug)] diff --git a/egui/src/style.rs b/egui/src/style.rs index 6876c208..942b029c 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -32,6 +32,8 @@ pub struct Style { /// Mouse must be the close to the corner of a window to resize pub resize_interact_radius_corner: f32, + pub resize_corner_size: f32, + // ----------------------------------------------- // Purely visual: pub interact: Interact, @@ -82,6 +84,7 @@ impl Default for Style { start_icon_width: 14.0, resize_interact_radius_side: 5.0, resize_interact_radius_corner: 10.0, + resize_corner_size: 16.0, interact: Default::default(), text_color: gray(160, 255), line_width: 1.0,