summaryrefslogtreecommitdiffstats
path: root/native/src/widget/pane_grid.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-17 16:23:29 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-17 16:23:29 +0100
commita467a037c3aee6cf659ec11a8deb744ca0408c59 (patch)
treed1f5f5bb6b5b504e8e72034d2912865c7d55cfdc /native/src/widget/pane_grid.rs
parentfd3a141024a11e17bba0c568f0df7ff34b79315b (diff)
downloadiced-a467a037c3aee6cf659ec11a8deb744ca0408c59.tar.gz
iced-a467a037c3aee6cf659ec11a8deb744ca0408c59.tar.bz2
iced-a467a037c3aee6cf659ec11a8deb744ca0408c59.zip
Use `Pixels` for `spacing`
Diffstat (limited to 'native/src/widget/pane_grid.rs')
-rw-r--r--native/src/widget/pane_grid.rs61
1 files changed, 27 insertions, 34 deletions
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index c6ff61ac..83564c3f 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -42,8 +42,8 @@ use crate::widget;
use crate::widget::container;
use crate::widget::tree::{self, Tree};
use crate::{
- Clipboard, Color, Element, Layout, Length, Point, Rectangle, Shell, Size,
- Vector, Widget,
+ Clipboard, Color, Element, Layout, Length, Pixels, Point, Rectangle, Shell,
+ Size, Vector, Widget,
};
/// A collection of panes distributed using either vertical or horizontal splits
@@ -104,10 +104,10 @@ where
contents: Contents<'a, Content<'a, Message, Renderer>>,
width: Length,
height: Length,
- spacing: u16,
+ spacing: f32,
on_click: Option<Box<dyn Fn(Pane) -> Message + 'a>>,
on_drag: Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
- on_resize: Option<(u16, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
+ on_resize: Option<(f32, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -150,7 +150,7 @@ where
contents,
width: Length::Fill,
height: Length::Fill,
- spacing: 0,
+ spacing: 0.0,
on_click: None,
on_drag: None,
on_resize: None,
@@ -171,8 +171,8 @@ where
}
/// Sets the spacing _between_ the panes of the [`PaneGrid`].
- pub fn spacing(mut self, units: u16) -> Self {
- self.spacing = units;
+ pub fn spacing(mut self, amount: impl Into<Pixels>) -> Self {
+ self.spacing = amount.into().0;
self
}
@@ -205,11 +205,11 @@ where
/// The grabbable area of a split will have a length of `spacing + leeway`,
/// properly centered. In other words, a length of
/// `(spacing + leeway) / 2.0` on either side of the split line.
- pub fn on_resize<F>(mut self, leeway: u16, f: F) -> Self
+ pub fn on_resize<F>(mut self, leeway: impl Into<Pixels>, f: F) -> Self
where
F: 'a + Fn(ResizeEvent) -> Message,
{
- self.on_resize = Some((leeway, Box::new(f)));
+ self.on_resize = Some((leeway.into().0, Box::new(f)));
self
}
@@ -485,14 +485,14 @@ pub fn layout<Renderer, T>(
node: &Node,
width: Length,
height: Length,
- spacing: u16,
+ spacing: f32,
contents: impl Iterator<Item = (Pane, T)>,
layout_content: impl Fn(T, &Renderer, &layout::Limits) -> layout::Node,
) -> layout::Node {
let limits = limits.width(width).height(height);
let size = limits.resolve(Size::ZERO);
- let regions = node.pane_regions(f32::from(spacing), size);
+ let regions = node.pane_regions(spacing, size);
let children = contents
.filter_map(|(pane, content)| {
let region = regions.get(&pane)?;
@@ -522,11 +522,11 @@ pub fn update<'a, Message, T: Draggable>(
layout: Layout<'_>,
cursor_position: Point,
shell: &mut Shell<'_, Message>,
- spacing: u16,
+ spacing: f32,
contents: impl Iterator<Item = (Pane, T)>,
on_click: &Option<Box<dyn Fn(Pane) -> Message + 'a>>,
on_drag: &Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
- on_resize: &Option<(u16, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
+ on_resize: &Option<(f32, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
) -> event::Status {
let mut event_status = event::Status::Ignored;
@@ -546,13 +546,13 @@ pub fn update<'a, Message, T: Draggable>(
);
let splits = node.split_regions(
- f32::from(spacing),
+ spacing,
Size::new(bounds.width, bounds.height),
);
let clicked_split = hovered_split(
splits.iter(),
- f32::from(spacing + leeway),
+ spacing + leeway,
relative_cursor,
);
@@ -624,7 +624,7 @@ pub fn update<'a, Message, T: Draggable>(
let bounds = layout.bounds();
let splits = node.split_regions(
- f32::from(spacing),
+ spacing,
Size::new(bounds.width, bounds.height),
);
@@ -698,8 +698,8 @@ pub fn mouse_interaction(
node: &Node,
layout: Layout<'_>,
cursor_position: Point,
- spacing: u16,
- resize_leeway: Option<u16>,
+ spacing: f32,
+ resize_leeway: Option<f32>,
) -> Option<mouse::Interaction> {
if action.picked_pane().is_some() {
return Some(mouse::Interaction::Grabbing);
@@ -710,20 +710,15 @@ pub fn mouse_interaction(
resize_leeway.and_then(|leeway| {
let bounds = layout.bounds();
- let splits =
- node.split_regions(f32::from(spacing), bounds.size());
+ let splits = node.split_regions(spacing, bounds.size());
let relative_cursor = Point::new(
cursor_position.x - bounds.x,
cursor_position.y - bounds.y,
);
- hovered_split(
- splits.iter(),
- f32::from(spacing + leeway),
- relative_cursor,
- )
- .map(|(_, axis, _)| axis)
+ hovered_split(splits.iter(), spacing + leeway, relative_cursor)
+ .map(|(_, axis, _)| axis)
})
});
@@ -747,8 +742,8 @@ pub fn draw<Renderer, T>(
theme: &Renderer::Theme,
default_style: &renderer::Style,
viewport: &Rectangle,
- spacing: u16,
- resize_leeway: Option<u16>,
+ spacing: f32,
+ resize_leeway: Option<f32>,
style: &<Renderer::Theme as StyleSheet>::Style,
contents: impl Iterator<Item = (Pane, T)>,
draw_pane: impl Fn(
@@ -770,12 +765,11 @@ pub fn draw<Renderer, T>(
.and_then(|(split, axis)| {
let bounds = layout.bounds();
- let splits = node.split_regions(f32::from(spacing), bounds.size());
+ let splits = node.split_regions(spacing, bounds.size());
let (_axis, region, ratio) = splits.get(&split)?;
- let region =
- axis.split_line_bounds(*region, *ratio, f32::from(spacing));
+ let region = axis.split_line_bounds(*region, *ratio, spacing);
Some((axis, region + Vector::new(bounds.x, bounds.y), true))
})
@@ -788,12 +782,11 @@ pub fn draw<Renderer, T>(
cursor_position.y - bounds.y,
);
- let splits =
- node.split_regions(f32::from(spacing), bounds.size());
+ let splits = node.split_regions(spacing, bounds.size());
let (_split, axis, region) = hovered_split(
splits.iter(),
- f32::from(spacing + leeway),
+ spacing + leeway,
relative_cursor,
)?;