diff options
author | 2020-03-14 05:26:59 +0100 | |
---|---|---|
committer | 2020-03-14 05:27:27 +0100 | |
commit | 5c8ec4504b6541cdc588b91a6b2c7100b4a7cc77 (patch) | |
tree | 7d780613c258c02078813f5c7d8163d07acd1341 /native/src/widget/pane_grid/split.rs | |
parent | 460565056e6787d5cc7cb0d1d49c9e8ff1f77850 (diff) | |
download | iced-5c8ec4504b6541cdc588b91a6b2c7100b4a7cc77.tar.gz iced-5c8ec4504b6541cdc588b91a6b2c7100b4a7cc77.tar.bz2 iced-5c8ec4504b6541cdc588b91a6b2c7100b4a7cc77.zip |
Create module boundaries for `pane_grid` logic
Diffstat (limited to 'native/src/widget/pane_grid/split.rs')
-rw-r--r-- | native/src/widget/pane_grid/split.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/native/src/widget/pane_grid/split.rs b/native/src/widget/pane_grid/split.rs new file mode 100644 index 00000000..ca9ed5e1 --- /dev/null +++ b/native/src/widget/pane_grid/split.rs @@ -0,0 +1,54 @@ +use crate::Rectangle; + +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +pub enum Split { + Horizontal, + Vertical, +} + +impl Split { + pub(super) fn apply( + &self, + rectangle: &Rectangle, + ratio: f32, + halved_spacing: f32, + ) -> (Rectangle, Rectangle) { + match self { + Split::Horizontal => { + let width_left = + (rectangle.width * ratio).round() - halved_spacing; + let width_right = rectangle.width - width_left - halved_spacing; + + ( + Rectangle { + width: width_left, + ..*rectangle + }, + Rectangle { + x: rectangle.x + width_left + halved_spacing, + width: width_right, + ..*rectangle + }, + ) + } + Split::Vertical => { + let height_top = + (rectangle.height * ratio).round() - halved_spacing; + let height_bottom = + rectangle.height - height_top - halved_spacing; + + ( + Rectangle { + height: height_top, + ..*rectangle + }, + Rectangle { + y: rectangle.y + height_top + halved_spacing, + height: height_bottom, + ..*rectangle + }, + ) + } + } + } +} |