From 91e31fed7ed6e86e6cd935804adcf0024ae0e1d7 Mon Sep 17 00:00:00 2001 From: RustyStriker Date: Mon, 15 Aug 2022 23:25:47 +0300 Subject: [PATCH] can now change colors! --- src/ui.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index a439127..05f7e5c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -116,8 +116,9 @@ pub fn items_tree_sys( mut selected: ResMut, mut egui_ctx: ResMut, shapes:Query<(Entity, &ShapeData)>, - mut visible: Query<&mut Visibility, Or<(With, With)>>, images: Query<(Entity, &ImageName), With>, + mut draw_modes: Query<&mut DrawMode, With>, + mut visible: Query<&mut Visibility, Or<(With, With)>>, ) { egui::Window::new("Items") .default_pos((10.0,100.0)) @@ -125,11 +126,12 @@ pub fn items_tree_sys( .resizable(false) .show(egui_ctx.ctx_mut(), |ui| { for (e, sd) in shapes.iter() { + let entity_selected = if let Some(se) = **selected && se == e { true } else { false }; ui.horizontal(|hui| { - let color = if let Some(se) = **selected && se == e { egui::Color32::GOLD } else { egui::Color32::WHITE }; + let color = if entity_selected { egui::Color32::GOLD } else { egui::Color32::WHITE }; let label = egui::Label::new(egui::RichText::new(&sd.name).color(color)).sense(egui::Sense::click()); if hui.add(label).clicked() { - if color == egui::Color32::GOLD { + if entity_selected { **selected = None; } else { @@ -144,13 +146,21 @@ pub fn items_tree_sys( } } }); + + if let Ok(mut dm) = draw_modes.get_mut(e) { + if let DrawMode::Outlined { fill_mode: _ , outline_mode: o } = &mut *dm { + o.color = if entity_selected { Color::GOLD } else { Color::rgba(0.0, 0.5, 0.5, 0.6) }; + } + } } for (e, n) in images.iter() { + let entity_selected = if let Some(se) = **selected && se == e { true } else { false }; + ui.horizontal(|hui| { - let color = if let Some(se) = **selected && se == e { egui::Color32::GOLD } else { egui::Color32::WHITE }; + let color = if entity_selected { egui::Color32::GOLD } else { egui::Color32::WHITE }; let label = egui::Label::new(egui::RichText::new(&**n).color(color)).sense(egui::Sense::click()); if hui.add(label).clicked() { - if color == egui::Color32::GOLD { + if entity_selected { **selected = None; } else { @@ -254,6 +264,19 @@ pub fn inspector_sys( if let Ok(mut v) = visible.get_mut(e) { ui.checkbox(&mut v.is_visible, "Visible"); } + if let Ok(mut dm) = draw_modes.get_mut(e) { + ui.separator(); + if let DrawMode::Outlined { fill_mode: f, outline_mode: _ } = &mut *dm { + ui.horizontal(|hui| { + hui.label("Color: "); + let mut color = [f.color.r(), f.color.g(), f.color.b(), f.color.a()]; + if hui.color_edit_button_rgba_unmultiplied(&mut color).changed() { + f.color = Color::from(color); + } + }); + } + } + ui.separator(); if ui.button("Delete").clicked() {