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

Area::new now takes an Id by argument #4115

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Changes from 1 commit
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
Next Next commit
Area::new now takes an Id by argument
This makes it more explicit that you are responsible for assiging
a globally unique `Id`.
  • Loading branch information
emilk committed Feb 29, 2024
commit 3cb8369b1a97bad949d78cc6b3d838ec527e0456
8 changes: 6 additions & 2 deletions crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
@@ -79,9 +79,10 @@ pub struct Area {
}

impl Area {
pub fn new(id: impl Into<Id>) -> Self {
/// The `id` must be globally unique.
pub fn new(id: Id) -> Self {
Self {
id: id.into(),
id,
movable: true,
interactable: true,
constrain: false,
@@ -96,6 +97,9 @@ impl Area {
}
}

/// Let's you change the `id` that you assigned in [`Self::new`].
///
/// The `id` must be globally unique.
#[inline]
pub fn id(mut self, id: Id) -> Self {
self.id = id;
14 changes: 6 additions & 8 deletions crates/egui_demo_lib/src/demo/pan_zoom.rs
Original file line number Diff line number Diff line change
@@ -69,30 +69,25 @@ impl super::View for PanZoom {
}
}

for (id, pos, callback) in [
for (i, (pos, callback)) in [
(
"a",
egui::Pos2::new(0.0, 0.0),
Box::new(|ui: &mut egui::Ui, _: &mut Self| ui.button("top left!"))
as Box<dyn Fn(&mut egui::Ui, &mut Self) -> egui::Response>,
),
(
"b",
egui::Pos2::new(0.0, 120.0),
Box::new(|ui: &mut egui::Ui, _| ui.button("bottom left?")),
),
(
"c",
egui::Pos2::new(120.0, 120.0),
Box::new(|ui: &mut egui::Ui, _| ui.button("right bottom :D")),
),
(
"d",
egui::Pos2::new(120.0, 0.0),
Box::new(|ui: &mut egui::Ui, _| ui.button("right top ):")),
),
(
"e",
egui::Pos2::new(60.0, 60.0),
Box::new(|ui, state| {
use egui::epaint::*;
@@ -110,8 +105,11 @@ impl super::View for PanZoom {
ui.add(egui::Slider::new(&mut state.drag_value, 0.0..=100.0).text("My value"))
}),
),
] {
let id = egui::Area::new(id)
]
.into_iter()
.enumerate()
{
let id = egui::Area::new(id.with(("subarea", i)))
.default_pos(pos)
// Need to cover up the pan_zoom demo window,
// but may also cover over other windows.
Loading