Skip to main content

iced_resizable_split/
state.rs

1#[derive(Clone, Copy, PartialEq)]
2pub struct State {
3    ratio: f32,
4
5    first_split_min: f32,
6    second_split_min: f32,
7}
8
9impl Default for State {
10    fn default() -> Self {
11        Self {
12            ratio: 0.5,
13            first_split_min: 0.05,
14            second_split_min: 0.95,
15        }
16    }
17}
18
19pub(super) type IsDragging = bool;
20
21impl State {
22    #[must_use]
23    pub const fn new(initial_ratio: f32, first_split_min: f32, second_split_min: f32) -> Self {
24        Self {
25            ratio: initial_ratio,
26            first_split_min,
27            second_split_min,
28        }
29    }
30
31    pub const fn update(&mut self, new_state: Self) {
32        *self = new_state;
33    }
34
35    pub(super) const fn copy_with_new_ratio(&self, ratio: f32) -> Self {
36        Self { ratio, ..*self }
37    }
38
39    pub(super) const fn ratio(&self) -> f32 {
40        self.ratio
41    }
42}