show/hide images/shapes and images visible in tree view
This commit is contained in:
parent
374fce86e1
commit
10b120512f
3 changed files with 66 additions and 15 deletions
|
@ -16,6 +16,9 @@ pub use helpers::*;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct PointSize(pub f32);
|
||||
|
||||
#[derive(Component, Debug, Deref, DerefMut)]
|
||||
pub struct ImageName(pub String);
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct ShapeData {
|
||||
pub name: Option<String>,
|
||||
|
|
57
src/ui.rs
57
src/ui.rs
|
@ -36,11 +36,13 @@ pub fn action_bar_sys(
|
|||
.set_title("Please dont try to pick a cat instead of an image(although you can pick a cat image)")
|
||||
.pick_file();
|
||||
if let Some(file) = file {
|
||||
let name = String::from(file.file_name().unwrap().to_str().unwrap_or("Image"));
|
||||
let image: Handle<Image> = assets.load(file);
|
||||
coms.spawn_bundle(SpriteBundle {
|
||||
texture: image,
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
.insert(ImageName(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,6 +85,8 @@ pub fn shape_tree_sys(
|
|||
global_transforms: Query<&GlobalTransform>,
|
||||
mut paths: Query<&mut Path>,
|
||||
mut draw_modes: Query<&mut DrawMode, With<Path>>,
|
||||
mut visible: Query<&mut Visibility, Or<(With<Path>, With<Sprite>)>>,
|
||||
mut images: Query<(Entity, &mut ImageName), With<Sprite>>,
|
||||
) {
|
||||
if !shapes.is_empty() {
|
||||
egui::Window::new("Shape Tree")
|
||||
|
@ -162,16 +166,27 @@ pub fn shape_tree_sys(
|
|||
coms.entity(sd.main_shape).despawn_recursive();
|
||||
coms.entity(e).despawn();
|
||||
}
|
||||
let mut v = visible.get_mut(sd.main_shape).unwrap();
|
||||
let text = if v.is_visible { egui::RichText::new("V") } else { egui::RichText::new("V").strikethrough() };
|
||||
if hui.button(text).clicked() {
|
||||
v.is_visible ^= true;
|
||||
}
|
||||
});
|
||||
ui_func(ui);
|
||||
});
|
||||
let closed = collapse.fully_closed();
|
||||
if closed && hui.button("E").clicked() {
|
||||
*name_change = Some((e, default_name));
|
||||
}
|
||||
if closed && hui.button("D").clicked() {
|
||||
coms.entity(sd.main_shape).despawn_recursive();
|
||||
coms.entity(e).despawn();
|
||||
if collapse.fully_closed() {
|
||||
if hui.button("E").clicked() {
|
||||
*name_change = Some((e, default_name));
|
||||
}
|
||||
if hui.button("D").clicked() {
|
||||
coms.entity(sd.main_shape).despawn_recursive();
|
||||
coms.entity(e).despawn();
|
||||
}
|
||||
let mut v = visible.get_mut(sd.main_shape).unwrap();
|
||||
let text = if v.is_visible { egui::RichText::new("V") } else { egui::RichText::new("V").strikethrough() };
|
||||
if hui.button(text).clicked() {
|
||||
v.is_visible ^= true;
|
||||
}
|
||||
}
|
||||
let d_normal = DrawMode::Outlined {
|
||||
fill_mode: FillMode::color(Color::rgba(0.0, 0.5, 0.5, 0.4)),
|
||||
|
@ -192,6 +207,32 @@ pub fn shape_tree_sys(
|
|||
}
|
||||
});
|
||||
}
|
||||
for (e, mut n) in images.iter_mut() {
|
||||
if let Some((ne, name)) = &mut *name_change && *ne == e {
|
||||
let te = egui::TextEdit::singleline(name);
|
||||
|
||||
if ui.add(te).lost_focus() {
|
||||
let (_, name) = name_change.take().unwrap();
|
||||
**n = name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui.horizontal(|hui| {
|
||||
hui.label(&**n);
|
||||
if hui.button("E").clicked() {
|
||||
*name_change = Some((e, n.clone()));
|
||||
}
|
||||
if hui.button("D").clicked() {
|
||||
coms.entity(e).despawn();
|
||||
}
|
||||
let mut v = visible.get_mut(e).unwrap();
|
||||
let text = if v.is_visible { egui::RichText::new("V") } else { egui::RichText::new("V").strikethrough() };
|
||||
if hui.button(text).clicked() {
|
||||
v.is_visible ^= true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue