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

Generic view property building, applied to TimeSeriesView's PlotLegend #6400

Merged
merged 11 commits into from
May 22, 2024
69 changes: 69 additions & 0 deletions crates/re_data_ui/src/editors/corner2d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use re_data_store::LatestAtQuery;
use re_entity_db::{external::re_query::LatestAtComponentResults, EntityDb};
use re_log_types::{EntityPath, Instance};
use re_types::blueprint::components::Corner2D;
use re_viewer_context::{UiLayout, ViewerContext};

#[allow(clippy::too_many_arguments)]
pub fn edit_corner2d(
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_ui_layout: UiLayout,
query: &LatestAtQuery,
db: &EntityDb,
entity_path: &EntityPath,
override_path: &EntityPath,
component: &LatestAtComponentResults,
instance: &Instance,
) {
let corner = component
// TODO(#5607): what should happen if the promise is still pending?
.instance::<Corner2D>(db.resolver(), instance.get() as _)
.unwrap_or_else(|| default_corner2d(ctx, query, db, entity_path));
let mut edit_corner = corner;

egui::ComboBox::from_id_source("corner2d")
.selected_text(format!("{corner}"))
.show_ui(ui, |ui| {
ui.style_mut().wrap = Some(false);
ui.set_min_width(64.0);

ui.selectable_value(
&mut edit_corner,
egui_plot::Corner::LeftTop.into(),
format!("{}", Corner2D::from(egui_plot::Corner::LeftTop)),
);
ui.selectable_value(
&mut edit_corner,
egui_plot::Corner::RightTop.into(),
format!("{}", Corner2D::from(egui_plot::Corner::RightTop)),
);
ui.selectable_value(
&mut edit_corner,
egui_plot::Corner::LeftBottom.into(),
format!("{}", Corner2D::from(egui_plot::Corner::LeftBottom)),
);
ui.selectable_value(
&mut edit_corner,
egui_plot::Corner::RightBottom.into(),
format!("{}", Corner2D::from(egui_plot::Corner::RightBottom)),
);
});

if corner != edit_corner {
ctx.save_blueprint_component(override_path, &edit_corner);
}
}

#[inline]
pub fn default_corner2d(
_ctx: &ViewerContext<'_>,
_query: &LatestAtQuery,
_db: &EntityDb,
_entity_path: &EntityPath,
) -> Corner2D {
// TODO: Want to distinguish the space view this happens in.
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
// TimeSeriesView: RightBottom
// BarChart: RightTop
Corner2D::RightBottom
}
10 changes: 9 additions & 1 deletion crates/re_data_ui/src/editors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// TODO(jleibs): Turn this into a trait
// TODO(jleibs): Turn these methods into a trait.

mod corner2d;

use egui::NumExt as _;
use re_data_store::LatestAtQuery;
use re_entity_db::{external::re_query::LatestAtComponentResults, EntityDb};
use re_log_types::{EntityPath, Instance};
use re_types::{
blueprint::components::Corner2D,
components::{
Color, MarkerShape, MarkerSize, Name, Radius, ScalarScattering, StrokeWidth, Text,
},
Expand Down Expand Up @@ -462,6 +465,11 @@ fn register_editor<'a, C>(

pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) {
register_editor::<Color>(registry, default_color, edit_color_ui);
register_editor::<Corner2D>(
registry,
corner2d::default_corner2d,
corner2d::edit_corner2d,
);
register_editor::<MarkerShape>(registry, default_marker_shape, edit_marker_shape_ui);
register_editor::<MarkerSize>(registry, default_marker_size, edit_marker_size_ui);
register_editor::<Name>(registry, default_name, edit_name_ui);
Expand Down