gled-ui 2.32.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! egui colors for the model's colors, and the scene color picker.

use egui::{Color32, WidgetText};
use strum::IntoEnumIterator;

use crate::ui::ChangeButton;
use gled_model::asset::{palette::Color, scene::color::SceneInstanceColor};

/// The egui color of a model color.
pub(crate) trait ToColor32 {
    fn color32(&self) -> Color32;
}

impl ToColor32 for Color {
    fn color32(&self) -> Color32 {
        let [r, g, b] = self.rgb8();
        Color32::from_rgb(r, g, b)
    }
}

impl ToColor32 for SceneInstanceColor {
    fn color32(&self) -> Color32 {
        let [r, g, b] = self.rgb8();
        Color32::from_rgb(r, g, b)
    }
}

impl ChangeButton for SceneInstanceColor {
    fn change_button(&mut self, ui: &mut egui::Ui) -> bool {
        egui::ComboBox::new("scene_instance_color", "")
            .selected_text(WidgetText::Text(format!("{self:?}")).background_color(self.color32()))
            .show_ui(ui, |ui| {
                for color in SceneInstanceColor::iter() {
                    ui.selectable_value(self, color, format!("{color:?}"));
                }
            })
            .response
            .changed()
    }
}