Skip to content

Commit

Permalink
unify enum edit ui and add background kind
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Jun 3, 2024
1 parent 6ca5a92 commit 3a78e80
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
34 changes: 0 additions & 34 deletions crates/re_edit_ui/src/corner2d.rs

This file was deleted.

25 changes: 25 additions & 0 deletions crates/re_edit_ui/src/datatype_editors/enum_combobox.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::response_utils::response_with_changes_of_inner;

pub fn edit_enum<Value: PartialEq + std::fmt::Display + Copy>(
ui: &mut egui::Ui,
id_source: &str,
value: &mut Value,
variants: &[Value],
) -> egui::Response {
response_with_changes_of_inner(
egui::ComboBox::from_id_source(id_source)
.selected_text(format!("{value}"))
.show_ui(ui, |ui| {
let mut iter = variants.iter().copied();
let Some(first) = iter.next() else {
return ui.label("<no variants>");
};

let mut response = ui.selectable_value(value, first, format!("{first}"));
for variant in iter {
response |= ui.selectable_value(value, variant, format!("{variant}"));
}
response
}),
)
}
2 changes: 2 additions & 0 deletions crates/re_edit_ui/src/datatype_editors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod bool_toggle;
mod enum_combobox;
mod float_drag;
mod singleline_string;

pub use bool_toggle::edit_bool;
pub use enum_combobox::edit_enum;
pub use float_drag::edit_f32_zero_to_inf;
pub use singleline_string::edit_singleline_string;
9 changes: 6 additions & 3 deletions crates/re_edit_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
//! The only entry point is [`register_editors`], which registers all editors in the component UI registry.
//! This should be called by `re_viewer` on startup.
mod corner2d;
mod datatype_editors;
mod marker_shape;
mod response_utils;

use datatype_editors::edit_enum;
use re_types::{
blueprint::components::Visible,
blueprint::components::{BackgroundKind, Corner2D, Visible},
components::{Color, MarkerSize, Name, Radius, StrokeWidth, Text},
};
use re_viewer_context::ViewerContext;
Expand Down Expand Up @@ -37,7 +37,6 @@ fn edit_color_ui(_ctx: &ViewerContext<'_>, ui: &mut egui::Ui, value: &mut Color)
/// This crate is meant to be a leaf crate in the viewer ecosystem and should only be used by the `re_viewer` crate itself.
pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) {
registry.add_editor(edit_color_ui);
registry.add_editor(corner2d::edit_corner2d);
registry.add_editor(marker_shape::edit_marker_shape_ui);

registry.add_editor::<Visible>(datatype_editors::edit_bool);
Expand All @@ -48,4 +47,8 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) {
registry.add_editor::<Radius>(datatype_editors::edit_f32_zero_to_inf);
registry.add_editor::<MarkerSize>(datatype_editors::edit_f32_zero_to_inf);
registry.add_editor::<StrokeWidth>(datatype_editors::edit_f32_zero_to_inf);

registry.add_editor(|_ctx, ui, value| edit_enum(ui, "corner2d", value, &Corner2D::ALL));
registry
.add_editor(|_ctx, ui, value| edit_enum(ui, "backgroundkind", value, &BackgroundKind::ALL));
}

0 comments on commit 3a78e80

Please sign in to comment.