-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic view property building, applied to
TimeSeriesView
's `PlotLe…
…gend` (#6400) ### What * Part of #6237 What's happening: * edit uis for: * corner2d * visible * introduce generic method for drawing ui for a view property Next steps in this area: * improve edit ui overall * make it easier to implement (with less boilerplate) * make default providing easier & more powerful (as described in passing there) * do this for more/all properties ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6400?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6400?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! - [PR Build Summary](https://build.rerun.io/pr/6400) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
- Loading branch information
Showing
10 changed files
with
226 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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(#4194): Want to distinguish the space view this happens in. | ||
// TimeSeriesView: RightBottom | ||
// BarChart: RightTop | ||
// Need to make handling of editors a bit more powerful for this. | ||
// Rough idea right now is to have "default providers" which can be either a View or a Visualizer. | ||
// They then get queried with a ComponentName and return LatestAtComponentResults (or similar). | ||
Corner2D::RightBottom | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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::Visible; | ||
use re_viewer_context::{UiLayout, ViewerContext}; | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub fn edit_visible( | ||
ctx: &ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
_ui_layout: UiLayout, | ||
query: &LatestAtQuery, | ||
db: &EntityDb, | ||
entity_path: &EntityPath, | ||
override_path: &EntityPath, | ||
component: &LatestAtComponentResults, | ||
instance: &Instance, | ||
) { | ||
let visible = component | ||
// TODO(#5607): what should happen if the promise is still pending? | ||
.instance::<Visible>(db.resolver(), instance.get() as _) | ||
.unwrap_or_else(|| default_visible(ctx, query, db, entity_path)); | ||
let mut edit_visible = visible; | ||
|
||
ui.scope(|ui| { | ||
ui.visuals_mut().widgets.hovered.expansion = 0.0; | ||
ui.visuals_mut().widgets.active.expansion = 0.0; | ||
ui.add(re_ui::toggle_switch(15.0, &mut edit_visible.0)); | ||
}); | ||
|
||
if edit_visible != visible { | ||
ctx.save_blueprint_component(override_path, &edit_visible); | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn default_visible( | ||
_ctx: &ViewerContext<'_>, | ||
_query: &LatestAtQuery, | ||
_db: &EntityDb, | ||
_entity_path: &EntityPath, | ||
) -> Visible { | ||
Visible(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.