iced_resizable_split/
state.rs1#[derive(Debug, 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
19#[derive(Debug, Default, Clone, Copy)]
20pub(crate) struct InternalState {
21 pub(crate) is_dragging: bool,
22 pub(crate) is_hovering: bool,
23}
24
25impl State {
26 #[must_use]
27 pub const fn new(initial_ratio: f32, first_split_min: f32, second_split_min: f32) -> Self {
28 Self {
29 ratio: initial_ratio,
30 first_split_min,
31 second_split_min,
32 }
33 }
34
35 pub const fn update(&mut self, new_state: Self) {
36 *self = new_state;
37 }
38
39 pub(crate) const fn copy_with_new_ratio(&self, ratio: f32) -> Self {
40 let ratio = ratio.clamp(self.first_split_min, self.second_split_min);
41 Self { ratio, ..*self }
42 }
43
44 pub(crate) const fn ratio(&self) -> f32 {
45 self.ratio
46 }
47}