Skip to content

Commit 8bd03cc

Browse files
committed
Complete overhaul of State structure.
1 parent eb777c7 commit 8bd03cc

File tree

4 files changed

+152
-117
lines changed

4 files changed

+152
-117
lines changed

crates/re_ui/src/list_item2/list_item.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use egui::{NumExt, Response, Shape, Ui};
44

5-
use crate::list_item2::{ContentContext, DesiredWidth, ListItemContent, StateStack};
5+
use crate::list_item2::{ContentContext, DesiredWidth, LayoutInfoStack, ListItemContent};
66
use crate::ReUi;
77

88
struct ListItemResponse {
@@ -238,10 +238,10 @@ impl<'a> ListItem<'a> {
238238

239239
// We use the state set by ListItemContainer to determine how far the background should
240240
// extend.
241-
let state = StateStack::top(ui.ctx());
241+
let layout_info = LayoutInfoStack::top(ui.ctx());
242242
let mut bg_rect = rect;
243-
bg_rect.set_left(state.background_x_range.min);
244-
bg_rect.set_right(state.background_x_range.max);
243+
bg_rect.set_left(layout_info.background_x_range.min);
244+
bg_rect.set_right(layout_info.background_x_range.max);
245245

246246
// We want to be able to select/hover the item across its full span, so we interact over the
247247
// entire background rect. But…
@@ -295,6 +295,7 @@ impl<'a> ListItem<'a> {
295295
bg_rect,
296296
response: &style_response,
297297
list_item: &self,
298+
layout_info,
298299
};
299300
content.ui(re_ui, ui, &content_ctx);
300301

crates/re_ui/src/list_item2/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub struct ContentContext<'a> {
3434

3535
/// The current list item.
3636
pub list_item: &'a ListItem<'a>,
37+
38+
/// Layout information to use for rendering.
39+
pub layout_info: LayoutInfo,
3740
}
3841

3942
#[derive(Debug, Clone, Copy)]

crates/re_ui/src/list_item2/property_content.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ impl ListItemContent for PropertyContent<'_> {
179179
} = *self;
180180

181181
// │ │
182-
// │◀─────────────────────────────background_x_range─────────────────────────────▶│
182+
// │◀─────────────────────layout_info.background_x_range─────────────────────────▶│
183183
// │ │
184-
// │ ◀───────────state.left_column_width────────────▶│┌──COLUMN_SPACING │
184+
// │ ◀────────layout_info.left_column_width─────────▶│┌──COLUMN_SPACING │
185185
// │ ▼ │
186186
// │ ◀─────────────────────────┼────────context.rect──────▶ │
187187
// │ ┌ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ┬ ┬────────┬─┬─────────────┬─┬─────────────┬─┬─────────┐ │
@@ -192,18 +192,17 @@ impl ListItemContent for PropertyContent<'_> {
192192
// │ │ │ │ │││ │ │ │ │
193193
// │ └ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ┴ ┴────────┴─┴─────────────┴─┴─────────────┴─┴─────────┘ │
194194
// │ ▲ ▲ ▲ │ ▲ │
195-
// │ └──state.left_x │ └───────────────────────────────┤ │
195+
// │ └──layout_info.left │ └───────────────────────────────┤ │
196196
// │ │ ▲ │ │
197-
// │ content_left_x──┘ mid_point_x───┘ text_to_icon_padding
197+
// │ content_left_x──┘ mid_point_x───┘ text_to_icon_padding()
198198
// │ │
199199

200-
let state = super::StateStack::top(ui.ctx());
201-
202200
let content_left_x = context.rect.left();
203201
// Total indent left of the content rect. This is part of the left column width.
204-
let content_indent = content_left_x - state.left_x;
205-
let mid_point_x = state.left_x
206-
+ state
202+
let content_indent = content_left_x - context.layout_info.left_x;
203+
let mid_point_x = context.layout_info.left_x
204+
+ context
205+
.layout_info
207206
.left_column_width
208207
.unwrap_or_else(|| content_indent + (context.rect.width() / 2.).at_least(0.0));
209208

@@ -217,7 +216,7 @@ impl ListItemContent for PropertyContent<'_> {
217216
let action_button_dimension =
218217
ReUi::small_icon_size().x + 2.0 * ui.spacing().button_padding.x;
219218
let reserve_action_button_space =
220-
action_buttons.is_some() || state.reserve_action_button_space;
219+
action_buttons.is_some() || context.layout_info.reserve_action_button_space;
221220
let action_button_extra = if reserve_action_button_space {
222221
action_button_dimension + ReUi::text_to_icon_padding()
223222
} else {
@@ -258,10 +257,12 @@ impl ListItemContent for PropertyContent<'_> {
258257
(content_indent + icon_extra + desired_galley.size().x + Self::COLUMN_SPACING / 2.0)
259258
.ceil();
260259

261-
super::StateStack::top_mut(ui.ctx(), |state| {
262-
state.register_desired_left_column_width(desired_width);
263-
state.reserve_action_button_space(action_buttons.is_some());
264-
});
260+
context
261+
.layout_info
262+
.register_desired_left_column_width(ui.ctx(), desired_width);
263+
context
264+
.layout_info
265+
.reserve_action_button_space(ui.ctx(), action_buttons.is_some());
265266

266267
let galley = if desired_galley.size().x <= label_rect.width() {
267268
desired_galley

0 commit comments

Comments
 (0)