ui/
state.rs

1//! We need to share various bits and bops throughout the different UI layers, we define a singleton
2//! resource that contains this code.
3
4use crate::layout::EditorPanels;
5use bevy::prelude::Resource;
6use egui_dock::{DockState, NodeIndex};
7
8/// Holds the internal state of various UI components.
9///
10/// Most notably, it holds the [`DockState`] used to build the general layout docks.
11#[derive(Resource)]
12pub struct UiState {
13    /// The [`DockState`](https://docs.rs/egui_dock/latest/egui_dock/dock_state/struct.DockState.html)
14    /// that controls most of the general layout.
15    pub dock_state: DockState<EditorPanels>,
16}
17
18impl Default for UiState {
19    fn default() -> Self {
20        let mut state = DockState::new(vec![EditorPanels::Editor]);
21        let surface = state.main_surface_mut();
22        let [_, _assets] = surface.split_below(NodeIndex::root(), 0.9, vec![EditorPanels::Assets]);
23        let [_, layers] = surface.split_right(
24            NodeIndex::root(),
25            0.8,
26            vec![EditorPanels::Layers, EditorPanels::Levels],
27        );
28        let [_, _settings] = surface.split_below(layers, 0.6, vec![EditorPanels::Settings]);
29
30        Self { dock_state: state }
31    }
32}