Skip to main content

waft_material/compose/
adapt_strategy.rs

1//! What a pane does when there is no partition left for it.
2
3use crate::compose::ThreePaneScaffoldRole;
4
5/// What a pane does when there is no partition left for it.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum AdaptStrategy {
8    /// Hide the pane.
9    Hide,
10    /// Show the pane under another one, at most half its height.
11    Reflow {
12        /// The pane this one is shown under.
13        reflow_under: ThreePaneScaffoldRole,
14    },
15}
16
17/// One [`AdaptStrategy`] per pane role.
18#[derive(Clone, Debug, PartialEq, Eq)]
19pub struct ThreePaneScaffoldAdaptStrategies {
20    /// The primary pane's strategy.
21    pub primary: AdaptStrategy,
22    /// The secondary pane's strategy.
23    pub secondary: AdaptStrategy,
24    /// The tertiary pane's strategy.
25    pub tertiary: AdaptStrategy,
26}
27
28impl ThreePaneScaffoldAdaptStrategies {
29    /// The strategy for `role`.
30    pub fn get(&self, role: ThreePaneScaffoldRole) -> AdaptStrategy {
31        match role {
32            ThreePaneScaffoldRole::Primary => self.primary,
33            ThreePaneScaffoldRole::Secondary => self.secondary,
34            ThreePaneScaffoldRole::Tertiary => self.tertiary,
35        }
36    }
37
38    /// All three hide, as Compose's `ListDetailPaneScaffoldDefaults` does.
39    pub fn list_detail() -> ThreePaneScaffoldAdaptStrategies {
40        ThreePaneScaffoldAdaptStrategies {
41            primary: AdaptStrategy::Hide,
42            secondary: AdaptStrategy::Hide,
43            tertiary: AdaptStrategy::Hide,
44        }
45    }
46
47    /// The supporting pane reflows under the main one, as Compose's
48    /// `SupportingPaneScaffoldDefaults` does.
49    pub fn supporting() -> ThreePaneScaffoldAdaptStrategies {
50        ThreePaneScaffoldAdaptStrategies {
51            primary: AdaptStrategy::Hide,
52            secondary: AdaptStrategy::Reflow {
53                reflow_under: ThreePaneScaffoldRole::Primary,
54            },
55            tertiary: AdaptStrategy::Hide,
56        }
57    }
58}