diff options
Diffstat (limited to 'native/src/widget')
| -rw-r--r-- | native/src/widget/image/viewer.rs | 25 | ||||
| -rw-r--r-- | native/src/widget/pane_grid.rs | 2 | ||||
| -rw-r--r-- | native/src/widget/pane_grid/content.rs | 17 | ||||
| -rw-r--r-- | native/src/widget/pane_grid/title_bar.rs | 24 | ||||
| -rw-r--r-- | native/src/widget/text_input.rs | 35 | 
5 files changed, 64 insertions, 39 deletions
diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs index a006c0af..405daf00 100644 --- a/native/src/widget/image/viewer.rs +++ b/native/src/widget/image/viewer.rs @@ -132,19 +132,30 @@ where      ) -> layout::Node {          let (width, height) = renderer.dimensions(&self.handle); -        let aspect_ratio = width as f32 / height as f32; -          let mut size = limits              .width(self.width)              .height(self.height)              .resolve(Size::new(width as f32, height as f32)); -        let viewport_aspect_ratio = size.width / size.height; - -        if viewport_aspect_ratio > aspect_ratio { -            size.width = width as f32 * size.height / height as f32; +        let expansion_size = if height > width { +            self.width          } else { -            size.height = height as f32 * size.width / width as f32; +            self.height +        }; + +        // Only calculate viewport sizes if the images are constrained to a limited space. +        // If they are Fill|Portion let them expand within their alotted space. +        match expansion_size { +            Length::Shrink | Length::Units(_) => { +                let aspect_ratio = width as f32 / height as f32; +                let viewport_aspect_ratio = size.width / size.height; +                if viewport_aspect_ratio > aspect_ratio { +                    size.width = width as f32 * size.height / height as f32; +                } else { +                    size.height = height as f32 * size.width / width as f32; +                } +            } +            Length::Fill | Length::FillPortion(_) => {}          }          layout::Node::new(size) diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 44028f5e..b72172cc 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -6,7 +6,7 @@  //! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,  //! drag and drop, and hotkey support.  //! -//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid +//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.3/examples/pane_grid  mod axis;  mod configuration;  mod content; diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index f028ec25..b0110393 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -193,18 +193,17 @@ where          &mut self,          layout: Layout<'_>,      ) -> Option<overlay::Element<'_, Message, Renderer>> { -        let body_layout = if self.title_bar.is_some() { +        if let Some(title_bar) = self.title_bar.as_mut() {              let mut children = layout.children(); +            let title_bar_layout = children.next()?; -            // Overlays only allowed in the pane body, for now at least. -            let _title_bar_layout = children.next(); - -            children.next()? +            match title_bar.overlay(title_bar_layout) { +                Some(overlay) => Some(overlay), +                None => self.body.overlay(children.next()?), +            }          } else { -            layout -        }; - -        self.body.overlay(body_layout) +            self.body.overlay(layout) +        }      }  } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index d9d85dbb..070010f8 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -1,6 +1,7 @@  use crate::container;  use crate::event::{self, Event};  use crate::layout; +use crate::overlay;  use crate::pane_grid;  use crate::{      Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Size, @@ -242,4 +243,27 @@ where          control_status.merge(title_status)      } + +    pub(crate) fn overlay( +        &mut self, +        layout: Layout<'_>, +    ) -> Option<overlay::Element<'_, Message, Renderer>> { +        let mut children = layout.children(); +        let padded = children.next()?; + +        let mut children = padded.children(); +        let title_layout = children.next()?; + +        let Self { +            content, controls, .. +        } = self; + +        content.overlay(title_layout).or_else(move || { +            controls.as_mut().and_then(|controls| { +                let controls_layout = children.next()?; + +                controls.overlay(controls_layout) +            }) +        }) +    }  } diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 20117fa0..f06f057b 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -362,7 +362,7 @@ where              Event::Keyboard(keyboard::Event::CharacterReceived(c))                  if self.state.is_focused                      && self.state.is_pasting.is_none() -                    && !self.state.keyboard_modifiers.is_command_pressed() +                    && !self.state.keyboard_modifiers.command()                      && !c.is_control() =>              {                  let mut editor = @@ -450,7 +450,7 @@ where                          if platform::is_jump_modifier_pressed(modifiers)                              && !self.is_secure                          { -                            if modifiers.shift { +                            if modifiers.shift() {                                  self.state                                      .cursor                                      .select_left_by_words(&self.value); @@ -459,7 +459,7 @@ where                                      .cursor                                      .move_left_by_words(&self.value);                              } -                        } else if modifiers.shift { +                        } else if modifiers.shift() {                              self.state.cursor.select_left(&self.value)                          } else {                              self.state.cursor.move_left(&self.value); @@ -469,7 +469,7 @@ where                          if platform::is_jump_modifier_pressed(modifiers)                              && !self.is_secure                          { -                            if modifiers.shift { +                            if modifiers.shift() {                                  self.state                                      .cursor                                      .select_right_by_words(&self.value); @@ -478,14 +478,14 @@ where                                      .cursor                                      .move_right_by_words(&self.value);                              } -                        } else if modifiers.shift { +                        } else if modifiers.shift() {                              self.state.cursor.select_right(&self.value)                          } else {                              self.state.cursor.move_right(&self.value);                          }                      }                      keyboard::KeyCode::Home => { -                        if modifiers.shift { +                        if modifiers.shift() {                              self.state.cursor.select_range(                                  self.state.cursor.start(&self.value),                                  0, @@ -495,7 +495,7 @@ where                          }                      }                      keyboard::KeyCode::End => { -                        if modifiers.shift { +                        if modifiers.shift() {                              self.state.cursor.select_range(                                  self.state.cursor.start(&self.value),                                  self.value.len(), @@ -505,10 +505,7 @@ where                          }                      }                      keyboard::KeyCode::C -                        if self -                            .state -                            .keyboard_modifiers -                            .is_command_pressed() => +                        if self.state.keyboard_modifiers.command() =>                      {                          match self.state.cursor.selection(&self.value) {                              Some((start, end)) => { @@ -520,10 +517,7 @@ where                          }                      }                      keyboard::KeyCode::X -                        if self -                            .state -                            .keyboard_modifiers -                            .is_command_pressed() => +                        if self.state.keyboard_modifiers.command() =>                      {                          match self.state.cursor.selection(&self.value) {                              Some((start, end)) => { @@ -545,7 +539,7 @@ where                          messages.push(message);                      }                      keyboard::KeyCode::V => { -                        if self.state.keyboard_modifiers.is_command_pressed() { +                        if self.state.keyboard_modifiers.command() {                              let content = match self.state.is_pasting.take() {                                  Some(content) => content,                                  None => { @@ -576,10 +570,7 @@ where                          }                      }                      keyboard::KeyCode::A -                        if self -                            .state -                            .keyboard_modifiers -                            .is_command_pressed() => +                        if self.state.keyboard_modifiers.command() =>                      {                          self.state.cursor.select_all(&self.value);                      } @@ -858,9 +849,9 @@ mod platform {      pub fn is_jump_modifier_pressed(modifiers: keyboard::Modifiers) -> bool {          if cfg!(target_os = "macos") { -            modifiers.alt +            modifiers.alt()          } else { -            modifiers.control +            modifiers.control()          }      }  }  | 
