Skip to content

Commit

Permalink
Wire up an editor for the color component
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jan 25, 2024
1 parent 542ccff commit 5b5146f
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
6 changes: 5 additions & 1 deletion crates/re_data_ui/src/component_ui_registry.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use re_data_store::{DataStore, LatestAtQuery};
use re_log_types::{external::arrow2, EntityPath};
use re_query::ComponentWithInstances;
use re_types::external::arrow2::array::Utf8Array;
use re_types::{external::arrow2::array::Utf8Array, Loggable};
use re_viewer_context::{ComponentUiRegistry, UiVerbosity, ViewerContext};

use crate::editors::edit_color_ui;

use super::EntityDataUi;

pub fn create_component_ui_registry() -> ComponentUiRegistry {
Expand All @@ -29,6 +31,8 @@ pub fn create_component_ui_registry() -> ComponentUiRegistry {

add_to_registry::<re_types::blueprint::components::IncludedQueries>(&mut registry);

registry.add_editor(re_types::components::Color::name(), Box::new(edit_color_ui));

registry
}

Expand Down
40 changes: 40 additions & 0 deletions crates/re_data_ui/src/editors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// TODO(jleibs): Turn this into a trait

use re_data_store::{DataStore, LatestAtQuery};
use re_log_types::EntityPath;
use re_query::ComponentWithInstances;
use re_types::components::Color;
use re_viewer_context::{UiVerbosity, ViewerContext};

#[allow(clippy::too_many_arguments)]
pub fn edit_color_ui(
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_verbosity: UiVerbosity,
_query: &LatestAtQuery,
_store: &DataStore,
_entity_path: &EntityPath,
override_path: &EntityPath,
component: &ComponentWithInstances,
instance_key: &re_types::components::InstanceKey,
) {
// TODO(jleibs): Handle missing data still
if let Ok(current_color) = component.lookup::<Color>(instance_key) {
let [r, g, b, a] = current_color.to_array();
let current_color = egui::Color32::from_rgba_unmultiplied(r, g, b, a);
let mut edit_color = current_color;

egui::color_picker::color_edit_button_srgba(
ui,
&mut edit_color,
egui::color_picker::Alpha::Opaque,
);

if edit_color != current_color {
let [r, g, b, a] = edit_color.to_array();
let new_color = Color::from_unmultiplied_rgba(r, g, b, a);

ctx.save_blueprint_component(override_path, new_color);
}
}
}
1 change: 1 addition & 0 deletions crates/re_data_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod component;
mod component_path;
mod component_ui_registry;
mod data;
mod editors;
mod entity_db;
mod entity_path;
mod image;
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/src/ui/override_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn override_ui(
&query,
store,
entity_path,
&overrides.override_path,
&component_data,
instance_key,
);
Expand Down
21 changes: 14 additions & 7 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use re_types::{
components::{Color, PinholeProjection, Transform3D},
tensor_data::TensorDataMeaning,
};
use re_types_core::Loggable;
use re_types_core::{components::InstanceKey, Loggable};
use re_ui::list_item::ListItem;
use re_ui::ReUi;
use re_ui::SyntaxHighlighting as _;
Expand Down Expand Up @@ -195,11 +195,18 @@ impl SelectionPanel {

// Special section for space-view-entities
if let Item::InstancePath(Some(space_view_id), instance_path) = item {
if let Some(space_view) = viewport.blueprint.space_views.get(space_view_id) {
ctx.re_ui
.large_collapsing_header(ui, "Component Overrides", true, |ui| {
override_ui(ctx, space_view, instance_path, ui);
});
if instance_path.instance_key == InstanceKey::SPLAT {
if let Some(space_view) = viewport.blueprint.space_views.get(space_view_id)
{
ctx.re_ui.large_collapsing_header(
ui,
"Component Overrides",
true,
|ui| {
override_ui(ctx, space_view, instance_path, ui);
},
);
}
}
}

Expand Down Expand Up @@ -922,7 +929,7 @@ fn blueprint_ui(
data_result.accumulated_properties(),
);
data_result.save_override(Some(props), ctx);
entity_overrides_ui(ctx, ui, &space_view_class, &data_result);
//entity_overrides_ui(ctx, ui, &space_view_class, &data_result);
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions crates/re_viewer_context/src/blueprint_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use re_log_types::{DataCell, DataRow, EntityPath, RowId, Time, TimePoint, Timeline};
use re_types::ComponentName;
use re_types::{components::InstanceKey, ComponentName};

use crate::{SystemCommand, SystemCommandSender as _, ViewerContext};

Expand All @@ -23,12 +23,18 @@ impl ViewerContext<'_> {
{
let timepoint = blueprint_timepoint_for_writes();

match DataRow::from_cells1_sized(
let mut splat_cell: DataCell = [InstanceKey::SPLAT].into();
splat_cell.compute_size_bytes();

let mut component: DataCell = [component].into();
component.compute_size_bytes();

match DataRow::from_cells(
RowId::new(),
entity_path.clone(),
timepoint.clone(),
entity_path.clone(),
1,
[component],
[splat_cell, component],
) {
Ok(row) => self
.command_sender
Expand Down
3 changes: 3 additions & 0 deletions crates/re_viewer_context/src/component_ui_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ComponentEditCallback = Box<
&LatestAtQuery,
&DataStore,
&EntityPath,
&EntityPath,
&ComponentWithInstances,
&InstanceKey,
) + Send
Expand Down Expand Up @@ -138,6 +139,7 @@ impl ComponentUiRegistry {
query: &LatestAtQuery,
store: &DataStore,
entity_path: &EntityPath,
override_path: &EntityPath,
component: &ComponentWithInstances,
instance_key: &InstanceKey,
) {
Expand All @@ -157,6 +159,7 @@ impl ComponentUiRegistry {
query,
store,
entity_path,
override_path,
component,
instance_key,
);
Expand Down

0 comments on commit 5b5146f

Please sign in to comment.