From fd0f6ddb21afb273b8e9d2f7cd46aecddc7783b6 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 13 Mar 2022 15:25:30 +0000 Subject: [PATCH] messing around with egui editor prototype --- src/bin/editor.rs | 50 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/bin/editor.rs b/src/bin/editor.rs index fcb0f38..e8d22fb 100644 --- a/src/bin/editor.rs +++ b/src/bin/editor.rs @@ -4,7 +4,6 @@ use peachy::{Colour, Config, Game, Palette}; struct EditorState { game: Option, - // selected_palette: Option<&Palette>, } impl epi::App for EditorState { @@ -37,21 +36,40 @@ impl epi::App for EditorState { // todo if game is none, add a "load project" window? if let Some(game) = &mut self.game { - // for palette in &mut game.palettes { - // } - // todo store selected palette in application state - // todo show palette window if selected - let palette = game.find_palette("example palette".into()); + egui::Window::new("palettes") + .default_width(200.0) + .collapsible(false) + .show(ctx, |ui| { + for palette in game.palettes.iter_mut() { + ui.columns(2, |columns | { + columns[0].label(&palette.name); - if let Some(palette) = palette { - egui::Window::new(&palette.name) - .default_width(200.0) - .collapsible(false) - .show(ctx, |ui| { - ui.label("palette name"); - ui.text_edit_singleline(&mut palette.name); - }); - } + if columns[1].button("edit").clicked() { + egui::Window::new(&palette.name) + .default_width(200.0) + .collapsible(true) + .show(ctx, |ui| { + for (i, colour) in palette.colours.iter().enumerate() { + ui.columns(2, |row| { + // todo edit each colour... this is broken + row[0].color_edit_button_rgb(&mut [ + colour.red as f32, + colour.green as f32, + colour.blue as f32 + ]); + + if row[1].button("delete").clicked() { + // can't alter palettes while iterating... what to do? + // palette.colours.remove(i); + } + }); + } + // todo "add colour" button + }); + } + }); + } + }); } }); } @@ -93,7 +111,7 @@ fn main() { scenes: vec![], tiles: vec![], music: vec![] - }) + }), }; let native_options = eframe::NativeOptions::default();