ui-egui: replacement egui and atomic names; window input methods in their own function

Ui::scope_id and Id::unique are the renamed Ui::id and Id::new (same hash, so
ids are unchanged); AtomicU64::try_update is the renamed fetch_update.
control::handle answers the input, screenshot and window methods through
window_input, bringing it under the complexity limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 02:22:19 +00:00
co-authored by Claude Opus 5.5
parent 72db063166
commit 30735ede88
5 changed files with 80 additions and 71 deletions
+2 -2
View File
@@ -56,12 +56,12 @@ pub(crate) fn show(app: &mut SlideApp, ui: &mut egui::Ui, space: &CanvasSpace) {
continue;
}
let Some((_, control)) = selection_box(st, sh) else { continue };
control.id(ui.id().with(("selection", *id))).show_at(ui, space.view.rect);
control.id(ui.scope_id().with(("selection", *id))).show_at(ui, space.view.rect);
if !sh.locked {
let geometry = deckcraft_render::shape_geometry(sh, x.w, x.h);
let mut points: Vec<Point> = geometry.handles.iter().map(|h| a * h.pos).collect();
points.extend(deckcraft_engine::tools::wordart_handles(&st.doc, &st.selection, sh, x.w, x.h).into_iter().map(|h| a * h.pos));
AdjustHandles::new("Adjustment points", &points).id(ui.id().with(("adjustment_points", *id))).show_at(ui, space.view.rect);
AdjustHandles::new("Adjustment points", &points).id(ui.scope_id().with(("adjustment_points", *id))).show_at(ui, space.view.rect);
}
}
space.paint_overlay(ui, |draw, _| {
+1 -1
View File
@@ -384,7 +384,7 @@ fn document_bounds(points: [deckcraft_geom::Point; 4], transform: Affine) -> Rec
/// The editor takes keyboard focus in the first pass it is shown, and again after a pass without it, including
/// frames in which the canvas was not laid out at all (the File view replaces it).
pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &CanvasSpace) -> Option<TextEditorOutput> {
let shown = egui::Id::new("slide-text-editor-shown");
let shown = egui::Id::unique("slide-text-editor-shown");
let frame = ui.ctx().cumulative_frame_nr();
let hosted = ui.data(|data| data.get_temp::<(egui::Id, u64)>(shown)).filter(|(_, at)| at + 1 >= frame).map(|(id, _)| id);
let blocked = crate::dialogs::modal_open(ui.ctx()) || app.palette_open || app.backstage_open() || app.opening.is_some();
+73 -64
View File
@@ -91,70 +91,8 @@ pub fn handle(app: &mut SlideApp, ctx: &egui::Context, req: &ControlRequest) ->
if let Some(result) = crate::dialogs::control(app, ctx, method, &req.params) {
return wrap(result);
}
if matches!(
method,
"ui.click"
| "ui.move"
| "ui.drag"
| "ui.release"
| "ui.key"
| "ui.type"
| "ui.ime"
| "ui.wheel"
| "ui.focus"
| "ui.drop"
| "ui.capsLock"
| "ui.find"
| "ui.screenshot"
| "ui.window"
) {
let (viewport, mut params) = match window_target(app, ctx, &req.params) {
Ok(target) => target,
Err(error) => return err(error),
};
// `active` is the protocol's older name for the preedit's converted segment.
if method == "ui.ime"
&& let Some(active) = params.as_object_mut().and_then(|fields| fields.remove("active"))
{
params["cursor"] = active;
}
if method == "ui.screenshot" {
let params = match ScreenshotParams::from_params(&params) {
Ok(params) => params,
Err(error) => return err(error),
};
let token = match CAPTURE_SERIAL.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |n| n.checked_add(1)) {
Ok(token) => token,
Err(_) => return err("screenshot token space exhausted"),
};
return Reply::screenshot(token, params, viewport);
}
let map = |page: usize, point: egui::Pos2| {
if viewport != egui::ViewportId::ROOT || app.show.is_some() || app.backstage.is_some() {
return None;
}
let document = app.session.active()?;
if document.selection.slide != page || app.canvas_rect().is_none() {
return None;
}
Some(app.canvas_view.to_screen(craft::behavior::kurbo::Point::new(f64::from(point.x), f64::from(point.y))))
};
if let Some(result) = craft::automation::synthetic::input_method(method, &params, &host, viewport, &map) {
return match result {
Ok(()) => {
app.note_injected(ctx);
Reply::AfterInput
}
Err(error) => err(error),
};
}
if let Some(result) = craft::automation::access::access_method(method, &params, &host, viewport) {
return wrap(result);
}
#[cfg(not(target_arch = "wasm32"))]
if let Some(result) = craft::automation::window::window_method(&host, viewport, method, &params) {
return wrap(result);
}
if let Some(reply) = window_input(app, ctx, &host, method, &req.params) {
return reply;
}
let p = &req.params;
let s = |k: &str| p.get(k).and_then(Value::as_str);
@@ -376,6 +314,77 @@ pub fn handle(app: &mut SlideApp, ctx: &egui::Context, req: &ControlRequest) ->
}
}
/// The input, accessibility, screenshot and window methods, answered for the window the request names.
/// `None` when `method` is not one of them, or no handler answered it.
fn window_input(app: &mut SlideApp, ctx: &egui::Context, host: &WindowHost, method: &str, request: &Value) -> Option<Reply> {
if !matches!(
method,
"ui.click"
| "ui.move"
| "ui.drag"
| "ui.release"
| "ui.key"
| "ui.type"
| "ui.ime"
| "ui.wheel"
| "ui.focus"
| "ui.drop"
| "ui.capsLock"
| "ui.find"
| "ui.screenshot"
| "ui.window"
) {
return None;
}
let (viewport, mut params) = match window_target(app, ctx, request) {
Ok(target) => target,
Err(error) => return Some(err(error)),
};
// `active` is the protocol's older name for the preedit's converted segment.
if method == "ui.ime"
&& let Some(active) = params.as_object_mut().and_then(|fields| fields.remove("active"))
{
params["cursor"] = active;
}
if method == "ui.screenshot" {
let params = match ScreenshotParams::from_params(&params) {
Ok(params) => params,
Err(error) => return Some(err(error)),
};
let Ok(token) = CAPTURE_SERIAL.try_update(Ordering::Relaxed, Ordering::Relaxed, |n| n.checked_add(1)) else {
return Some(err("screenshot token space exhausted"));
};
return Some(Reply::screenshot(token, params, viewport));
}
let map = |page: usize, point: egui::Pos2| {
if viewport != egui::ViewportId::ROOT || app.show.is_some() || app.backstage.is_some() {
return None;
}
let document = app.session.active()?;
if document.selection.slide != page || app.canvas_rect().is_none() {
return None;
}
Some(app.canvas_view.to_screen(craft::behavior::kurbo::Point::new(f64::from(point.x), f64::from(point.y))))
};
if let Some(result) = craft::automation::synthetic::input_method(method, &params, host, viewport, &map) {
return Some(match result {
Ok(()) => {
app.note_injected(ctx);
Reply::AfterInput
}
Err(error) => err(error),
});
}
if let Some(result) = craft::automation::access::access_method(method, &params, host, viewport) {
return Some(wrap(result));
}
#[cfg(not(target_arch = "wasm32"))]
if let Some(result) = craft::automation::window::window_method(host, viewport, method, &params) {
return Some(wrap(result));
}
None
}
fn mods_from(p: &Value) -> Mods {
let b = |n: &str| p.get(n).and_then(Value::as_bool).unwrap_or(false);
Mods { shift: b("shift"), alt: b("alt"), cmd: b("cmd") || b("ctrl") }
+1 -1
View File
@@ -89,7 +89,7 @@ fn run(app: &mut SlideApp, id: &str, p: serde_json::Value) {
/// The selection list identity for a document.
pub fn list_id(uid: u64) -> egui::Id {
egui::Id::new(("selection_pane", uid))
egui::Id::unique(("selection_pane", uid))
}
const EYE: ColumnKey = ColumnKey::new("eye");
+3 -3
View File
@@ -27,7 +27,7 @@ fn harness(with_sections: bool) -> Harness<'static, Framed> {
|app, ui| {
let rerun = ui.input(|input| !input.events.is_empty());
app.logic(ui.ctx());
let _ = inspect::record(ui, egui::Id::new("sorter-trial"), |ui| app.ui(ui));
let _ = inspect::record(ui, egui::Id::unique("sorter-trial"), |ui| app.ui(ui));
// egui supplies events to the first pass only; rerunning that frame must not repeat them.
if rerun {
craft::ui::runtime::frame::discard_pass(ui.ctx(), "exercise the input frame's second pass");
@@ -75,7 +75,7 @@ pub(crate) fn drag(h: &mut Harness<'_, Framed>, from: Pos2, to: Pos2) {
}
fn fold(h: &mut Harness<'_, Framed>, group: usize) {
let record = inspect::recorded(&h.ctx, egui::Id::new("sorter-trial")).unwrap();
let record = inspect::recorded(&h.ctx, egui::Id::unique("sorter-trial")).unwrap();
let disclosure = record.hits.iter().find(|hit| hit.part == Some(PartKey::new("group_toggle").at(group as u64))).unwrap().rect.center();
h.hover_at(disclosure);
h.run_steps(1);
@@ -88,7 +88,7 @@ fn fold(h: &mut Harness<'_, Framed>, group: usize) {
fn header_rect(h: &Harness<'_, Framed>, index: usize) -> egui::Rect {
let names = section_names(h);
let record = inspect::recorded(&h.ctx, egui::Id::new("sorter-trial")).unwrap();
let record = inspect::recorded(&h.ctx, egui::Id::unique("sorter-trial")).unwrap();
let label = record
.elements
.iter()