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

[pure refactor] move data ui to new re_data_ui crate #2048

Merged
merged 9 commits into from
May 5, 2023
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
44 changes: 39 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ re_build_build_info = { path = "crates/re_build_build_info", version = "=0.6.0-a
re_build_info = { path = "crates/re_build_info", version = "=0.6.0-alpha.0", default-features = false }
re_build_web_viewer = { path = "crates/re_build_web_viewer", version = "=0.6.0-alpha.0", default-features = false }
re_data_store = { path = "crates/re_data_store", version = "=0.6.0-alpha.0", default-features = false }
re_data_ui = { path = "crates/re_data_ui", version = "=0.6.0-alpha.0", default-features = false }
re_error = { path = "crates/re_error", version = "=0.6.0-alpha.0", default-features = false }
re_format = { path = "crates/re_format", version = "=0.6.0-alpha.0", default-features = false }
re_int_histogram = { path = "crates/re_int_histogram", version = "=0.6.0-alpha.0", default-features = false }
Expand Down Expand Up @@ -85,6 +86,9 @@ polars-core = "0.27.1"
polars-lazy = "0.27.1"
polars-ops = "0.27.1"
puffin = "0.14"
rfd = { version = "0.11.3", default_features = false, features = [
"xdg-portal",
] }
slotmap = { version = "1.0.6", features = ["serde"] }
smallvec = { version = "1.0", features = ["const_generics", "union"] }
thiserror = "1.0"
Expand Down
40 changes: 40 additions & 0 deletions crates/re_data_ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
authors.workspace = true
description = "Provides ui elements for Rerun component data for the Rerun Viewer."
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "re_data_ui"
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true
include = ["../../LICENSE-APACHE", "../../LICENSE-MIT", "**/*.rs", "Cargo.toml"]

[package.metadata.docs.rs]
all-features = true

[dependencies]
re_arrow_store.workspace = true
re_data_store.workspace = true
re_error.workspace = true
re_format.workspace = true
re_log_types.workspace = true
re_log.workspace = true
re_query.workspace = true
re_renderer.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true

anyhow.workspace = true
bytemuck.workspace = true
egui_extras.workspace = true
egui.workspace = true
image.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
rfd.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
puffin.workspace = true
10 changes: 10 additions & 0 deletions crates/re_data_ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_data_ui

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_data_ui.svg)](https://crates.io/crates/re_data_ui)
[![Documentation](https://docs.rs/re_data_ui/badge.svg)](https://docs.rs/re_data_ui)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Provides ui elements for Rerun component data for the Rerun Viewer.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use egui::{color_picker, Vec2};
use itertools::Itertools;
use re_log_types::{context::AnnotationInfo, AnnotationContext};
use re_viewer_context::{UiVerbosity, ViewerContext};
use re_viewer_context::{auto_color, UiVerbosity, ViewerContext};

use super::DataUi;
use crate::ui::annotations::auto_color;

const TABLE_SCROLL_AREA_HEIGHT: f32 = 500.0; // add scroll-bars when we get to this height

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use re_query::ComponentWithInstances;
use re_viewer_context::{UiVerbosity, ViewerContext};

use super::DataUi;
use crate::ui::item_ui;
use crate::item_ui;

// We do NOT implement `DataUi` for just `ComponentWithInstances`
// because we also want the context of what entity it is part of!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl DataUi for re_log_types::component_types::TextEntry {
verbosity: UiVerbosity,
_query: &re_arrow_store::LatestAtQuery,
) {
use crate::ui::view_text::level_to_rich_text;
use re_viewer_context::level_to_rich_text;

let Self { body, level } = self;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use re_log_types::{
};
use re_renderer::renderer::ColormappedTexture;
use re_ui::ReUi;
use re_viewer_context::{UiVerbosity, ViewerContext};
use re_viewer_context::{
gpu_bridge, AnnotationMap, Annotations, SceneQuery, TensorDecodeCache, TensorStats,
TensorStatsCache, UiVerbosity, ViewerContext,
};

use super::EntityDataUi;
use crate::{
misc::caches::{TensorDecodeCache, TensorStats, TensorStatsCache},
ui::annotations::AnnotationMap,
};

pub fn format_tensor_shape_single_line(
shape: &[re_log_types::component_types::TensorDimension],
Expand Down Expand Up @@ -57,7 +56,7 @@ fn tensor_ui(
let tensor_stats = *ctx.cache.entry::<TensorStatsCache>().entry(tensor);
let annotations = annotations(ctx, query, entity_path);
let debug_name = entity_path.to_string();
let texture_result = crate::gpu_bridge::tensor_to_gpu(
let texture_result = gpu_bridge::tensor_to_gpu(
ctx.render_ctx,
&debug_name,
tensor,
Expand Down Expand Up @@ -166,11 +165,11 @@ fn annotations(
ctx: &mut ViewerContext<'_>,
query: &re_arrow_store::LatestAtQuery,
entity_path: &re_data_store::EntityPath,
) -> std::sync::Arc<crate::ui::Annotations> {
) -> std::sync::Arc<Annotations> {
let mut annotation_map = AnnotationMap::default();
let entity_paths: nohash_hasher::IntSet<_> = std::iter::once(entity_path.clone()).collect();
let entity_props_map = re_data_store::EntityPropertyMap::default();
let scene_query = crate::ui::scene::SceneQuery {
let scene_query = SceneQuery {
entity_paths: &entity_paths,
timeline: query.timeline,
latest_at: query.at,
Expand Down Expand Up @@ -201,7 +200,7 @@ fn show_image_at_max_size(
};

let (response, painter) = ui.allocate_painter(desired_size, egui::Sense::hover());
if let Err(err) = crate::gpu_bridge::render_image(
if let Err(err) = gpu_bridge::render_image(
render_ctx,
&painter,
response.rect,
Expand Down Expand Up @@ -326,7 +325,7 @@ fn show_zoomed_image_region_tooltip(
response: egui::Response,
tensor: &DecodedTensor,
tensor_stats: &TensorStats,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
meter: Option<f32>,
debug_name: &str,
image_rect: egui::Rect,
Expand Down Expand Up @@ -406,7 +405,7 @@ pub fn show_zoomed_image_region(
ui: &mut egui::Ui,
tensor: &DecodedTensor,
tensor_stats: &TensorStats,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
meter: Option<f32>,
debug_name: &str,
center_texel: [isize; 2],
Expand All @@ -432,18 +431,13 @@ fn try_show_zoomed_image_region(
ui: &mut egui::Ui,
tensor: &DecodedTensor,
tensor_stats: &TensorStats,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
meter: Option<f32>,
debug_name: &str,
center_texel: [isize; 2],
) -> anyhow::Result<()> {
let texture = crate::gpu_bridge::tensor_to_gpu(
render_ctx,
debug_name,
tensor,
tensor_stats,
annotations,
)?;
let texture =
gpu_bridge::tensor_to_gpu(render_ctx, debug_name, tensor, tensor_stats, annotations)?;

let Some([height, width, _]) = tensor.image_height_width_channels() else { return Ok(()); };

Expand All @@ -463,7 +457,7 @@ fn try_show_zoomed_image_region(
POINTS_PER_TEXEL * egui::vec2(width as f32, height as f32),
);

crate::gpu_bridge::render_image(
gpu_bridge::render_image(
render_ctx,
&painter.with_clip_rect(zoom_rect),
image_rect_on_screen,
Expand Down Expand Up @@ -498,7 +492,7 @@ fn try_show_zoomed_image_region(
- zoom * egui::vec2(center_texel[0] as f32 + 0.5, center_texel[1] as f32 + 0.5),
zoom * egui::vec2(width as f32, height as f32),
);
crate::gpu_bridge::render_image(
gpu_bridge::render_image(
render_ctx,
&ui.painter().with_clip_rect(rect),
image_rect_on_screen,
Expand All @@ -515,7 +509,7 @@ fn try_show_zoomed_image_region(
fn tensor_pixel_value_ui(
ui: &mut egui::Ui,
tensor: &Tensor,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
[x, y]: [u64; 2],
meter: Option<f32>,
) {
Expand Down Expand Up @@ -676,7 +670,7 @@ fn copy_and_save_image_ui(ui: &mut egui::Ui, tensor: &Tensor, _encoded_tensor: &
match tensor.to_dynamic_image() {
Ok(dynamic_image) => {
let rgba = dynamic_image.to_rgba8();
crate::misc::Clipboard::with(|clipboard| {
re_viewer_context::Clipboard::with(|clipboard| {
clipboard.set_image(
[rgba.width() as _, rgba.height() as _],
bytemuck::cast_slice(rgba.as_raw()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use re_query::{get_component_with_instances, QueryError};
use re_viewer_context::{UiVerbosity, ViewerContext};

use super::DataUi;
use crate::ui::item_ui;
use crate::item_ui;

const HIDDEN_COMPONENTS_FOR_ALL_VERBOSITY: &[&str] = &["rerun.instance_key"];
const HIDDEN_COMPONENTS_FOR_LOW_VERBOSITY: &[&str] = &[];
Expand Down
26 changes: 26 additions & 0 deletions crates/re_data_ui/src/item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use re_viewer_context::{Item, UiVerbosity, ViewerContext};

use crate::DataUi;

impl DataUi for Item {
fn data_ui(
&self,
ctx: &mut ViewerContext<'_>,
ui: &mut egui::Ui,
verbosity: UiVerbosity,
query: &re_arrow_store::LatestAtQuery,
) {
match self {
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => {
// Shouldn't be reachable since SelectionPanel::contents doesn't show data ui for these.
// If you add something in here make sure to adjust SelectionPanel::contents accordingly.
}
Item::ComponentPath(component_path) => {
component_path.data_ui(ctx, ui, verbosity, query);
}
Item::InstancePath(_, instance_path) => {
instance_path.data_ui(ctx, ui, verbosity, query);
}
}
}
}
Loading