Skip to content

Commit

Permalink
Complete overhaul of State structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed May 2, 2024
1 parent eb777c7 commit 8bd03cc
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 117 deletions.
9 changes: 5 additions & 4 deletions crates/re_ui/src/list_item2/list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use egui::{NumExt, Response, Shape, Ui};

use crate::list_item2::{ContentContext, DesiredWidth, ListItemContent, StateStack};
use crate::list_item2::{ContentContext, DesiredWidth, LayoutInfoStack, ListItemContent};
use crate::ReUi;

struct ListItemResponse {
Expand Down Expand Up @@ -238,10 +238,10 @@ impl<'a> ListItem<'a> {

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

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

Expand Down
3 changes: 3 additions & 0 deletions crates/re_ui/src/list_item2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub struct ContentContext<'a> {

/// The current list item.
pub list_item: &'a ListItem<'a>,

/// Layout information to use for rendering.
pub layout_info: LayoutInfo,
}

#[derive(Debug, Clone, Copy)]
Expand Down
29 changes: 15 additions & 14 deletions crates/re_ui/src/list_item2/property_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ impl ListItemContent for PropertyContent<'_> {
} = *self;

// │ │
// │◀─────────────────────────────background_x_range─────────────────────────────▶│
// │◀─────────────────────layout_info.background_x_range─────────────────────────▶│
// │ │
// │ ◀───────────state.left_column_width────────────▶│┌──COLUMN_SPACING │
// │ ◀────────layout_info.left_column_width─────────▶│┌──COLUMN_SPACING │
// │ ▼ │
// │ ◀─────────────────────────┼────────context.rect──────▶ │
// │ ┌ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ┬ ┬────────┬─┬─────────────┬─┬─────────────┬─┬─────────┐ │
Expand All @@ -192,18 +192,17 @@ impl ListItemContent for PropertyContent<'_> {
// │ │ │ │ │││ │ │ │ │
// │ └ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ┴ ┴────────┴─┴─────────────┴─┴─────────────┴─┴─────────┘ │
// │ ▲ ▲ ▲ │ ▲ │
// │ └──state.left_x │ └───────────────────────────────┤ │
// │ └──layout_info.left │ └───────────────────────────────┤ │
// │ │ ▲ │ │
// │ content_left_x──┘ mid_point_x───┘ text_to_icon_padding
// │ content_left_x──┘ mid_point_x───┘ text_to_icon_padding()
// │ │

let state = super::StateStack::top(ui.ctx());

let content_left_x = context.rect.left();
// Total indent left of the content rect. This is part of the left column width.
let content_indent = content_left_x - state.left_x;
let mid_point_x = state.left_x
+ state
let content_indent = content_left_x - context.layout_info.left_x;
let mid_point_x = context.layout_info.left_x
+ context
.layout_info
.left_column_width
.unwrap_or_else(|| content_indent + (context.rect.width() / 2.).at_least(0.0));

Expand All @@ -217,7 +216,7 @@ impl ListItemContent for PropertyContent<'_> {
let action_button_dimension =
ReUi::small_icon_size().x + 2.0 * ui.spacing().button_padding.x;
let reserve_action_button_space =
action_buttons.is_some() || state.reserve_action_button_space;
action_buttons.is_some() || context.layout_info.reserve_action_button_space;
let action_button_extra = if reserve_action_button_space {
action_button_dimension + ReUi::text_to_icon_padding()
} else {
Expand Down Expand Up @@ -258,10 +257,12 @@ impl ListItemContent for PropertyContent<'_> {
(content_indent + icon_extra + desired_galley.size().x + Self::COLUMN_SPACING / 2.0)
.ceil();

super::StateStack::top_mut(ui.ctx(), |state| {
state.register_desired_left_column_width(desired_width);
state.reserve_action_button_space(action_buttons.is_some());
});
context
.layout_info
.register_desired_left_column_width(ui.ctx(), desired_width);
context
.layout_info
.reserve_action_button_space(ui.ctx(), action_buttons.is_some());

let galley = if desired_galley.size().x <= label_rect.width() {
desired_galley
Expand Down
Loading

0 comments on commit 8bd03cc

Please sign in to comment.