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

Replace MarkerShape with code-generated enum type #5336

Merged
merged 29 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cc732bf
Rust enums codegen: Add `ALL` and `Display` implementation
emilk Feb 28, 2024
a884cb3
Rename enum_test file
emilk Feb 28, 2024
0a89672
Improve some codegen error messages
emilk Feb 28, 2024
3b3bc18
Add `default` attribute for enums
emilk Feb 28, 2024
677d0d0
Allow having enums as components
emilk Feb 28, 2024
54f1fac
Make EnumTest a component instead of a datatype
emilk Feb 28, 2024
bc8b333
Add `enum_type` attribute to work around flatbuffers limitation
emilk Feb 28, 2024
5c11970
Fix crash in sparse union size estimator
emilk Feb 28, 2024
ab49761
Replace `components.MarkerShape` with an `enum`
emilk Feb 28, 2024
592aa24
List enum variants in generated docs
emilk Feb 28, 2024
8dbe173
Fix: list all struct and union fields in generated documentation
emilk Feb 28, 2024
b57c178
Codegen: use `Field::new`
emilk Feb 28, 2024
4eb8760
Mark `MarkerShape` as unreleased so as to produce a speculative link
emilk Feb 28, 2024
9e1198c
Use PascalCase for enum variants in Python
emilk Feb 28, 2024
4c139b0
Fix warning about unused import
emilk Feb 28, 2024
315ccce
Replace ContainerKind with codegenerated enum
emilk Feb 28, 2024
b4d68b1
Replace `Corner2D` with enum
emilk Feb 28, 2024
287622b
Fix Python serialization problem
emilk Feb 28, 2024
764719c
Handle building empty sparse union in Python
emilk Feb 28, 2024
4aee9e4
vscode: add shortcut for launching a Python debugger of the current file
emilk Feb 28, 2024
db2360d
Case-insenitive string->enum conversion in Python
emilk Feb 28, 2024
08b6ad2
mypy: Allow strings for enums
emilk Feb 28, 2024
d991f84
Fix duplicated word
emilk Feb 28, 2024
b23fb9d
Cleanup
emilk Feb 28, 2024
895ef98
typo
emilk Feb 29, 2024
d08d3f3
Clean up `is_tuple_struct_from_obj` function
emilk Feb 29, 2024
a3042a9
enum_type -> is_enum
emilk Feb 29, 2024
dde7fa2
Remove enum attribute hack
emilk Feb 29, 2024
5819de7
Enforce that all enums are declared using the `byte` type
emilk Feb 29, 2024
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
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// Python
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
// Rust:
{
"name": "Lauch C++ minimal example",
"type": "cppdbg",
Expand Down
6 changes: 3 additions & 3 deletions crates/re_data_ui/src/editors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn edit_marker_shape_ui(

let mut edit_marker = current_marker;

let marker_text = edit_marker.as_str();
let marker_text = edit_marker.to_string();

egui::ComboBox::from_id_source("marker_shape")
.selected_text(marker_text) // TODO(emilk): Show marker shape in the selected text
Expand All @@ -270,8 +270,8 @@ fn edit_marker_shape_ui(
.with_max_x(ui.max_rect().max.x + ui.spacing().menu_margin.right),
);

for marker in MarkerShape::all_markers() {
let list_item = re_ui::list_item::ListItem::new(ctx.re_ui, marker.as_str())
for marker in MarkerShape::ALL {
let list_item = re_ui::list_item::ListItem::new(ctx.re_ui, marker.to_string())
.with_icon_fn(|_re_ui, ui, rect, visuals| {
paint_marker(ui, marker.into(), rect, visuals.text_color());
})
Expand Down

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

7 changes: 7 additions & 0 deletions crates/re_types/definitions/fbs/attributes.fbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
namespace fbs.attributes;

/// The default variant of an `enum`.
attribute "default";

/// This attribute is mandatory for all struct fields that have an `enum` type.
/// This is because flatbuffers report enums as integers.
attribute "enum_type";
emilk marked this conversation as resolved.
Show resolved Hide resolved

/// Mandatory attribute that applies to all kinds of objects: structs, enums, unions and even the
/// fields within.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ table SeriesPoint {
color: rerun.components.Color ("attr.rerun.component_optional", nullable, order: 1000);

/// What shape to use to represent the point
marker: rerun.components.MarkerShape ("attr.rerun.component_optional", nullable, order: 2000);
marker: rerun.components.MarkerShape (
enum_type: "rerun.components.MarkerShape",
"attr.rerun.component_optional",
nullable,
order: 2000
);

/// Display name of the series.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ namespace rerun.blueprint.archetypes;
/// The top-level description of the Viewport.
table ContainerBlueprint (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code had a bug, which defaulted the container_kind to the invalid value 0

"attr.rust.override_crate": "re_viewport"
) {
// --- Required ---

/// The class of the view.
container_kind: rerun.blueprint.components.ContainerKind ("attr.rerun.component_required", order: 100);
container_kind: rerun.blueprint.components.ContainerKind (
enum_type: "rerun.blueprint.components.ContainerKind",
"attr.rerun.component_required",
order: 100
);

// --- Optional ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ table PlotLegend (
/// To what corner the legend is aligned.
///
/// Defaults to the right bottom corner.
corner: rerun.blueprint.components.Corner2D ("attr.rerun.component_optional", nullable, order: 2100);
corner: rerun.blueprint.components.Corner2D (
enum_type: "rerun.blueprint.components.Corner2D",
"attr.rerun.component_optional",
nullable,
order: 2100
);

/// Whether the legend is shown at all.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,14 @@ include "rerun/attributes.fbs";
namespace rerun.blueprint.components;


// TODO(#3384)
/*
enum ContainerKind: byte {
Tabs = 1
Horizontal = 2,
Vertical = 3,
Grid = 4
}
*/

// ---

/// The kind of a blueprint container.
table ContainerKind (
/// The kind of a blueprint container (tabs, grid, …).
enum ContainerKind: byte (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord",
"attr.rust.override_crate": "re_viewport"
"attr.rust.override_crate": "re_viewport",
"attr.docs.unreleased"
) {
/// Which kind of container this is.
///
/// Allowed values:
/// - Tabs = 1
/// - Horizontal = 2
/// - Vertical = 3
/// - Grid = 4
kind: ubyte (order: 100);
Tabs,
Horizontal,
Vertical,
Grid,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,13 @@ include "rust/attributes.fbs";

namespace rerun.blueprint.components;

// TODO(#3384)
/*
enum LegendPosition: byte {
LeftTop = 1,
RightTop = 2,
LeftBottom = 3,
RightBottom = 4
}
*/

/// One of four 2D corners, typically used to align objects.
table Corner2D (
"attr.arrow.transparent",
enum Corner2D: byte (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Copy, PartialEq, Eq, PartialOrd, Ord",
"attr.rust.tuple_struct"
"attr.rust.derive": "Copy, PartialEq, Eq"
) {
/// Where should the legend be located.
///
/// Allowed values:
/// - LeftTop = 1,
/// - RightTop = 2,
/// - LeftBottom = 3,
/// - RightBottom = 4
location: ubyte (order: 200);
LeftTop,
RightTop,
LeftBottom,
RightBottom (default),
}
2 changes: 2 additions & 0 deletions crates/re_types/definitions/rerun/components.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ include "./components/vector2d.fbs";
include "./components/vector3d.fbs";
include "./components/view_coordinates.fbs";
include "./components/visualizer_overrides.fbs";

include "./testing/components/enum_test.fbs";
34 changes: 12 additions & 22 deletions crates/re_types/definitions/rerun/components/marker_shape.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,18 @@ include "rerun/attributes.fbs";

namespace rerun.components;

// TODO(#3384)
/*
enum MarkerShape: byte {
Circle = 1,
Diamond = 2,
Square = 3,
Cross = 4,
Plus = 5,
Up = 6,
Down = 7,
Left = 8,
Right = 9,
Asterisk = 10,
}
*/

/// Shape of a marker.
struct MarkerShape (
"attr.python.aliases": "int, str",
"attr.python.array_aliases": "int, str",
"attr.rust.derive": "PartialEq, Eq, PartialOrd, Copy",
"attr.rust.repr": "transparent"
enum MarkerShape: byte (
"attr.docs.unreleased"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why unreleased?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

) {
shape: ubyte (order: 100);
Circle (default),
Diamond,
Square,
Cross,
Plus,
Up,
Down,
Left,
Right,
Asterisk,
}
2 changes: 0 additions & 2 deletions crates/re_types/definitions/rerun/datatypes.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ include "./datatypes/vec2d.fbs";
include "./datatypes/vec3d.fbs";
include "./datatypes/vec4d.fbs";

include "./testing/datatypes/enum.fbs";

namespace rerun.datatypes;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace rerun.testing.datatypes;
namespace rerun.testing.components;

/// A test of the enum type.
enum EnumTest: byte {
Expand All @@ -9,7 +9,7 @@ enum EnumTest: byte {
Down,

/// Correct.
Right,
Right (default),

/// It's what's remaining.
Left,
Expand Down
11 changes: 5 additions & 6 deletions crates/re_types/src/blueprint/components/column_shares.rs

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

Loading
Loading