-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ListItem
2.0 (part 6): split full-span range management to a dedica…
…ted module (#6211) ### What So far, the full span x coordinate rang needed for highlighting was maintained by `LayoutInfo` and `list_item_scope`. However, other widgets also need this mechanism. This PR splits of full-span management to a dedicated module, and deploys it both in `re_ui_example` and where `list_item2` is currently used. Other changes: - This PR also improves the sanity checks regarding both `list_item_scope` and `full_span_scope`. When missing, debug build will panic and release build will emit warnings. - Both scopes are now `ui.scope()`, so it's safe to modify `ui.style()` from the closure. - `list_item_scope` now sets `ui.spacing().item_spacing.y = 0`, since this is required anyway for `ListItem`s to look good. Follow-up PR will be needed to deploy `full_span` to all relevant widgets and their use in the viewer (#6156). - Part of #6075 - Part of #6156 - Follow-up to #6184 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6211?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6211?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! - [PR Build Summary](https://build.rerun.io/pr/6211) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
- Loading branch information
Showing
10 changed files
with
210 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Support for full-span widgets. | ||
//! | ||
//! Full-span widgets are widgets which draw beyond the boundaries of `ui.max_rect()`, e.g. to | ||
//! provide highlighting without margin, like [`crate::list_item2`]. Typically, in the context of a | ||
//! side panel, the full span is the entire width of the panel, excluding any margin. | ||
//! | ||
//! This module maintains a stack of full span values (effectively[`egui::Rangef`]) using nestable | ||
//! scopes (via [`full_span_scope`]) and makes them available to widgets (via [`get_full_span`]). | ||
#[derive(Clone, Default)] | ||
struct FullSpanStack(Vec<egui::Rangef>); | ||
|
||
/// Set up a full-span scope. | ||
/// | ||
/// Note: | ||
/// - Uses [`egui::Ui::scope`] internally, so it's safe to modify `ui` in the closure. | ||
/// - Can be nested since the full-span range is stored in a stack. | ||
pub fn full_span_scope<R>( | ||
ui: &mut egui::Ui, | ||
background_x_range: egui::Rangef, | ||
content: impl FnOnce(&mut egui::Ui) -> R, | ||
) -> R { | ||
// push | ||
ui.ctx().data_mut(|writer| { | ||
let stack: &mut FullSpanStack = writer.get_temp_mut_or_default(egui::Id::NULL); | ||
stack.0.push(background_x_range); | ||
}); | ||
|
||
// | ||
let result = ui.scope(content).inner; | ||
|
||
// pop | ||
ui.ctx().data_mut(|writer| { | ||
let stack: &mut FullSpanStack = writer.get_temp_mut_or_default(egui::Id::NULL); | ||
stack.0.pop(); | ||
}); | ||
|
||
result | ||
} | ||
|
||
/// Retrieve the current full-span scope. | ||
/// | ||
/// If called outside a [`full_span_scope`], this function emits a warning and returns the clip | ||
/// rectangle width. In debug build, it panics. | ||
pub fn get_full_span(ui: &egui::Ui) -> egui::Rangef { | ||
let range = ui.ctx().data_mut(|writer| { | ||
let stack: &mut FullSpanStack = writer.get_temp_mut_or_default(egui::Id::NULL); | ||
stack.0.last().copied() | ||
}); | ||
|
||
if range.is_none() { | ||
re_log::warn_once!("Full span requested outside a `full_span_scope()`"); | ||
} | ||
debug_assert!( | ||
range.is_some(), | ||
"Full span requested outside a `full_span_scope()`" | ||
); | ||
|
||
range.unwrap_or(ui.clip_rect().x_range()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.