mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-14 22:24:37 +00:00
Panels: read the native dock width from its parent-scoped key for egui 0.37
egui 0.37 keeps a panel's size under its parent's scope, reports an immediate viewport's commands from its own pass in that pass's output, and deprecates Id::new for Id::unique (same hash).
This commit is contained in:
1 parent
292f869d8a
commit
1992d65e82
9 files changed
+17
-14
No files matched your search
@@ -827,7 +827,7 @@ fn hue_saturation_bars_fill_the_panel_width() {
|
||||
let mut h = Harness::builder().with_size(vec2(width, 500.0)).build_ui_state(
|
||||
|ui, values: &mut serde_json::Value| {
|
||||
let cx = EditorCx {
|
||||
mem: egui::Id::new("hs"),
|
||||
mem: egui::Id::unique("hs"),
|
||||
hist: None,
|
||||
gray: false,
|
||||
swatches: [[0.0; 3], [1.0; 3]],
|
||||
@@ -838,14 +838,14 @@ fn hue_saturation_bars_fill_the_panel_width() {
|
||||
};
|
||||
let avail = ui.available_width();
|
||||
editor(ui, "hueSaturation", values, &cx);
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::new("hs-avail"), avail));
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::unique("hs-avail"), avail));
|
||||
},
|
||||
json!({}),
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
let bars = h.ctx.data(|d| d.get_temp::<Rect>(egui::Id::new("hs").with("hs-bars"))).expect("bars drawn");
|
||||
let avail = h.ctx.data(|d| d.get_temp::<f32>(egui::Id::new("hs-avail"))).unwrap();
|
||||
let bars = h.ctx.data(|d| d.get_temp::<Rect>(egui::Id::unique("hs").with("hs-bars"))).expect("bars drawn");
|
||||
let avail = h.ctx.data(|d| d.get_temp::<f32>(egui::Id::unique("hs-avail"))).unwrap();
|
||||
assert!((bars.width() - avail).abs() < 0.5, "{width}: bars {} of {avail}", bars.width());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,7 +861,7 @@ pub fn persist(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
fn native_moved(app: &PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
let places: Vec<(u64, [f32; 4])> =
|
||||
app.ui.docking.iter().flat_map(|workspace| workspace.layout.floating.iter().filter_map(|window| Some((window.id, window.native?)))).collect();
|
||||
let id = egui::Id::new("dock-native-places");
|
||||
let id = egui::Id::unique("dock-native-places");
|
||||
ctx.data_mut(|data| {
|
||||
let moved = data.get_temp::<Vec<(u64, [f32; 4])>>(id).is_some_and(|last| last != places);
|
||||
data.insert_temp(id, places);
|
||||
|
||||
@@ -119,7 +119,7 @@ type Drawn = (Vec<(String, Rect)>, Vec<(craft_ui::docking::Hit<String>, Rect)>);
|
||||
|
||||
/// Every panel body and docking control drawn last frame.
|
||||
fn drawn(h: &Harness<'static, PhotocraftApp>) -> Drawn {
|
||||
(crate::panel_docking::last_bodies(&h.ctx), craft_ui::docking::DockArea::<String>::hit_rects(&h.ctx, egui::Id::new("photocraft-panel-docking")))
|
||||
(crate::panel_docking::last_bodies(&h.ctx), craft_ui::docking::DockArea::<String>::hit_rects(&h.ctx, egui::Id::unique("photocraft-panel-docking")))
|
||||
}
|
||||
|
||||
fn drag(h: &mut Harness<'static, PhotocraftApp>, from: Pos2, to: Pos2) {
|
||||
|
||||
@@ -1751,7 +1751,7 @@ mod tests {
|
||||
// One frame of the real shortcut handler, then a focused single-line text edit (the
|
||||
// numeric fields are text edits), as the app orders them.
|
||||
let mut text = String::from("100");
|
||||
let field = egui::Id::new("liquify-size-field");
|
||||
let field = egui::Id::unique("liquify-size-field");
|
||||
let mut frame = |app: &mut PhotocraftApp, events: Vec<egui::Event>| {
|
||||
let raw = egui::RawInput { events, ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
@@ -1793,7 +1793,7 @@ mod tests {
|
||||
|
||||
// With a text edit focused, `[` belongs to the field.
|
||||
let mut text = String::new();
|
||||
let field = egui::Id::new("liquify-size-field");
|
||||
let field = egui::Id::unique("liquify-size-field");
|
||||
let focused_frame = |app: &mut PhotocraftApp, text: &mut String, events: Vec<egui::Event>| {
|
||||
let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {
|
||||
crate::shortcuts::handle(app, ui.ctx());
|
||||
|
||||
@@ -818,7 +818,7 @@ fn set_dock_width(app: &mut PhotocraftApp, width: f32) {
|
||||
/// dock's panel id. The default layout's column takes it once, after the canvas has been laid
|
||||
/// out so the Studio Properties card keeps its place.
|
||||
fn native_dock_width(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
let id = egui::Id::new("dock");
|
||||
let id = crate::panels::panel_state_id(ctx, "dock");
|
||||
let Some(state) = ctx.data_mut(|data| data.get_persisted::<egui::PanelState>(id)) else { return };
|
||||
if app.ui.docking.is_none() && !app.last_canvas_rect.is_positive() {
|
||||
return;
|
||||
|
||||
@@ -69,6 +69,7 @@ impl Host {
|
||||
match command {
|
||||
egui::ViewportCommand::OuterPosition(pos) => window.rect = Rect::from_min_size(*pos, window.rect.size()),
|
||||
egui::ViewportCommand::InnerSize(size) => window.rect = Rect::from_min_size(window.rect.min, *size),
|
||||
egui::ViewportCommand::RequestPaste => window.paste_requested = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +117,8 @@ impl Desktop {
|
||||
input.viewports = infos;
|
||||
input.focused = main_focused;
|
||||
self.h.step();
|
||||
// egui reports the commands of immediate viewports in the main window's output.
|
||||
// A command sent to a window from the main window's pass is in the main pass's output;
|
||||
// one sent from the window's own pass is in that pass's output (`Host::render`).
|
||||
let mut host = self.host.borrow_mut();
|
||||
for (id, output) in &self.h.output().viewport_output {
|
||||
if let Some(window) = host.windows.get_mut(id) {
|
||||
|
||||
@@ -881,10 +881,11 @@ fn main_workspace_file_loads_as_the_default_and_saves_as_a_workspace() {
|
||||
fn the_native_dock_width_sizes_the_default_column() {
|
||||
let mut h = harness(app(), vec2(1280.0, 800.0));
|
||||
let state = egui::PanelState { outer_rect: egui::Rect::from_min_size(egui::pos2(900.0, 0.0), vec2(380.0, 700.0)) };
|
||||
h.ctx.data_mut(|data| data.insert_persisted(egui::Id::new("dock"), state));
|
||||
let key = crate::panels::panel_state_id(&h.ctx, "dock");
|
||||
h.ctx.data_mut(|data| data.insert_persisted(key, state));
|
||||
h.run_steps(2);
|
||||
let Some(Node::Split { second, .. }) = &lay(h.state()).root else { panic!("expected the canvas split") };
|
||||
let Node::Dock { columns, .. } = second.as_ref() else { panic!("expected the dock") };
|
||||
assert_eq!(columns[0].width, 380.0);
|
||||
assert!(h.ctx.data_mut(|data| data.get_persisted::<egui::PanelState>(egui::Id::new("dock"))).is_none(), "taken once");
|
||||
assert!(h.ctx.data_mut(|data| data.get_persisted::<egui::PanelState>(key)).is_none(), "taken once");
|
||||
}
|
||||
@@ -415,7 +415,7 @@ pub fn clipboard_keys(ctx: &egui::Context, typing: bool, raw: &mut egui::RawInpu
|
||||
/// The keys held down in floating panels' own OS windows, from the presses and releases they
|
||||
/// forwarded ([`handle_forwarded`]).
|
||||
fn forwarded_down_id() -> egui::Id {
|
||||
egui::Id::new("pc-forwarded-keys-down")
|
||||
egui::Id::unique("pc-forwarded-keys-down")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -149,7 +149,7 @@ fn native(ctx: &egui::Context) -> bool {
|
||||
/// nothing. Always false where egui embeds viewports, as they share one window's pointer.
|
||||
pub(crate) fn pointer_elsewhere(ctx: &egui::Context, others: &[egui::ViewportId]) -> bool {
|
||||
let own = ctx.viewport_id();
|
||||
let key = egui::Id::new(("pc-pointer-elsewhere", own));
|
||||
let key = egui::Id::unique(("pc-pointer-elsewhere", own));
|
||||
let before = ctx.data(|d| d.get_temp::<bool>(key)).unwrap_or(false);
|
||||
let separate = !ctx.embed_viewports() && others.iter().any(|&v| v != own);
|
||||
if !separate && !before {
|
||||
|
||||
Reference in new issue
Block a user