Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back display ui for Name and Text components #6764

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/re_edit_ui/src/datatype_editors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
65 changes: 65 additions & 0 deletions crates/re_edit_ui/src/datatype_editors/singleline_string.rs
Original file line number Diff line number Diff line change
@@ -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<'_>,
Expand All @@ -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());
}
7 changes: 5 additions & 2 deletions crates/re_edit_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -59,7 +60,9 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) {
registry.add_singleline_editor_ui::<LockRangeDuringZoom>(edit_bool);

registry.add_singleline_editor_ui::<Text>(edit_singleline_string);
registry.add_display_ui(Text::name(), Box::new(display_text_ui));
registry.add_singleline_editor_ui::<Name>(edit_singleline_string);
registry.add_display_ui(Name::name(), Box::new(display_name_ui));

registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::<BackgroundKind>(ui, value));
registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::<Colormap>(ui, value));
Expand Down
Loading