From fb3e4b390201e79773e3a691e8a57a8c7dec2366 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sat, 7 Nov 2026 23:51:57 -0500 Subject: [PATCH 01/10] Allow moving the activity stack window --- crates/ui-egui/src/panels/activity.rs | 53 +++++++++++++++------------ crates/ui-egui/src/tests/activity.rs | 22 +++++++++++ 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index dffdd1c4d3..cea1ee58e4 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -73,34 +73,39 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { let mut cancel = None; let mut toggle = false; let frame = egui::Frame::NONE.fill(t.chrome).stroke(Stroke::new(1.0, t.field_border)).corner_radius(6).inner_margin(Margin::same(MARGIN)); - egui::Area::new(egui::Id::unique("activity-stack")).order(egui::Order::Middle).fixed_pos(pos2(8.0, t.top_bar_h + 8.0)).show(ctx, |ui| { - // An area lays out in the size it had last frame, and the scroll area would take that as all the room there - // is: the stack would never grow when rows are added. Give it the whole height below the top bar instead - // (the scroll area keeps to `max_height`). - ui.set_max_height((ctx.content_rect().height() - t.top_bar_h - 16.0).max(80.0)); - frame.show(ui, |ui| { - let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); - ui.set_width(inner); - ui.spacing_mut().item_spacing.y = 3.0; - egui::ScrollArea::vertical().max_height(max_height).auto_shrink([false, true]).show(ui, |ui| { - for (i, task) in tasks.iter().take(shown).enumerate() { - if i > 0 { - ui.add_space(6.0); - } - if row(ui, &t, task, inner) { - cancel = Some(task.id); + egui::Area::new(egui::Id::unique("activity-stack")) + .order(egui::Order::Middle) + .default_pos(pos2(8.0, t.top_bar_h + 8.0)) + .movable(true) + .constrain(true) + .show(ctx, |ui| { + // An area lays out in the size it had last frame, and the scroll area would take that as all the room there + // is: the stack would never grow when rows are added. Give it the whole height below the top bar instead + // (the scroll area keeps to `max_height`). + ui.set_max_height((ctx.content_rect().height() - t.top_bar_h - 16.0).max(80.0)); + frame.show(ui, |ui| { + let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); + ui.set_width(inner); + ui.spacing_mut().item_spacing.y = 3.0; + egui::ScrollArea::vertical().max_height(max_height).auto_shrink([false, true]).show(ui, |ui| { + for (i, task) in tasks.iter().take(shown).enumerate() { + if i > 0 { + ui.add_space(6.0); + } + if row(ui, &t, task, inner) { + cancel = Some(task.id); + } } + }); + if hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS) { + ui.add_space(4.0); + let text = if hidden > 0 { tr_format!("+{n} more", n = hidden) } else { tr("Show less").to_string() }; + let r = ui.add(egui::Label::new(RichText::new(text).font(t.font(11.0)).color(t.accent)).sense(Sense::click())); + register(ui, "activity:more", r.rect); + toggle = r.clicked(); } }); - if hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS) { - ui.add_space(4.0); - let text = if hidden > 0 { tr_format!("+{n} more", n = hidden) } else { tr("Show less").to_string() }; - let r = ui.add(egui::Label::new(RichText::new(text).font(t.font(11.0)).color(t.accent)).sense(Sense::click())); - register(ui, "activity:more", r.rect); - toggle = r.clicked(); - } }); - }); if let Some(id) = cancel { self::cancel(app, id); } diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index b353405ffc..aa97141612 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -573,6 +573,28 @@ fn rows_added_later_grow_the_stack() { } } +#[test] +fn activity_stack_area_is_movable() { + let mut h = demo(); + let _g = h.app.session.activity.start("export", "Exporting", Cancel::Yes); + wait_visible(&mut h); + let id = egui::Id::unique("activity-stack"); + let initial_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!(initial_rect.min.x >= 7.0 && initial_rect.min.x <= 9.0, "default pos at x=8: {initial_rect:?}"); + + // Drag the activity stack using ui.drag + let start_x = initial_rect.center().x; + let start_y = initial_rect.center().y; + let dx = 100.0; + let dy = 60.0; + let r = h.request("ui.drag", json!({"x": start_x, "y": start_y, "toX": start_x + dx, "toY": start_y + dy, "steps": 6}), T); + assert_eq!(r["ok"], true, "{r:?}"); + h.step(); + let updated_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!((updated_rect.min.x - (initial_rect.min.x + dx)).abs() < 5.0, "stack moved in x: {updated_rect:?}"); + assert!((updated_rect.min.y - (initial_rect.min.y + dy)).abs() < 5.0, "stack moved in y: {updated_rect:?}"); +} + #[test] fn immediate_library_commands_and_auto_sync_show_completion() { let mut h = demo(); From 72b43e3e8c533dd22a0b2efc26005bebf9ec2f25 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 00:26:35 -0500 Subject: [PATCH 02/10] Show grab cursor when hovering or dragging the activity stack --- crates/ui-egui/src/panels/activity.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index cea1ee58e4..23c67b1af5 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -73,7 +73,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { let mut cancel = None; let mut toggle = false; let frame = egui::Frame::NONE.fill(t.chrome).stroke(Stroke::new(1.0, t.field_border)).corner_radius(6).inner_margin(Margin::same(MARGIN)); - egui::Area::new(egui::Id::unique("activity-stack")) + let area_resp = egui::Area::new(egui::Id::unique("activity-stack")) .order(egui::Order::Middle) .default_pos(pos2(8.0, t.top_bar_h + 8.0)) .movable(true) @@ -106,6 +106,11 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { } }); }); + if area_resp.response.dragged() { + ctx.set_cursor_icon(egui::CursorIcon::Grabbing); + } else if area_resp.response.hovered() { + ctx.set_cursor_icon(egui::CursorIcon::Grab); + } if let Some(id) = cancel { self::cancel(app, id); } From 126e6641809daf5e57afb490ee5b2ad8bea1b0f8 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 02:07:32 -0500 Subject: [PATCH 03/10] LR-BEHAV-BG-TASKS: show pointer cursor when hovering activity cancel cross --- crates/ui-egui/src/panels/activity.rs | 20 +++++++++++++++----- crates/ui-egui/src/tests/activity.rs | 9 ++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index 23c67b1af5..286a8faf26 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -83,18 +83,21 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { // is: the stack would never grow when rows are added. Give it the whole height below the top bar instead // (the scroll area keeps to `max_height`). ui.set_max_height((ctx.content_rect().height() - t.top_bar_h - 16.0).max(80.0)); - frame.show(ui, |ui| { + let frame_resp = frame.show(ui, |ui| { let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); ui.set_width(inner); ui.spacing_mut().item_spacing.y = 3.0; + let mut cross_hovered = false; egui::ScrollArea::vertical().max_height(max_height).auto_shrink([false, true]).show(ui, |ui| { for (i, task) in tasks.iter().take(shown).enumerate() { if i > 0 { ui.add_space(6.0); } - if row(ui, &t, task, inner) { + let (clicked, hovered) = row(ui, &t, task, inner); + if clicked { cancel = Some(task.id); } + cross_hovered |= hovered; } }); if hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS) { @@ -104,10 +107,15 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { register(ui, "activity:more", r.rect); toggle = r.clicked(); } + cross_hovered }); + frame_resp.inner }); + let cross_hovered = area_resp.inner; if area_resp.response.dragged() { ctx.set_cursor_icon(egui::CursorIcon::Grabbing); + } else if cross_hovered { + ctx.set_cursor_icon(egui::CursorIcon::PointingHand); } else if area_resp.response.hovered() { ctx.set_cursor_icon(egui::CursorIcon::Grab); } @@ -125,9 +133,10 @@ pub(crate) fn cancel(app: &mut LightcraftApp, id: u64) { let _ = app.session.execute("activity.cancel", &json!({"id": id})); } -/// One task: name and ✕, the bar, the detail line. True when ✕ was clicked. -fn row(ui: &mut egui::Ui, t: &Tokens, task: &TaskInfo, width: f32) -> bool { +/// One task: name and ✕, the bar, the detail line. Returns `(cancel_clicked, cross_hovered)`. +fn row(ui: &mut egui::Ui, t: &Tokens, task: &TaskInfo, width: f32) -> (bool, bool) { let mut clicked = false; + let mut cross_hovered = false; let r = ui.vertical(|ui| { ui.set_width(width); ui.horizontal(|ui| { @@ -143,6 +152,7 @@ fn row(ui: &mut egui::Ui, t: &Tokens, task: &TaskInfo, width: f32) -> bool { crate::widgets::announce(&resp, crate::i18n::tr("Cancel")); paint(ui.painter(), rect.shrink(2.0), Icon::Close, if resp.hovered() { t.text } else { t.icon }); register(ui, format!("activity:cancel:{}", task.id), rect); + cross_hovered = resp.hovered(); clicked = resp.on_hover_text(tr("Cancel")).clicked(); } }); @@ -153,7 +163,7 @@ fn row(ui: &mut egui::Ui, t: &Tokens, task: &TaskInfo, width: f32) -> bool { } }); register(ui, format!("activity:row:{}", task.id), r.response.rect); - clicked + (clicked, cross_hovered) } /// The progress bar, named after its task for screen readers; while the amount of work isn't diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index aa97141612..ec8b0da698 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -576,12 +576,19 @@ fn rows_added_later_grow_the_stack() { #[test] fn activity_stack_area_is_movable() { let mut h = demo(); - let _g = h.app.session.activity.start("export", "Exporting", Cancel::Yes); + let g = h.app.session.activity.start("export", "Exporting", Cancel::Yes); wait_visible(&mut h); let id = egui::Id::unique("activity-stack"); let initial_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); assert!(initial_rect.min.x >= 7.0 && initial_rect.min.x <= 9.0, "default pos at x=8: {initial_rect:?}"); + // Hover cancel cross -> PointingHand + let cancel_id = format!("activity:cancel:{}", g.id()); + let r = h.request("ui.hoverWidget", json!({"id": cancel_id}), T); + assert_eq!(r["ok"], true, "{r:?}"); + h.step(); + assert_eq!(h.last_cursor, egui::CursorIcon::PointingHand, "cancel cross shows pointing hand"); + // Drag the activity stack using ui.drag let start_x = initial_rect.center().x; let start_y = initial_rect.center().y; From 3efddf82118132d875a590f34f568ea4f59d1829 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 02:11:49 -0500 Subject: [PATCH 04/10] LR-BEHAV-BG-TASKS: dynamic height constraint on drag and boundary test --- crates/ui-egui/src/panels/activity.rs | 22 ++++++++++++---------- crates/ui-egui/src/tests/activity.rs | 20 +++++++++++++++++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index 286a8faf26..bed2558ad9 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -69,7 +69,6 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { let t = Tokens::get(ctx); let shown = if app.activity_expanded { tasks.len() } else { tasks.len().min(MAX_ROWS) }; let hidden = tasks.len().saturating_sub(shown); - let max_height = (ctx.content_rect().height() - t.top_bar_h - 60.0).max(80.0); let mut cancel = None; let mut toggle = false; let frame = egui::Frame::NONE.fill(t.chrome).stroke(Stroke::new(1.0, t.field_border)).corner_radius(6).inner_margin(Margin::same(MARGIN)); @@ -80,15 +79,17 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { .constrain(true) .show(ctx, |ui| { // An area lays out in the size it had last frame, and the scroll area would take that as all the room there - // is: the stack would never grow when rows are added. Give it the whole height below the top bar instead - // (the scroll area keeps to `max_height`). - ui.set_max_height((ctx.content_rect().height() - t.top_bar_h - 16.0).max(80.0)); + // is: the stack would never grow when rows are added. Give it the whole height below its position instead + // (the scroll area keeps to `max_scroll_h`). + let available_h = (ctx.content_rect().bottom() - ui.cursor().top() - 16.0).max(80.0); + ui.set_max_height(available_h); let frame_resp = frame.show(ui, |ui| { let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); ui.set_width(inner); ui.spacing_mut().item_spacing.y = 3.0; - let mut cross_hovered = false; - egui::ScrollArea::vertical().max_height(max_height).auto_shrink([false, true]).show(ui, |ui| { + let mut interactive_hovered = false; + let max_scroll_h = (available_h - 44.0).max(60.0); + egui::ScrollArea::vertical().max_height(max_scroll_h).auto_shrink([false, true]).show(ui, |ui| { for (i, task) in tasks.iter().take(shown).enumerate() { if i > 0 { ui.add_space(6.0); @@ -97,7 +98,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { if clicked { cancel = Some(task.id); } - cross_hovered |= hovered; + interactive_hovered |= hovered; } }); if hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS) { @@ -106,15 +107,16 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { let r = ui.add(egui::Label::new(RichText::new(text).font(t.font(11.0)).color(t.accent)).sense(Sense::click())); register(ui, "activity:more", r.rect); toggle = r.clicked(); + interactive_hovered |= r.hovered(); } - cross_hovered + interactive_hovered }); frame_resp.inner }); - let cross_hovered = area_resp.inner; + let interactive_hovered = area_resp.inner; if area_resp.response.dragged() { ctx.set_cursor_icon(egui::CursorIcon::Grabbing); - } else if cross_hovered { + } else if interactive_hovered { ctx.set_cursor_icon(egui::CursorIcon::PointingHand); } else if area_resp.response.hovered() { ctx.set_cursor_icon(egui::CursorIcon::Grab); diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index ec8b0da698..d5fcca1158 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -589,9 +589,9 @@ fn activity_stack_area_is_movable() { h.step(); assert_eq!(h.last_cursor, egui::CursorIcon::PointingHand, "cancel cross shows pointing hand"); - // Drag the activity stack using ui.drag - let start_x = initial_rect.center().x; - let start_y = initial_rect.center().y; + // Drag the activity stack using ui.drag from non-interactive frame padding + let start_x = initial_rect.min.x + 4.0; + let start_y = initial_rect.min.y + 4.0; let dx = 100.0; let dy = 60.0; let r = h.request("ui.drag", json!({"x": start_x, "y": start_y, "toX": start_x + dx, "toY": start_y + dy, "steps": 6}), T); @@ -600,6 +600,20 @@ fn activity_stack_area_is_movable() { let updated_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); assert!((updated_rect.min.x - (initial_rect.min.x + dx)).abs() < 5.0, "stack moved in x: {updated_rect:?}"); assert!((updated_rect.min.y - (initial_rect.min.y + dy)).abs() < 5.0, "stack moved in y: {updated_rect:?}"); + assert!(!g.is_cancelled(), "dragging the stack does not cancel the task"); + + // Dragging beyond the viewport edge is constrained on screen + let content = h.view.ctx.content_rect(); + let r = h.request( + "ui.drag", + json!({"x": updated_rect.min.x + 4.0, "y": updated_rect.min.y + 4.0, "toX": content.max.x + 500.0, "toY": content.max.y + 500.0, "steps": 6}), + T, + ); + assert_eq!(r["ok"], true, "{r:?}"); + h.step(); + let constrained_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!(constrained_rect.max.x <= content.max.x + 1.0, "constrained in x: {constrained_rect:?} vs {content:?}"); + assert!(constrained_rect.max.y <= content.max.y + 1.0, "constrained in y: {constrained_rect:?} vs {content:?}"); } #[test] From ca258379c30c9433d0149b8268b18ed51b1b0731 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 11:09:57 -0500 Subject: [PATCH 05/10] LR-BEHAV-BG-TASKS: refine scroll height calculation and test bidirectional constraints --- crates/ui-egui/src/panels/activity.rs | 6 ++- crates/ui-egui/src/tests/activity.rs | 55 +++++++++++++++++++++------ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index bed2558ad9..304694e6fb 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -88,7 +88,9 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { ui.set_width(inner); ui.spacing_mut().item_spacing.y = 3.0; let mut interactive_hovered = false; - let max_scroll_h = (available_h - 44.0).max(60.0); + let has_footer = hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS); + let footer_reserve = if has_footer { 44.0 } else { 20.0 }; + let max_scroll_h = (available_h - footer_reserve).max(0.0); egui::ScrollArea::vertical().max_height(max_scroll_h).auto_shrink([false, true]).show(ui, |ui| { for (i, task) in tasks.iter().take(shown).enumerate() { if i > 0 { @@ -101,7 +103,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { interactive_hovered |= hovered; } }); - if hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS) { + if has_footer { ui.add_space(4.0); let text = if hidden > 0 { tr_format!("+{n} more", n = hidden) } else { tr("Show less").to_string() }; let r = ui.add(egui::Label::new(RichText::new(text).font(t.font(11.0)).color(t.accent)).sense(Sense::click())); diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index d5fcca1158..e82978ae76 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -589,21 +589,35 @@ fn activity_stack_area_is_movable() { h.step(); assert_eq!(h.last_cursor, egui::CursorIcon::PointingHand, "cancel cross shows pointing hand"); - // Drag the activity stack using ui.drag from non-interactive frame padding - let start_x = initial_rect.min.x + 4.0; - let start_y = initial_rect.min.y + 4.0; - let dx = 100.0; - let dy = 60.0; - let r = h.request("ui.drag", json!({"x": start_x, "y": start_y, "toX": start_x + dx, "toY": start_y + dy, "steps": 6}), T); + // Hover frame padding -> Grab + let r = h.request("ui.move", json!({"x": initial_rect.min.x + 4.0, "y": initial_rect.min.y + 4.0}), T); assert_eq!(r["ok"], true, "{r:?}"); h.step(); + assert_eq!(h.last_cursor, egui::CursorIcon::Grab, "frame padding hover shows grab cursor"); + + // Drag the activity stack from non-interactive frame padding, verifying Grabbing cursor mid-drag + let start_pos = initial_rect.min + egui::vec2(4.0, 4.0); + let target_pos = start_pos + egui::vec2(100.0, 60.0); + let modifiers = egui::Modifiers::NONE; + h.app.synthetic.push(egui::Event::PointerMoved(start_pos)); + h.app.synthetic.push(egui::Event::PointerButton { pos: start_pos, button: egui::PointerButton::Primary, pressed: true, modifiers }); + h.step(); + for i in 1..=4 { + h.app.synthetic.push(egui::Event::PointerMoved(start_pos + (target_pos - start_pos) * (i as f32 / 4.0))); + h.step(); + } + assert_eq!(h.last_cursor, egui::CursorIcon::Grabbing, "cursor is Grabbing mid-drag"); + h.app.synthetic.push(egui::Event::PointerButton { pos: target_pos, button: egui::PointerButton::Primary, pressed: false, modifiers }); + h.step(); + h.step(); let updated_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); - assert!((updated_rect.min.x - (initial_rect.min.x + dx)).abs() < 5.0, "stack moved in x: {updated_rect:?}"); - assert!((updated_rect.min.y - (initial_rect.min.y + dy)).abs() < 5.0, "stack moved in y: {updated_rect:?}"); + assert!((updated_rect.min.x - (initial_rect.min.x + 100.0)).abs() < 5.0, "stack moved in x: {updated_rect:?}"); + assert!((updated_rect.min.y - (initial_rect.min.y + 60.0)).abs() < 5.0, "stack moved in y: {updated_rect:?}"); assert!(!g.is_cancelled(), "dragging the stack does not cancel the task"); - // Dragging beyond the viewport edge is constrained on screen + // Dragging beyond the right and bottom viewport edges moves toward edges and is constrained on screen let content = h.view.ctx.content_rect(); + let before_rb = updated_rect; let r = h.request( "ui.drag", json!({"x": updated_rect.min.x + 4.0, "y": updated_rect.min.y + 4.0, "toX": content.max.x + 500.0, "toY": content.max.y + 500.0, "steps": 6}), @@ -611,9 +625,26 @@ fn activity_stack_area_is_movable() { ); assert_eq!(r["ok"], true, "{r:?}"); h.step(); - let constrained_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); - assert!(constrained_rect.max.x <= content.max.x + 1.0, "constrained in x: {constrained_rect:?} vs {content:?}"); - assert!(constrained_rect.max.y <= content.max.y + 1.0, "constrained in y: {constrained_rect:?} vs {content:?}"); + let constrained_rb = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!(constrained_rb.min.x > before_rb.min.x, "stack moved right toward edge: {constrained_rb:?} vs {before_rb:?}"); + assert!(constrained_rb.min.y > before_rb.min.y, "stack moved down toward edge: {constrained_rb:?} vs {before_rb:?}"); + assert!(constrained_rb.max.x <= content.max.x + 1.0, "constrained in right: {constrained_rb:?} vs {content:?}"); + assert!(constrained_rb.max.y <= content.max.y + 1.0, "constrained in bottom: {constrained_rb:?} vs {content:?}"); + + // Dragging past the left and top edges moves toward top-left and is constrained + let before_lt = constrained_rb; + let r = h.request( + "ui.drag", + json!({"x": constrained_rb.min.x + 4.0, "y": constrained_rb.min.y + 4.0, "toX": content.min.x - 500.0, "toY": content.min.y - 500.0, "steps": 6}), + T, + ); + assert_eq!(r["ok"], true, "{r:?}"); + h.step(); + let constrained_lt = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!(constrained_lt.min.x < before_lt.min.x, "stack moved left toward edge: {constrained_lt:?} vs {before_lt:?}"); + assert!(constrained_lt.min.y < before_lt.min.y, "stack moved up toward edge: {constrained_lt:?} vs {before_lt:?}"); + assert!(constrained_lt.min.x >= content.min.x - 1.0, "constrained in left: {constrained_lt:?} vs {content:?}"); + assert!(constrained_lt.min.y >= content.min.y - 1.0, "constrained in top: {constrained_lt:?} vs {content:?}"); } #[test] From ca475515319f4abaacea9de2c3d90bed302108e6 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 11:41:07 -0500 Subject: [PATCH 06/10] LR-BEHAV-BG-TASKS: account for egui scroll minimum and add megabytes docstring --- crates/ui-egui/src/panels/activity.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index 304694e6fb..9de1d09b2a 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -35,6 +35,7 @@ pub fn count_text(t: &TaskInfo) -> String { } } +/// Format bytes as a decimal megabyte string ("1.2", "42"). fn megabytes(bytes: u64) -> String { let mb = bytes as f64 / 1_048_576.0; if mb < 10.0 { format!("{mb:.1}") } else { format!("{:.0}", mb.floor()) } @@ -81,17 +82,19 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { // An area lays out in the size it had last frame, and the scroll area would take that as all the room there // is: the stack would never grow when rows are added. Give it the whole height below its position instead // (the scroll area keeps to `max_scroll_h`). - let available_h = (ctx.content_rect().bottom() - ui.cursor().top() - 16.0).max(80.0); + let has_footer = hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS); + let footer_reserve = if has_footer { 44.0 } else { 20.0 }; + let min_scroll_h = 64.0f32; + let space_below = (ctx.content_rect().bottom() - ui.cursor().top() - 16.0).max(0.0); + let available_h = space_below.max(min_scroll_h + footer_reserve); ui.set_max_height(available_h); let frame_resp = frame.show(ui, |ui| { let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); ui.set_width(inner); ui.spacing_mut().item_spacing.y = 3.0; let mut interactive_hovered = false; - let has_footer = hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS); - let footer_reserve = if has_footer { 44.0 } else { 20.0 }; - let max_scroll_h = (available_h - footer_reserve).max(0.0); - egui::ScrollArea::vertical().max_height(max_scroll_h).auto_shrink([false, true]).show(ui, |ui| { + let max_scroll_h = (available_h - footer_reserve).max(min_scroll_h); + egui::ScrollArea::vertical().max_height(max_scroll_h).min_scrolled_height(min_scroll_h).auto_shrink([false, true]).show(ui, |ui| { for (i, task) in tasks.iter().take(shown).enumerate() { if i > 0 { ui.add_space(6.0); From e8f864163242456b6ab7041a537b9671b9f91b0c Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 12:09:31 -0500 Subject: [PATCH 07/10] LR-BEHAV-BG-TASKS: adapt height to viewport and add short-viewport test --- crates/ui-egui/src/panels/activity.rs | 10 ++++--- crates/ui-egui/src/tests/activity.rs | 42 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index 9de1d09b2a..e0da90c872 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -20,7 +20,9 @@ pub const MAX_ROWS: usize = 3; /// The stack's width (points). pub const WIDTH: f32 = 280.0; +/// Inner margin around the activity stack frame (points). const MARGIN: i8 = 8; +/// Size of the ✕ cancel cross (points). const CROSS: f32 = 16.0; /// "3 of 25", "12 of 340 MB", "40 %"; empty while the amount of work isn't known. @@ -84,17 +86,17 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { // (the scroll area keeps to `max_scroll_h`). let has_footer = hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS); let footer_reserve = if has_footer { 44.0 } else { 20.0 }; - let min_scroll_h = 64.0f32; let space_below = (ctx.content_rect().bottom() - ui.cursor().top() - 16.0).max(0.0); - let available_h = space_below.max(min_scroll_h + footer_reserve); + let max_stack_h = (ctx.content_rect().height() - 16.0).max(footer_reserve); + let available_h = space_below.clamp(footer_reserve, max_stack_h); ui.set_max_height(available_h); let frame_resp = frame.show(ui, |ui| { let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); ui.set_width(inner); ui.spacing_mut().item_spacing.y = 3.0; let mut interactive_hovered = false; - let max_scroll_h = (available_h - footer_reserve).max(min_scroll_h); - egui::ScrollArea::vertical().max_height(max_scroll_h).min_scrolled_height(min_scroll_h).auto_shrink([false, true]).show(ui, |ui| { + let max_scroll_h = (available_h - footer_reserve).max(0.0); + egui::ScrollArea::vertical().max_height(max_scroll_h).min_scrolled_height(0.0).auto_shrink([false, true]).show(ui, |ui| { for (i, task) in tasks.iter().take(shown).enumerate() { if i > 0 { ui.add_space(6.0); diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index e82978ae76..d2a2b39db4 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -647,6 +647,48 @@ fn activity_stack_area_is_movable() { assert!(constrained_lt.min.y >= content.min.y - 1.0, "constrained in top: {constrained_lt:?} vs {content:?}"); } +#[test] +fn activity_stack_short_viewport_near_bottom_keeps_controls_reachable() { + // 300 pt tall viewport exercises the height-budget path. + // Do NOT use h.settle(T): demo renders asynchronously and blocks 60 s. + // Two steps suffice for a pure-UI / height-constraint test. + let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() }); + let mut h = Headless::new(app, [600.0, 300.0], 1.0); + h.step(); + h.step(); + let guards: Vec<_> = (0..5).map(|i| h.app.session.activity.start("export", &format!("Task {i}"), Cancel::Yes)).collect(); + wait_visible(&mut h); + + let content = h.view.ctx.content_rect(); + let id = egui::Id::unique("activity-stack"); + + // At the default position the cancel and "+more" controls are within the viewport. + let cancel_id = format!("activity:cancel:{}", guards[0].id()); + assert!(has(&h, &cancel_id), "cancel button is present at default position"); + assert!(content.contains_rect(rect(&h, &cancel_id)), "cancel button within viewport at default position"); + assert!(has(&h, "activity:more"), "+more button is present at default position"); + assert!(content.contains_rect(rect(&h, "activity:more")), "+more button within viewport at default position"); + + // Cancel task 0 while controls are reachable at the default position. + click(&mut h, &cancel_id); + assert!(guards[0].is_cancelled(), "cancel button was clickable and worked"); + + // Drag the stack to 40 pt above the bottom edge. When only 40 pt remain the + // height-budget path clamps available_h to footer_reserve, so rows disappear — + // that is expected. What must hold is that the stack does not exceed the + // viewport: its max.y must stay at or below content.bottom(). + let initial_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + let r = h.request( + "ui.drag", + json!({"x": initial_rect.min.x + 4.0, "y": initial_rect.min.y + 4.0, "toX": initial_rect.min.x + 4.0, "toY": content.bottom() - 40.0, "steps": 6}), + T, + ); + assert_eq!(r["ok"], true, "{r:?}"); + h.step(); + let dragged_rect = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!(dragged_rect.max.y <= content.bottom() + 1.0, "stack stays within viewport after near-bottom drag: {dragged_rect:?} vs {content:?}"); +} + #[test] fn immediate_library_commands_and_auto_sync_show_completion() { let mut h = demo(); From fc64b8f2aaa95651193d5fcddb9913e3de39a4ca Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 12:46:49 -0500 Subject: [PATCH 08/10] LR-BEHAV-BG-TASKS: cap max_stack_h at true viewport capacity for sub-footer-reserve viewports --- crates/ui-egui/src/panels/activity.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index e0da90c872..117b88c2aa 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -87,8 +87,10 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { let has_footer = hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS); let footer_reserve = if has_footer { 44.0 } else { 20.0 }; let space_below = (ctx.content_rect().bottom() - ui.cursor().top() - 16.0).max(0.0); - let max_stack_h = (ctx.content_rect().height() - 16.0).max(footer_reserve); - let available_h = space_below.clamp(footer_reserve, max_stack_h); + // Cap at the true viewport capacity so the stack never claims more height + // than the viewport can provide, even when it is shorter than `footer_reserve`. + let max_stack_h = (ctx.content_rect().height() - 16.0).max(0.0); + let available_h = space_below.clamp(max_stack_h.min(footer_reserve), max_stack_h); ui.set_max_height(available_h); let frame_resp = frame.show(ui, |ui| { let inner = WIDTH - 2.0 * (f32::from(MARGIN) + 1.0); From 2309fbad0cd71828872e63fa549c80299b465f04 Mon Sep 17 00:00:00 2001 From: bd78 Date: Sun, 8 Nov 2026 14:35:45 -0500 Subject: [PATCH 09/10] LR-BEHAV-BG-TASKS: add docstrings to test helpers and new test functions --- crates/ui-egui/src/tests/activity.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index d2a2b39db4..d9945ecbbf 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -12,6 +12,7 @@ use crate::{LightcraftApp, Services}; // generous: merges and renders run on worker threads that a busy machine (a full workspace test run) slows a lot const T: Duration = Duration::from_secs(60); +/// Build a headless instance with the procedural demo library loaded. fn demo() -> Headless { let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() }); let mut h = Headless::new(app, [1200.0, 800.0], 1.0); @@ -21,14 +22,17 @@ fn demo() -> Headless { h } +/// Check whether a widget with the given identifier is registered. fn has(h: &Headless, id: &str) -> bool { h.app.widgets.iter().any(|(w, _)| w == id) } +/// Count the number of activity row widgets registered. fn rows(h: &Headless) -> usize { h.app.widgets.iter().filter(|(w, _)| w.starts_with("activity:row:")).count() } +/// Return the bounding rectangle of the registered widget with `id`. fn rect(h: &Headless, id: &str) -> egui::Rect { h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r).unwrap_or_else(|| panic!("no widget {id}")) } @@ -573,6 +577,7 @@ fn rows_added_later_grow_the_stack() { } } +/// Verify that dragging the activity stack moves the panel across frames and respects viewport constraints. #[test] fn activity_stack_area_is_movable() { let mut h = demo(); @@ -647,6 +652,7 @@ fn activity_stack_area_is_movable() { assert!(constrained_lt.min.y >= content.min.y - 1.0, "constrained in top: {constrained_lt:?} vs {content:?}"); } +/// Verify that dragging the stack near the bottom in a short viewport keeps controls reachable and within bounds. #[test] fn activity_stack_short_viewport_near_bottom_keeps_controls_reachable() { // 300 pt tall viewport exercises the height-budget path. From 4b9d2eda4d5dece37f4f838e8af0514fc22aa538 Mon Sep 17 00:00:00 2001 From: "Bruno D." Date: Wed, 18 Nov 2026 23:28:18 -0500 Subject: [PATCH 10/10] LR-BEHAV-BG-TASKS: a grip at the top of the activity stack moves it When the expanded task list overflows, a drag over its rows scrolls the list (touch screens), so only the narrow frame margin and the footer could move the stack. A grip strip above the list, outside the scroll area, now always moves it. Its height counts in the stack's height budget. A test drags the grip with an overflowing list. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panels/activity.rs | 13 ++++++++++++- crates/ui-egui/src/tests/activity.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rs index 117b88c2aa..3c1e7aac9b 100644 --- a/crates/ui-egui/src/panels/activity.rs +++ b/crates/ui-egui/src/panels/activity.rs @@ -24,6 +24,9 @@ pub const WIDTH: f32 = 280.0; const MARGIN: i8 = 8; /// Size of the ✕ cancel cross (points). const CROSS: f32 = 16.0; +/// Height of the grip strip at the top of the stack (points): a drag there always moves the stack, also when the +/// task list overflows and a drag over its rows scrolls it (touch screens). +const HANDLE_H: f32 = 10.0; /// "3 of 25", "12 of 340 MB", "40 %"; empty while the amount of work isn't known. pub fn count_text(t: &TaskInfo) -> String { @@ -85,7 +88,8 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { // is: the stack would never grow when rows are added. Give it the whole height below its position instead // (the scroll area keeps to `max_scroll_h`). let has_footer = hidden > 0 || (app.activity_expanded && tasks.len() > MAX_ROWS); - let footer_reserve = if has_footer { 44.0 } else { 20.0 }; + // the footer (or the frame's margins alone) and the grip strip with its spacing + let footer_reserve = if has_footer { 44.0 } else { 20.0 } + HANDLE_H + 3.0; let space_below = (ctx.content_rect().bottom() - ui.cursor().top() - 16.0).max(0.0); // Cap at the true viewport capacity so the stack never claims more height // than the viewport can provide, even when it is shorter than `footer_reserve`. @@ -97,6 +101,13 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { ui.set_width(inner); ui.spacing_mut().item_spacing.y = 3.0; let mut interactive_hovered = false; + // the grip: not a widget, so a drag on it is the area's (moves the stack), never the list's + let (grip, _) = ui.allocate_exact_size(vec2(inner, HANDLE_H), Sense::hover()); + register(ui, "activity:handle", grip); + for dy in [-1.5, 1.5] { + let y = grip.center().y + dy; + ui.painter().line_segment([pos2(grip.center().x - 12.0, y), pos2(grip.center().x + 12.0, y)], Stroke::new(1.0, t.text_dim)); + } let max_scroll_h = (available_h - footer_reserve).max(0.0); egui::ScrollArea::vertical().max_height(max_scroll_h).min_scrolled_height(0.0).auto_shrink([false, true]).show(ui, |ui| { for (i, task) in tasks.iter().take(shown).enumerate() { diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index 896bc75a4b..5861a95b8a 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -695,6 +695,32 @@ fn activity_stack_short_viewport_near_bottom_keeps_controls_reachable() { assert!(dragged_rect.max.y <= content.bottom() + 1.0, "stack stays within viewport after near-bottom drag: {dragged_rect:?} vs {content:?}"); } +/// The grip at the top of the stack sits outside the task list: dragging it moves the stack even when the list +/// overflows (a drag over the rows would scroll the list instead). +#[test] +fn the_grip_moves_the_stack_when_the_list_overflows() { + let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() }); + let mut h = Headless::new(app, [600.0, 300.0], 1.0); + h.step(); + h.step(); + let _guards: Vec<_> = (0..8).map(|i| h.app.session.activity.start("export", &format!("Task {i}"), Cancel::Yes)).collect(); + wait_visible(&mut h); + click(&mut h, "activity:more"); + assert!(h.app.activity_expanded, "the stack shows every task"); + let grip = rect(&h, "activity:handle"); + let first_row = h.app.widgets.iter().filter(|(w, _)| w.starts_with("activity:row:")).map(|(_, r)| r.min.y).fold(f32::MAX, f32::min); + assert!(grip.max.y <= first_row, "the grip is above the list: {grip:?} vs first row at {first_row}"); + let id = egui::Id::unique("activity-stack"); + let before = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + let from = grip.center(); + let r = h.request("ui.drag", json!({"x": from.x, "y": from.y, "toX": from.x + 120.0, "toY": from.y, "steps": 6}), T); + assert_eq!(r["ok"], true, "{r:?}"); + h.step(); + h.step(); + let after = h.view.ctx.memory(|m| m.area_rect(id)).expect("the stack is drawn"); + assert!((after.min.x - (before.min.x + 120.0)).abs() < 5.0, "the grip moved the stack: {before:?} -> {after:?}"); +} + #[test] fn immediate_library_commands_and_auto_sync_show_completion() { let mut h = demo();