Skip to content

Commit

Permalink
Introduce snapshot unit tests for re_component_ui (#8546)
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Reich <[email protected]>
  • Loading branch information
abey79 and Wumpf authored Dec 20, 2024
1 parent 774ad70 commit 3532706
Show file tree
Hide file tree
Showing 203 changed files with 999 additions and 30 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5704,7 +5704,10 @@ dependencies = [
"arrow",
"egui",
"egui_extras",
"egui_kittest",
"egui_plot",
"itertools 0.13.0",
"nohash-hasher",
"re_data_source",
"re_data_ui",
"re_format",
Expand Down
2 changes: 1 addition & 1 deletion crates/store/re_types/src/components/image_format_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ImageFormat {
datatypes::ImageFormat::rgba8([width, height]).into()
}

/// From a speicifc pixel format.
/// From a specific pixel format.
#[inline]
pub fn from_pixel_format([width, height]: [u32; 2], pixel_format: PixelFormat) -> Self {
datatypes::ImageFormat::from_pixel_format([width, height], pixel_format).into()
Expand Down
6 changes: 6 additions & 0 deletions crates/viewer/re_component_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ arrow.workspace = true
egui_extras.workspace = true
egui_plot.workspace = true
egui.workspace = true


[dev-dependencies]
egui_kittest.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
8 changes: 4 additions & 4 deletions crates/viewer/re_component_ui/src/datatype_uis/float_drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::RangeInclusive;

use egui::NumExt as _;
use re_types::datatypes;
use re_viewer_context::MaybeMutRef;
use re_viewer_context::{MaybeMutRef, UiLayout};

/// Generic editor for a [`re_types::datatypes::Float32`] value from zero to max float.
pub fn edit_f32_zero_to_max(
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn edit_f32_float_raw_with_speed_impl(
.suffix(suffix),
)
} else {
ui.label(format!("{}{}", re_format::format_f32(**value), suffix))
UiLayout::List.data_label(ui, format!("{}{}", re_format::format_f32(**value), suffix))
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ fn edit_f32_zero_to_one_raw(ui: &mut egui::Ui, value: &mut MaybeMutRef<'_, f32>)
.fixed_decimals(2),
)
} else {
ui.label(re_format::format_f32(**value))
UiLayout::List.data_label(ui, re_format::format_f32(**value))
}
}

Expand Down Expand Up @@ -162,6 +162,6 @@ pub fn edit_f64_float_raw_with_speed_impl(
.speed(speed),
)
} else {
ui.label(re_format::format_f64(**value))
UiLayout::List.data_label(ui, re_format::format_f64(**value))
}
}
4 changes: 2 additions & 2 deletions crates/viewer/re_component_ui/src/datatype_uis/int_drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::RangeInclusive;

use egui::NumExt as _;
use re_types_core::datatypes;
use re_viewer_context::MaybeMutRef;
use re_viewer_context::{MaybeMutRef, UiLayout};

/// Generic editor for a [`re_types::datatypes::UInt64`] values within a given range.
pub fn edit_u64_range(
Expand Down Expand Up @@ -46,6 +46,6 @@ pub fn edit_u64_raw_with_speed_impl(
.suffix(suffix),
)
} else {
ui.label(format!("{}{}", re_format::format_uint(**value), suffix))
UiLayout::List.data_label(ui, format!("{}{}", re_format::format_uint(**value), suffix))
}
}
15 changes: 9 additions & 6 deletions crates/viewer/re_component_ui/src/datatype_uis/range1d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::NumExt as _;

use re_types::datatypes::Range1D;
use re_viewer_context::MaybeMutRef;
use re_viewer_context::{MaybeMutRef, UiLayout};

pub fn edit_view_range1d(
_ctx: &re_viewer_context::ViewerContext<'_>,
Expand Down Expand Up @@ -41,10 +41,13 @@ fn edit_view_range1d_impl(
response_min | response_max
} else {
let [min, max] = value.0;
ui.label(format!(
"{} - {}",
re_format::format_f64(min),
re_format::format_f64(max)
))
UiLayout::List.data_label(
ui,
format!(
"{} - {}",
re_format::format_f64(min),
re_format::format_f64(max)
),
)
}
}
30 changes: 18 additions & 12 deletions crates/viewer/re_component_ui/src/datatype_uis/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::RangeInclusive;

use egui::NumExt as _;
use re_types::datatypes;
use re_viewer_context::MaybeMutRef;
use re_viewer_context::{MaybeMutRef, UiLayout};

pub fn edit_or_view_vec2d(
_ctx: &re_viewer_context::ViewerContext<'_>,
Expand Down Expand Up @@ -60,11 +60,14 @@ pub fn edit_or_view_vec2d_raw(

response
} else {
ui.label(format!(
"[ {} , {} ]",
re_format::format_f32(x),
re_format::format_f32(y),
))
UiLayout::List.data_label(
ui,
format!(
"[{}, {}]",
re_format::format_f32(x),
re_format::format_f32(y),
),
)
}
}

Expand Down Expand Up @@ -94,11 +97,14 @@ pub fn edit_or_view_vec3d_raw(

response
} else {
ui.label(format!(
"[ {} , {} , {} ]",
re_format::format_f32(x),
re_format::format_f32(y),
re_format::format_f32(z),
))
UiLayout::List.data_label(
ui,
format!(
"[{}, {}, {}]",
re_format::format_f32(x),
re_format::format_f32(y),
re_format::format_f32(z),
),
)
}
}
4 changes: 2 additions & 2 deletions crates/viewer/re_component_ui/src/datatype_uis/view_uuid.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use re_types::datatypes::Uuid;
use re_viewer_context::MaybeMutRef;
use re_viewer_context::{MaybeMutRef, UiLayout};

pub fn view_uuid(
_ctx: &re_viewer_context::ViewerContext<'_>,
ui: &mut egui::Ui,
value: &mut MaybeMutRef<'_, impl std::ops::DerefMut<Target = Uuid>>,
) -> egui::Response {
ui.label(value.as_ref().to_string())
UiLayout::List.data_label(ui, value.as_ref().to_string())
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3532706

Please sign in to comment.