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

ListItem2.0 (part 1): introduce content-generic ListItem and LabelContent legacy back-port #6161

Merged
merged 9 commits into from
May 2, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/re_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ default = []
[dependencies]
re_entity_db.workspace = true # syntax-highlighting for InstancePath. TODO(emilk): move InstancePath
re_format.workspace = true
re_log.workspace = true
re_log_types.workspace = true # syntax-highlighting for EntityPath

egui_commonmark = { workspace = true, features = ["pulldown_cmark"] }
Expand All @@ -42,9 +43,8 @@ serde_json.workspace = true
strum_macros.workspace = true
strum.workspace = true
sublime_fuzzy.workspace = true
once_cell.workspace = true
abey79 marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
re_log.workspace = true

eframe = { workspace = true, default-features = false, features = ["wgpu"] }
egui_tiles.workspace = true
Expand Down
10 changes: 7 additions & 3 deletions crates/re_ui/examples/re_ui_example/drag_and_drop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::HashSet;

use re_ui::list_item2;

#[derive(Hash, Clone, Copy, PartialEq, Eq)]
struct ItemId(u32);

Expand All @@ -20,6 +22,9 @@ impl Default for ExampleDragAndDrop {
}

impl ExampleDragAndDrop {
/// Draw the drag-and-drop demo.
///
/// Note: this function uses `ListItem` and must be wrapped in a `ListItemContent`.
pub fn ui(&mut self, re_ui: &crate::ReUi, ui: &mut egui::Ui) {
let mut swap: Option<(usize, usize)> = None;

Expand All @@ -29,11 +34,10 @@ impl ExampleDragAndDrop {
//

let label = format!("Item {}", item_id.0);
let response = re_ui
.list_item(label.as_str())
let response = list_item2::ListItem::new(re_ui)
.selected(self.selected_items.contains(item_id))
.draggable(true)
.show_flat(ui);
.show_flat(ui, list_item2::LabelContent::new(&label));

//
// Handle item selection
Expand Down
23 changes: 13 additions & 10 deletions crates/re_ui/examples/re_ui_example/hierarchical_drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};

use egui::NumExt;

use re_ui::ReUi;
use re_ui::{list_item2, ReUi};

#[derive(Hash, Clone, Copy, PartialEq, Eq)]
struct ItemId(u32);
Expand Down Expand Up @@ -276,15 +276,19 @@ impl HierarchicalDragAndDrop {
item_id: ItemId,
children: &Vec<ItemId>,
) {
let response = re_ui
.list_item(format!("Container {item_id:?}"))
.subdued(true)
let response = list_item2::ListItem::new(re_ui)
.selected(self.selected(item_id))
.draggable(true)
.drop_target_style(self.target_container == Some(item_id))
.show_hierarchical_with_content(ui, item_id, true, |re_ui, ui| {
self.container_children_ui(re_ui, ui, children);
});
.show_hierarchical_with_children(
ui,
item_id,
true,
list_item2::LabelContent::new(format!("Container {item_id:?}")).subdued(true),
|re_ui, ui| {
self.container_children_ui(re_ui, ui, children);
},
);

self.handle_interaction(
ui,
Expand Down Expand Up @@ -315,11 +319,10 @@ impl HierarchicalDragAndDrop {
}

fn leaf_ui(&self, re_ui: &crate::ReUi, ui: &mut egui::Ui, item_id: ItemId, label: &str) {
let response = re_ui
.list_item(label)
let response = list_item2::ListItem::new(re_ui)
.selected(self.selected(item_id))
.draggable(true)
.show_hierarchical(ui);
.show_hierarchical(ui, list_item2::LabelContent::new(label));

self.handle_interaction(ui, item_id, false, &response, None);
}
Expand Down
49 changes: 13 additions & 36 deletions crates/re_ui/examples/re_ui_example/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,19 @@ impl eframe::App for ExampleApp {
egui::SidePanel::right("right_panel")
.frame(panel_frame)
.show_animated(egui_ctx, self.show_right_panel, |ui| {
self.right_panel.ui(&self.re_ui, ui);
// TODO(#6156): this is still needed for some full-span widgets
ui.set_clip_rect(ui.max_rect());

// define the hover/selection background highlight range for all nested `ListItem`s
re_ui::list_item2::list_item_scope(
ui,
"right_panel_list_item_scope",
Some(ui.max_rect().x_range()),
|ui| {
ui.spacing_mut().item_spacing.y = 0.0;
self.right_panel.ui(&self.re_ui, ui);
},
);
});

egui::CentralPanel::default()
Expand Down Expand Up @@ -430,41 +442,6 @@ fn file_menu(ui: &mut egui::Ui, command_sender: &CommandSender) {
UICommand::Quit.menu_button_ui(ui, command_sender);
}

fn selection_buttons(ui: &mut egui::Ui) {
use egui_extras::{Size, StripBuilder};

const BUTTON_SIZE: f32 = 20.0;
const MIN_COMBOBOX_SIZE: f32 = 100.0;

ui.horizontal(|ui| {
StripBuilder::new(ui)
.cell_layout(egui::Layout::centered_and_justified(
egui::Direction::TopDown, // whatever
))
.size(Size::exact(BUTTON_SIZE)) // prev
.size(Size::remainder().at_least(MIN_COMBOBOX_SIZE)) // browser
.size(Size::exact(BUTTON_SIZE)) // next
.horizontal(|mut strip| {
strip.cell(|ui| {
let _ = ui.small_button("⏴");
});

strip.cell(|ui| {
egui::ComboBox::from_id_source("foo")
.width(ui.available_width())
.selected_text("ComboBox")
.show_ui(ui, |ui| {
ui.label("contents");
});
});

strip.cell(|ui| {
let _ = ui.small_button("⏵");
});
});
});
}

fn tabs_ui(ui: &mut egui::Ui, tree: &mut egui_tiles::Tree<Tab>) {
tree.ui(&mut MyTileTreeBehavior {}, ui);
}
Expand Down
Loading
Loading