gled-ui 2.33.0

gled's egui interface, shared by the desktop app and the browser
Documentation
use crate::ui::{
    asset_tree::{AssetTree, TreeSelection},
    window_common::{gled_window_frame, raise, tool_window_builder},
};
use egui::{Id, Vec2, ViewportId};
use gled_model::{asset::project::Project, collection::Collections};
use gled_protocol::action::UiAction;

#[derive(Debug, Default)]
pub(crate) struct ProjectsWindow {
    open: bool,
    /// Set while the window still has to be brought forward.
    raise: bool,
    dirty: bool,
    tree: AssetTree<Project>,
}

impl ProjectsWindow {
    #[cfg_attr(feature = "profiling", profiling::function)]
    pub(crate) fn update(&mut self, ctx: &egui::Context, collections: &mut Collections) {
        if !self.open {
            return;
        }

        ctx.show_viewport_immediate(
            ViewportId(Id::new("projects window")),
            tool_window_builder("Projects")
                .with_inner_size(Vec2::new(550.0, 500.0))
                .with_min_inner_size(Vec2::new(550.0, 500.0)),
            |ctx, _viewport_class| {
                raise(ctx, &mut self.raise);
                ctx.input(|input| {
                    if input.viewport().close_requested()
                        || crate::ui::window_common::embedded_close_clicked("Projects")
                    {
                        self.open = false;
                    }
                });

                gled_window_frame(ctx, "Projects", |ui| {
                    egui::Panel::left("projects tree")
                        .exact_size(200.0)
                        .resizable(false)
                        .show(ui, |ui| {
                            if self.tree.show(
                                ui,
                                ui.make_persistent_id("projects_tree"),
                                collections,
                            ) {
                                self.dirty = false;
                            }
                        });

                    egui::CentralPanel::default().show(ui, |ui| {
                        self.tree.common_settings(ui, &mut self.dirty, collections);
                        if let TreeSelection::Asset(project) = self.tree.selected() {
                            ui.label(format!(
                                "Scenes in Grid: {}",
                                project.data.scenes_instances_grid_len()
                            ));
                            ui.vertical_centered_justified(|ui| {
                                if ui.button("Load Project").clicked() {
                                    UiAction::SetProject(project.id).enqueue();
                                    self.open = false;
                                }
                            });
                        }
                    });
                });
            },
        );
    }

    pub(crate) fn open(&mut self) {
        self.open = true;
        self.raise = true;
    }
}