messing around with egui editor prototype

This commit is contained in:
Max Bradbury 2022-03-13 15:25:30 +00:00
parent 75ca8c84ea
commit fd0f6ddb21
1 changed files with 34 additions and 16 deletions

View File

@ -4,7 +4,6 @@ use peachy::{Colour, Config, Game, Palette};
struct EditorState { struct EditorState {
game: Option<peachy::Game>, game: Option<peachy::Game>,
// selected_palette: Option<&Palette>,
} }
impl epi::App for EditorState { impl epi::App for EditorState {
@ -37,21 +36,40 @@ impl epi::App for EditorState {
// todo if game is none, add a "load project" window? // todo if game is none, add a "load project" window?
if let Some(game) = &mut self.game { if let Some(game) = &mut self.game {
// for palette in &mut game.palettes { egui::Window::new("palettes")
// }
// todo store selected palette in application state
// todo show palette window if selected
let palette = game.find_palette("example palette".into());
if let Some(palette) = palette {
egui::Window::new(&palette.name)
.default_width(200.0) .default_width(200.0)
.collapsible(false) .collapsible(false)
.show(ctx, |ui| { .show(ctx, |ui| {
ui.label("palette name"); for palette in game.palettes.iter_mut() {
ui.text_edit_singleline(&mut palette.name); ui.columns(2, |columns | {
columns[0].label(&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![], scenes: vec![],
tiles: vec![], tiles: vec![],
music: vec![] music: vec![]
}) }),
}; };
let native_options = eframe::NativeOptions::default(); let native_options = eframe::NativeOptions::default();