diff options
Diffstat (limited to '')
-rw-r--r-- | native/src/widget/pane_grid.rs | 46 | ||||
-rw-r--r-- | native/src/widget/pane_grid/content.rs | 17 | ||||
-rw-r--r-- | native/src/widget/pick_list.rs | 6 | ||||
-rw-r--r-- | native/src/widget/text_input.rs | 8 | ||||
-rw-r--r-- | native/src/window/action.rs | 20 |
5 files changed, 63 insertions, 34 deletions
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index d84fb7a0..96cf78ef 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -341,6 +341,7 @@ where cursor_position, viewport, renderer, + self.on_drag.is_some(), ) }) .max() @@ -648,7 +649,7 @@ pub fn mouse_interaction( resize_leeway: Option<u16>, ) -> Option<mouse::Interaction> { if action.picked_pane().is_some() { - return Some(mouse::Interaction::Grab); + return Some(mouse::Interaction::Grabbing); } let resize_axis = @@ -756,27 +757,12 @@ pub fn draw<Renderer, T>( cursor_position }; + let mut render_picked_pane = None; + for ((id, pane), layout) in elements.zip(layout.children()) { match picked_pane { Some((dragging, origin)) if id == dragging => { - let bounds = layout.bounds(); - - renderer.with_translation( - cursor_position - - Point::new(bounds.x + origin.x, bounds.y + origin.y), - |renderer| { - renderer.with_layer(bounds, |renderer| { - draw_pane( - pane, - renderer, - default_style, - layout, - pane_cursor_position, - viewport, - ); - }); - }, - ); + render_picked_pane = Some((pane, origin, layout)); } _ => { draw_pane( @@ -791,6 +777,28 @@ pub fn draw<Renderer, T>( } } + // Render picked pane last + if let Some((pane, origin, layout)) = render_picked_pane { + let bounds = layout.bounds(); + + renderer.with_translation( + cursor_position + - Point::new(bounds.x + origin.x, bounds.y + origin.y), + |renderer| { + renderer.with_layer(bounds, |renderer| { + draw_pane( + pane, + renderer, + default_style, + layout, + pane_cursor_position, + viewport, + ); + }); + }, + ); + }; + if let Some((axis, split_region, is_picked)) = picked_split { let highlight = if is_picked { theme.picked_split(style) diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 98ce2c4b..c236d820 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -115,25 +115,25 @@ where let show_controls = bounds.contains(cursor_position); - title_bar.draw( - &tree.children[1], + self.body.as_widget().draw( + &tree.children[0], renderer, theme, style, - title_bar_layout, + body_layout, cursor_position, viewport, - show_controls, ); - self.body.as_widget().draw( - &tree.children[0], + title_bar.draw( + &tree.children[1], renderer, theme, style, - body_layout, + title_bar_layout, cursor_position, viewport, + show_controls, ); } else { self.body.as_widget().draw( @@ -238,6 +238,7 @@ where cursor_position: Point, viewport: &Rectangle, renderer: &Renderer, + drag_enabled: bool, ) -> mouse::Interaction { let (body_layout, title_bar_interaction) = if let Some(title_bar) = &self.title_bar { @@ -247,7 +248,7 @@ where let is_over_pick_area = title_bar .is_over_pick_area(title_bar_layout, cursor_position); - if is_over_pick_area { + if is_over_pick_area && drag_enabled { return mouse::Interaction::Grab; } diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index c334804e..896f5b35 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -348,9 +348,9 @@ where let state = state(); let event_status = if state.is_open { - // TODO: Encode cursor availability in the type system - state.is_open = - cursor_position.x < 0.0 || cursor_position.y < 0.0; + // Event wasn't processed by overlay, so cursor was clicked either outside it's + // bounds or on the drop-down, either way we close the overlay. + state.is_open = false; event::Status::Captured } else if layout.bounds().contains(cursor_position) { diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index c2d25520..54a6aaf8 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -92,7 +92,7 @@ where is_secure: false, font: Default::default(), width: Length::Fill, - padding: Padding::ZERO, + padding: Padding::new(5), size: None, on_change: Box::new(on_change), on_paste: None, @@ -712,14 +712,14 @@ where } return event::Status::Captured; + } else { + state.is_pasting = None; } } Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => { let state = state(); - if state.is_focused { - state.keyboard_modifiers = modifiers; - } + state.keyboard_modifiers = modifiers; } _ => {} } diff --git a/native/src/window/action.rs b/native/src/window/action.rs index 73338e22..009dcc27 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -5,6 +5,12 @@ use std::fmt; /// An operation to be performed on some window. pub enum Action<T> { + /// Moves the window with the left mouse button until the button is + /// released. + /// + /// There’s no guarantee that this will work unless the left mouse + /// button was pressed immediately before this function is called. + Drag, /// Resize the window. Resize { /// The new logical width of the window @@ -12,6 +18,10 @@ pub enum Action<T> { /// The new logical height of the window height: u32, }, + /// Sets the window to maximized or back + Maximize(bool), + /// Set the window to minimized or back + Minimize(bool), /// Move the window. /// /// Unsupported on Wayland. @@ -23,6 +33,8 @@ pub enum Action<T> { }, /// Set the [`Mode`] of the window. SetMode(Mode), + /// Sets the window to maximized or back + ToggleMaximize, /// Fetch the current [`Mode`] of the window. FetchMode(Box<dyn FnOnce(Mode) -> T + 'static>), } @@ -37,9 +49,13 @@ impl<T> Action<T> { T: 'static, { match self { + Self::Drag => Action::Drag, Self::Resize { width, height } => Action::Resize { width, height }, + Self::Maximize(bool) => Action::Maximize(bool), + Self::Minimize(bool) => Action::Minimize(bool), Self::Move { x, y } => Action::Move { x, y }, Self::SetMode(mode) => Action::SetMode(mode), + Self::ToggleMaximize => Action::ToggleMaximize, Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))), } } @@ -48,15 +64,19 @@ impl<T> Action<T> { impl<T> fmt::Debug for Action<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { + Self::Drag => write!(f, "Action::Drag"), Self::Resize { width, height } => write!( f, "Action::Resize {{ widget: {}, height: {} }}", width, height ), + Self::Maximize(value) => write!(f, "Action::Maximize({})", value), + Self::Minimize(value) => write!(f, "Action::Minimize({}", value), Self::Move { x, y } => { write!(f, "Action::Move {{ x: {}, y: {} }}", x, y) } Self::SetMode(mode) => write!(f, "Action::SetMode({:?})", mode), + Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"), Self::FetchMode(_) => write!(f, "Action::FetchMode"), } } |