diff options
author | 2022-07-08 19:31:45 +0200 | |
---|---|---|
committer | 2022-07-08 19:31:45 +0200 | |
commit | fa55dff61db47197a961152285c6a6abfab0b217 (patch) | |
tree | 44904afb16a0cab9e22fce0d73a5616676cd426b /pure | |
parent | 1dd1a2f97fc747e15e12b5188dad6c41b0d052ea (diff) | |
parent | 66eb6263003c1bbedd1fd14d6b12f172d20a6211 (diff) | |
download | iced-fa55dff61db47197a961152285c6a6abfab0b217.tar.gz iced-fa55dff61db47197a961152285c6a6abfab0b217.tar.bz2 iced-fa55dff61db47197a961152285c6a6abfab0b217.zip |
Merge branch 'master' into theming
Diffstat (limited to 'pure')
-rw-r--r-- | pure/Cargo.toml | 2 | ||||
-rw-r--r-- | pure/src/widget/pane_grid/title_bar.rs | 80 | ||||
-rw-r--r-- | pure/src/widget/text_input.rs | 28 |
3 files changed, 80 insertions, 30 deletions
diff --git a/pure/Cargo.toml b/pure/Cargo.toml index 2301031d..b57e4c5a 100644 --- a/pure/Cargo.toml +++ b/pure/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_pure" -version = "0.2.1" +version = "0.2.2" edition = "2021" description = "Pure widgets for Iced" license = "MIT" diff --git a/pure/src/widget/pane_grid/title_bar.rs b/pure/src/widget/pane_grid/title_bar.rs index 950fd990..de9591a2 100644 --- a/pure/src/widget/pane_grid/title_bar.rs +++ b/pure/src/widget/pane_grid/title_bar.rs @@ -141,19 +141,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); - - self.content.as_widget().draw( - &tree.children[0], - renderer, - theme, - &inherited_style, - title_layout, - cursor_position, - viewport, - ); + let mut show_title = true; if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } if show_controls || self.always_show_controls { controls.as_widget().draw( @@ -167,6 +163,18 @@ where ); } } + + if show_title { + self.content.as_widget().draw( + &tree.children[0], + renderer, + theme, + &inherited_style, + title_layout, + cursor_position, + viewport, + ); + } } /// Returns whether the mouse cursor is over the pick area of the @@ -258,9 +266,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); + let mut show_title = true; let control_status = if let Some(controls) = &mut self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } controls.as_widget_mut().on_event( &mut tree.children[1], @@ -275,15 +289,19 @@ where event::Status::Ignored }; - let title_status = self.content.as_widget_mut().on_event( - &mut tree.children[0], - event, - title_layout, - cursor_position, - renderer, - clipboard, - shell, - ); + let title_status = if show_title { + self.content.as_widget_mut().on_event( + &mut tree.children[0], + event, + title_layout, + cursor_position, + renderer, + clipboard, + shell, + ) + } else { + event::Status::Ignored + }; control_status.merge(title_status) } @@ -312,17 +330,21 @@ where if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + let controls_interaction = controls.as_widget().mouse_interaction( + &tree.children[1], + controls_layout, + cursor_position, + viewport, + renderer, + ); - controls - .as_widget() - .mouse_interaction( - &tree.children[1], - controls_layout, - cursor_position, - viewport, - renderer, - ) - .max(title_interaction) + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + controls_interaction + } else { + controls_interaction.max(title_interaction) + } } else { title_interaction } diff --git a/pure/src/widget/text_input.rs b/pure/src/widget/text_input.rs index d3e642a5..9b0a466a 100644 --- a/pure/src/widget/text_input.rs +++ b/pure/src/widget/text_input.rs @@ -126,6 +126,34 @@ where self.style = style.into(); self } + + /// Draws the [`TextInput`] with the given [`Renderer`], overriding its + /// [`text_input::Value`] if provided. + /// + /// [`Renderer`]: text::Renderer + pub fn draw( + &self, + tree: &Tree, + renderer: &mut Renderer, + theme: &Renderer::Theme, + layout: Layout<'_>, + cursor_position: Point, + value: Option<&text_input::Value>, + ) { + text_input::draw( + renderer, + theme, + layout, + cursor_position, + tree.state.downcast_ref::<text_input::State>(), + value.unwrap_or(&self.value), + &self.placeholder, + self.size, + &self.font, + self.is_secure, + self.style, + ) + } } impl<'a, Message, Renderer> Widget<Message, Renderer> |