diff options
author | 2020-03-20 12:10:52 +0100 | |
---|---|---|
committer | 2020-03-20 12:10:52 +0100 | |
commit | f7ec679fec1b69c6dc5bc12d60627629f086bf22 (patch) | |
tree | 58ec4dd11e50f11ef85b972fee211930e7a0e7c0 /native/src/widget/pane_grid/axis.rs | |
parent | 93f5640a2dc06d8f1bf2b0d033d45c62f8985380 (diff) | |
parent | fb744a338c1b7566a3db9a3d24c03729b4858217 (diff) | |
download | iced-f7ec679fec1b69c6dc5bc12d60627629f086bf22.tar.gz iced-f7ec679fec1b69c6dc5bc12d60627629f086bf22.tar.bz2 iced-f7ec679fec1b69c6dc5bc12d60627629f086bf22.zip |
Merge pull request #224 from hecrj/feature/panes-widget
Pane grid widget
Diffstat (limited to 'native/src/widget/pane_grid/axis.rs')
-rw-r--r-- | native/src/widget/pane_grid/axis.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/native/src/widget/pane_grid/axis.rs b/native/src/widget/pane_grid/axis.rs new file mode 100644 index 00000000..f0e3f362 --- /dev/null +++ b/native/src/widget/pane_grid/axis.rs @@ -0,0 +1,54 @@ +use crate::Rectangle; + +/// A fixed reference line for the measurement of coordinates. +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +pub enum Axis { + /// The horizontal axis: — + Horizontal, + /// The vertical axis: | + Vertical, +} + +impl Axis { + pub(super) fn split( + &self, + rectangle: &Rectangle, + ratio: f32, + halved_spacing: f32, + ) -> (Rectangle, Rectangle) { + match self { + Axis::Horizontal => { + let height_top = (rectangle.height * ratio).round(); + let height_bottom = rectangle.height - height_top; + + ( + Rectangle { + height: height_top - halved_spacing, + ..*rectangle + }, + Rectangle { + y: rectangle.y + height_top + halved_spacing, + height: height_bottom - halved_spacing, + ..*rectangle + }, + ) + } + Axis::Vertical => { + let width_left = (rectangle.width * ratio).round(); + let width_right = rectangle.width - width_left; + + ( + Rectangle { + width: width_left - halved_spacing, + ..*rectangle + }, + Rectangle { + x: rectangle.x + width_left + halved_spacing, + width: width_right - halved_spacing, + ..*rectangle + }, + ) + } + } + } +} |