diff --git a/crates/re_edit_ui/src/datatype_editors/mod.rs b/crates/re_edit_ui/src/datatype_editors/mod.rs index 8b547c4168c8..068ca0c7fb39 100644 --- a/crates/re_edit_ui/src/datatype_editors/mod.rs +++ b/crates/re_edit_ui/src/datatype_editors/mod.rs @@ -9,4 +9,4 @@ pub use float_drag::{ edit_f32_min_to_max_float_raw, edit_f32_zero_to_max, edit_f32_zero_to_max_float_raw, edit_f32_zero_to_one, }; -pub use singleline_string::edit_singleline_string; +pub use singleline_string::{display_name_ui, display_text_ui, edit_singleline_string}; diff --git a/crates/re_edit_ui/src/datatype_editors/singleline_string.rs b/crates/re_edit_ui/src/datatype_editors/singleline_string.rs index 22e3bd9a4988..ce64d3bf86f4 100644 --- a/crates/re_edit_ui/src/datatype_editors/singleline_string.rs +++ b/crates/re_edit_ui/src/datatype_editors/singleline_string.rs @@ -1,3 +1,14 @@ +use re_types::{ + components::{Name, Text}, + external::arrow2, + Loggable as _, +}; +use re_ui::UiExt as _; +use re_viewer_context::{ + external::{re_data_store::LatestAtQuery, re_entity_db::EntityDb, re_log_types::EntityPath}, + UiLayout, ViewerContext, +}; + /// Generic singleline string editor. pub fn edit_singleline_string( _ctx: &re_viewer_context::ViewerContext<'_>, @@ -17,3 +28,57 @@ fn edit_singleline_string_impl( *value = edit_name.into(); response } + +// TODO(#6661): Should be merged with edit_singleline_string. +pub fn display_text_ui( + _ctx: &ViewerContext<'_>, + ui: &mut egui::Ui, + _layout: UiLayout, + _query: &LatestAtQuery, + _db: &EntityDb, + _path: &EntityPath, + data: &dyn arrow2::array::Array, +) { + let text = match Text::from_arrow(data) { + Ok(text) => text.first().cloned(), + Err(err) => { + ui.error_label("failed to deserialize") + .on_hover_text(err.to_string()); + return; + } + }; + + let Some(text) = text else { + ui.weak("(none)"); + return; + }; + + ui.label(text.as_str()); +} + +// TODO(#6661): Should be merged with edit_singleline_string. +pub fn display_name_ui( + _ctx: &ViewerContext<'_>, + ui: &mut egui::Ui, + _layout: UiLayout, + _query: &LatestAtQuery, + _db: &EntityDb, + _path: &EntityPath, + data: &dyn arrow2::array::Array, +) { + let name = match Name::from_arrow(data) { + Ok(name) => name.first().cloned(), + Err(err) => { + ui.error_label("failed to deserialize") + .on_hover_text(err.to_string()); + return; + } + }; + + let Some(name) = name else { + ui.weak("(none)"); + return; + }; + + ui.label(name.as_str()); +} diff --git a/crates/re_edit_ui/src/lib.rs b/crates/re_edit_ui/src/lib.rs index 4235933631d8..c8f80ca5b91b 100644 --- a/crates/re_edit_ui/src/lib.rs +++ b/crates/re_edit_ui/src/lib.rs @@ -13,8 +13,9 @@ mod response_utils; mod visual_bounds2d; use datatype_editors::{ - edit_bool, edit_bool_raw, edit_enum, edit_f32_min_to_max_float_raw, edit_f32_zero_to_max, - edit_f32_zero_to_max_float_raw, edit_f32_zero_to_one, edit_singleline_string, + display_name_ui, display_text_ui, edit_bool, edit_bool_raw, edit_enum, + edit_f32_min_to_max_float_raw, edit_f32_zero_to_max, edit_f32_zero_to_max_float_raw, + edit_f32_zero_to_one, edit_singleline_string, }; use re_types::{ blueprint::components::{BackgroundKind, Corner2D, LockRangeDuringZoom, ViewFit, Visible}, @@ -59,7 +60,9 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_singleline_editor_ui::(edit_bool); registry.add_singleline_editor_ui::(edit_singleline_string); + registry.add_display_ui(Text::name(), Box::new(display_text_ui)); registry.add_singleline_editor_ui::(edit_singleline_string); + registry.add_display_ui(Name::name(), Box::new(display_name_ui)); registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::(ui, value)); registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::(ui, value));