Window caption parts: a settled region declares them again when it replays

A title bar that settles keeps the caption record the Windows hit test reads.
This commit is contained in:
aiongg
2026-11-17 23:57:45 +00:00
parent 6836ba18dc
commit fc585f6227
2 changed files with 29 additions and 2 deletions
@@ -308,8 +308,10 @@ pub(super) fn with_exclusive<R>(ctx: &Context, viewport: ViewportId, f: impl FnO
}
/// Records that `part` of the component `owner` is, over `rect`, what `hit` says for the running viewport's window.
/// A part declared again in the same pass replaces its entry.
/// A part declared again in the same pass replaces its entry. A settled region that replays its last run declares
/// its parts again, so a settled title bar keeps its caption regions.
pub(crate) fn note_exclusive(ctx: &Context, owner: Id, part: PartRef, hit: WindowHit, rect: Rect) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| note_exclusive(ctx, owner, part, hit, rect));
with_exclusive(ctx, pass::current_viewport(ctx), |exclusive| {
let entry = ExclusivePart { owner, part, hit, rect };
match exclusive.current.iter_mut().find(|held| held.owner == owner && held.part == part) {
+26 -1
View File
@@ -2,13 +2,14 @@
//! `WindowHost::caption_regions`.
use craft_behavior::{PartKey, Sense};
use craft_ui::contract::{Common, Component, Cx, MeasureCx, PartsCx, Props as _, Role, Show as _};
use craft_ui::contract::{Common, Component, Cx, Lazy, MeasureCx, PartsCx, Props as _, Role, Show as _};
use craft_ui::runtime::windows::{ResizeEdge, WindowHit, WindowHost};
use craft_ui::shell::Caption;
use craft_ui::testing::trial;
use craft_ui_test_kit::contract::PlainStyle;
use craft_ui_test_kit::windows::Windows;
use egui::{Rect, Response, Vec2, ViewportId, pos2, vec2};
use std::cell::Cell;
const MOVE: PartKey = PartKey::new("move");
const CLOSE: PartKey = PartKey::new("close");
@@ -84,6 +85,30 @@ fn exclusive_parts_are_the_caption_record() {
assert_eq!(host.caption_regions(ViewportId::ROOT), None, "a bar that stops registering leaves no record");
}
/// A title bar that settles (`Lazy::settles`) keeps its caption record while it replays its last run, so the
/// Windows hit test still finds its drag area and buttons.
#[trial]
fn a_settled_bar_keeps_its_caption_record() {
let windows = Windows::new();
let host = WindowHost::of(&windows.ctx);
let ran = Cell::new(false);
let mut frame = || {
ran.set(false);
windows.frame(vec![], vec![], |ui| {
Lazy::new("bar", 0.0).settles(true).content(1).show(ui, |ui| {
ran.set(true);
Bar { common: Common::new() }.id_salt("bar").show(ui);
});
});
ran.get()
};
assert!(frame(), "the bar runs in its first frame");
let settled = (0..4).map(|_| frame()).last();
assert_eq!(settled, Some(false), "the bar settles");
let regions = host.caption_regions(ViewportId::ROOT).expect("the settled bar keeps its parts");
assert_eq!(regions.buttons.len() + regions.edges.len() + regions.moves.len(), 3, "every part stays: {regions:?}");
}
/// The maximize button under a window procedure that owns the pointer there (Windows 11 snap layouts answer the hit
/// test `HTMAXBUTTON`): the procedure reports hover, press and release through the sink, and the button shows and acts
/// as it does under the app's own pointer, so a release on it is a click and a press that ends elsewhere is none.