mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 16:59:56 +01:00
Merge origin/main into design-port/fw-palette-menu-dismissal
Main's #3563 keeps a popup window's layer memory by recording its appearance in the opener's viewport too (note_appeared), with recall_shown and appeared_this_frame. This branch's own fix for the same reset goes: appears_in, layer_viewport, reanchor, appeared_in_pass and the popup pass read before show_popup, the body hook's popup viewport read, and the three trials main covers (scroll offset, second right-click, and the timeout, which reads the same layer memory). Kept: the absorb zone in end_pass (host windows left out, exiting members dropped, the companion bar kept), the palette trial with its trace and the press_judgement and layer_pointer_at hooks, and the pass guard in popup_dismissal. The guard now reads overlay::opening in the opener, which note_appeared stamps in this pass before the popup's nested pass runs. Main's appeared_this_frame is frame-wide and only feeds pressed_elsewhere, so it is not the same signal: a press a later pass of the frame takes must still close the menu.
This commit is contained in:
commit
8f7d67a002
31 files changed
+848
-472
No files matched your search
@@ -122,10 +122,12 @@ jobs:
|
||||
cache-version: &cache-version v2-${{ needs.platforms.outputs.profile }}
|
||||
cold-build: ${{ github.event.schedule == '17 0 * * *' || github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/next' }}
|
||||
lint-cache: false
|
||||
# The vendored crates are on the workspace `exclude` list, so unreached-rs has no module tree for them.
|
||||
# The vendored crates are on the workspace `exclude` list and craft-pdf's read-only contract is a
|
||||
# workspace of its own (pdf.yml tests it), so unreached-rs has no module tree for them.
|
||||
unreached-rs-allow: |
|
||||
**/fixtures/**
|
||||
vendor/**
|
||||
crates/pdf/read-only-contract/**
|
||||
timeout-minutes: &timeout 120
|
||||
# Every leg runs its tests with nextest, and its doctests with cargo test (.config/nextest.toml).
|
||||
tools: &tools cargo-nextest@0.9.150
|
||||
|
||||
Generated
+14
-14
@@ -5581,7 +5581,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
@@ -5637,7 +5637,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5672,7 +5672,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
@@ -5691,7 +5691,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-wgpu"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5710,7 +5710,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-winit"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"bytemuck",
|
||||
@@ -5730,7 +5730,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui",
|
||||
@@ -5743,7 +5743,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_kittest"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -5820,7 +5820,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
@@ -5893,7 +5893,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5919,7 +5919,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[package]]
|
||||
name = "equator"
|
||||
@@ -15251,19 +15251,19 @@ dependencies = [
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_extras"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
+14
-14
@@ -317,20 +317,20 @@ hayro-postscript = { path = "vendor/hayro-postscript" }
|
||||
linesweeper = { path = "vendor/linesweeper" }
|
||||
vello_common = { path = "vendor/vello_common" }
|
||||
vello_cpu = { path = "vendor/vello_cpu" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
|
||||
# symphonia's FLAC decoder restores LPC samples as `residual + (prediction as i32)`. In a valid
|
||||
|
||||
@@ -942,6 +942,7 @@ ui-system_fonts = ["ui", "craft-ui/system_fonts"]
|
||||
ui-testing = ["ui", "craft-ui/testing"]
|
||||
|
||||
update = ["dep:craft-update"] # native only: downloads and installs through getrandom without wasm support
|
||||
update-local-mirror = ["update", "craft-update/local-mirror"]
|
||||
update-oci_migration = ["update", "craft-update/oci_migration"]
|
||||
|
||||
usd = ["dep:craft-usd"]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// The egui fork the library is built and tested with. Apps patch egui to exactly this.
|
||||
pub const GIT: &str = "https://github.com/storytold/egui.git";
|
||||
/// The commit of [`GIT`].
|
||||
pub const REV: &str = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec";
|
||||
pub const REV: &str = "b9770908e0f304896f9658d239a7b29cf8af1564";
|
||||
|
||||
/// The packages the workspace patches to the fork (the `[patch.crates-io]` entries that name [`GIT`]).
|
||||
pub const PACKAGES: &[&str] = &[
|
||||
|
||||
@@ -734,6 +734,7 @@ pub struct FontPicker<'a> {
|
||||
host_picked: Option<String>,
|
||||
/// Whether the font picker uses compact bar sizing (`size.length.field.sm` / `size.length.short`).
|
||||
#[style_key]
|
||||
#[prop]
|
||||
compact: bool,
|
||||
}
|
||||
|
||||
@@ -787,13 +788,6 @@ impl<'a> FontPicker<'a> {
|
||||
.enabled(catalog.is_ready())
|
||||
}
|
||||
|
||||
/// Sets whether the font picker uses compact bar sizing (`size.length.field.sm` / `size.length.short`).
|
||||
#[must_use]
|
||||
pub fn compact(mut self, compact: bool) -> Self {
|
||||
self.compact = compact;
|
||||
self
|
||||
}
|
||||
|
||||
/// The adornments at the end of the field: the missing mark when `missing`, then the chevron. The mark is a glyph
|
||||
/// whose part carries the note.
|
||||
fn trailing(name: Label, missing: bool, arrow: DropdownArrow) -> Vec<Adornment> {
|
||||
|
||||
@@ -868,15 +868,23 @@ fn copy_in(folder: &OsFontFolder, p: &Planned, found: Option<&str>) -> Result<()
|
||||
}
|
||||
let part = aside(&p.path, "part");
|
||||
let _ = std::fs::remove_file(&part);
|
||||
std::fs::copy(&p.source, &part).map_err(io(what()))?;
|
||||
folder.unload(&p.path);
|
||||
let checked = File::open(&part).and_then(|f| f.sync_all()).map_err(io(what())).and_then(|()| {
|
||||
if file_sha256(&part).as_ref() == Some(&p.sha256) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Verify { file: p.store_file.clone(), error: VerifyError::Sha256 })
|
||||
}
|
||||
// One writable handle writes and flushes the copy: Windows flushes only through a handle that can write, and the
|
||||
// copy doesn't take the source's permissions (`std::fs::copy` would), so a read-only store file still copies.
|
||||
let copied = File::open(&p.source).and_then(|mut source| {
|
||||
let mut copy = File::create(&part)?;
|
||||
std::io::copy(&mut source, &mut copy)?;
|
||||
copy.sync_all()
|
||||
});
|
||||
if let Err(e) = copied {
|
||||
let _ = std::fs::remove_file(&part);
|
||||
return Err(io(what())(e));
|
||||
}
|
||||
folder.unload(&p.path);
|
||||
let checked = if file_sha256(&part).as_ref() == Some(&p.sha256) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Verify { file: p.store_file.clone(), error: VerifyError::Sha256 })
|
||||
};
|
||||
if let Err(e) = checked.and_then(|()| publish(&part, p, found)) {
|
||||
let _ = std::fs::remove_file(&part);
|
||||
return Err(e);
|
||||
|
||||
@@ -904,6 +904,28 @@ mod store {
|
||||
assert_eq!(files[0]["postscript"], json!(["TestSans-Bold"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_only_store_files_are_made_available() {
|
||||
let server = Server::start();
|
||||
server.serve_fixture(&fixture());
|
||||
let (store, dir, root, shared) = shared_store(&server, "os-fonts-read-only");
|
||||
let set_read_only = |read_only: bool| {
|
||||
for name in entries(&dir.join("testsans")) {
|
||||
let path = dir.join("testsans").join(name);
|
||||
let mut permissions = std::fs::metadata(&path).unwrap().permissions();
|
||||
permissions.set_readonly(read_only);
|
||||
std::fs::set_permissions(&path, permissions).unwrap();
|
||||
}
|
||||
};
|
||||
set_read_only(true);
|
||||
let copies = store.make_available(GOOGLE_FONTS, "Test Sans");
|
||||
set_read_only(false);
|
||||
assert_eq!(copies.unwrap().len(), 3, "a read-only store file still copies");
|
||||
assert!(entries(&shared.join("testsans")).iter().all(|name| !name.starts_with('.')), "no copy is left aside");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_family_made_available_to_all_apps_is_withdrawn_exactly() {
|
||||
let server = Server::start();
|
||||
@@ -1005,6 +1027,7 @@ mod store {
|
||||
}
|
||||
|
||||
/// A catalog of the same system as [`shared_store`]'s, to look at what a scan sees.
|
||||
#[cfg(unix)]
|
||||
fn catalog_of(dir: &Path, root: &Path) -> Catalog {
|
||||
let env = FontEnv {
|
||||
os: Os::Unix,
|
||||
@@ -1187,9 +1210,12 @@ mod store {
|
||||
assert!(with(&[], &flatpak).is_err(), "read only");
|
||||
info("~/.local/share/fonts;");
|
||||
assert!(with(&[], &flatpak).is_ok());
|
||||
assert!(with(&[("HOST_XDG_DATA_HOME", "/elsewhere")], &flatpak).is_err(), "the grant is for another folder");
|
||||
// Absolute on every platform: `/elsewhere` isn't on Windows.
|
||||
let elsewhere = root.join("elsewhere");
|
||||
let host = [("HOST_XDG_DATA_HOME", elsewhere.to_str().unwrap())];
|
||||
assert!(with(&host, &flatpak).is_err(), "the grant is for another folder");
|
||||
info("xdg-data/fonts;");
|
||||
assert_eq!(with(&[("HOST_XDG_DATA_HOME", "/elsewhere")], &flatpak), Ok(PathBuf::from("/elsewhere/fonts/Craft")));
|
||||
assert_eq!(with(&host, &flatpak), Ok(elsewhere.join("fonts/Craft")));
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
}
|
||||
}
|
||||
@@ -206,14 +206,9 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
self.strip = scroll_strip_height(&env.tokens);
|
||||
self.row = env.tokens.size.control.md;
|
||||
let Some(scroll) = scroll else { return };
|
||||
// A scrolled body of a layer, or in one, starts at the top at every opening of the layer, as at its first. A
|
||||
// layer shown in a popup window is stamped in that window's pass, not in this one, which is its opener's: its
|
||||
// appearance is read where it is stamped.
|
||||
let opening = match &props.mount {
|
||||
Mount::Layer(overlay) => {
|
||||
let viewport = crate::contract::overlay::layer_viewport(&ctx, overlay, id);
|
||||
crate::runtime::overlay::appears_in(&ctx, viewport, id, false)
|
||||
}
|
||||
// A scrolled body of a layer, or in one, starts at the top at every opening of the layer, as at its first.
|
||||
let opening = match props.mount {
|
||||
Mount::Layer(_) => crate::runtime::overlay::appears(&ctx, id, false),
|
||||
_ => crate::runtime::overlay::drawing_parent(&ctx).is_some_and(|layer| crate::runtime::overlay::opening(&ctx, layer)),
|
||||
};
|
||||
if opening && comp.scroll().is_none() {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub(crate) use container_open::{opener_open, set_opener_open};
|
||||
pub use host::paint_frame_layers;
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) use host::remembered_pointer;
|
||||
pub(crate) use host::{Layer, forget_layer, host, host_window, layer_viewport};
|
||||
pub(crate) use host::{Layer, forget_layer, host, host_window};
|
||||
pub(crate) use opener::{LayerFloor, anchor_floor};
|
||||
pub use opener::{Opener, Trigger};
|
||||
pub use place::{Anchor, FloatPlace, OverlayFit, Place, Resize, ResizeEdges, SizeLimits, ViewportShare};
|
||||
|
||||
@@ -81,27 +81,20 @@ pub(super) fn dismissal(
|
||||
/// own pass decides: a layer that closes on outside presses closes on one in the opener outside it and its anchor
|
||||
/// (absorbed or not, as its rule says), and on one in any other window of the app; a popup also closes once the app
|
||||
/// has no focus. An absorbing layer can't keep a press in another OS window from reaching that window. A press recorded
|
||||
/// in the pass the layer appears in is not outside it: it was made before the layer opened. That pass is the popup
|
||||
/// window's, read as `pass` before it ran, and not an earlier pass of the frame.
|
||||
pub(super) fn popup_dismissal(
|
||||
ctx: &Context,
|
||||
layer: &Layer<'_>,
|
||||
rect: Rect,
|
||||
anchor: Rect,
|
||||
popup: egui::ViewportId,
|
||||
pass: u64,
|
||||
appears: bool,
|
||||
) -> Option<CloseReason> {
|
||||
/// in the pass the layer appears in is not outside it: it was made before the layer opened.
|
||||
pub(super) fn popup_dismissal(ctx: &Context, layer: &Layer<'_>, rect: Rect, anchor: Rect, popup: egui::ViewportId) -> Option<CloseReason> {
|
||||
let here = match layer.overlay.dismiss.outside {
|
||||
Outside::Keep => return None,
|
||||
// A layer that appears in this pass opened after the press was made, so the press is not outside it, as in
|
||||
// `dismissal`: the pass that shows the layer is the popup window's, which runs inside this one, and its first
|
||||
// appearance is read by that pass's number, not by the frame's.
|
||||
Outside::Absorb => overlay::absorbed_press(ctx).is_some() && !overlay::appeared_in_pass(ctx, popup, layer.id, pass),
|
||||
// `dismissal`. Its host recorded the appearance in this viewport (`note_appeared`) before the popup window's
|
||||
// pass, nested in this one, showed it: `opening` reads this pass, not the frame, so a press a later pass of the
|
||||
// frame takes still closes it.
|
||||
Outside::Absorb => overlay::absorbed_press(ctx).is_some() && !overlay::opening(ctx, layer.id),
|
||||
Outside::Close => press_outside(ctx, layer, rect, anchor),
|
||||
};
|
||||
let away = layer.overlay.rank == Rank::Popup && crate::runtime::windows::app_away(ctx);
|
||||
(here || away || crate::runtime::windows::pressed_elsewhere(ctx, popup, appears)).then_some(CloseReason::Outside)
|
||||
let appeared = overlay::appeared_this_frame(ctx, layer.id);
|
||||
(here || away || crate::runtime::windows::pressed_elsewhere(ctx, popup, appeared)).then_some(CloseReason::Outside)
|
||||
}
|
||||
|
||||
/// Whether a primary press landed outside the layer, its anchor and the layers opened from inside it. A press the
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::runtime::motion::{self, Driver};
|
||||
use crate::runtime::overlay::{self, Backdrop, CloseReason, OpenEntry, Rank};
|
||||
use crate::runtime::windows::{self, PopupOpen, PopupRoom, WindowSpec};
|
||||
use craft_behavior::{MotionKind, Playback};
|
||||
use egui::{Context, Id, Pos2, Rect, Ui, Vec2, ViewportId};
|
||||
use egui::{Context, Id, Pos2, Rect, Ui, Vec2};
|
||||
|
||||
/// What the host reads for one layer.
|
||||
pub(crate) struct Layer<'a> {
|
||||
@@ -80,6 +80,27 @@ fn recall(layer: &Layer<'_>, ctx: &Context) -> LayerMemory {
|
||||
MemoryStage::peek::<LayerMemory>(ctx, memory_slot(layer.id))
|
||||
}
|
||||
|
||||
/// What the layer remembers as its host's pass starts. A layer that `appears` starts with nothing it remembered while
|
||||
/// shown before, also when it opens again during its exit fade or its host never saw it hide: the focus that was inside
|
||||
/// it does not close it as `focus_left`. A right-click on a context opener while its layer is open hangs the layer at
|
||||
/// the new pointer.
|
||||
fn recall_shown(layer: &Layer<'_>, ctx: &Context, appears: bool) -> LayerMemory {
|
||||
if appears {
|
||||
return LayerMemory::default();
|
||||
}
|
||||
let mut memory = recall(layer, ctx);
|
||||
let pointed = layer
|
||||
.overlay
|
||||
.opener
|
||||
.as_ref()
|
||||
.is_some_and(|first| first.all().any(|opener| opener.fired && opener.trigger == Trigger::Context && opener.opening == Opening::Pointer));
|
||||
if pointed {
|
||||
memory.opening = None;
|
||||
memory.pointer_at = None;
|
||||
}
|
||||
memory
|
||||
}
|
||||
|
||||
fn remember(layer: &Layer<'_>, ctx: &Context, memory: LayerMemory) {
|
||||
let mut stage = MemoryStage::open_owned(ctx, memory_slot(layer.id), layer.owner);
|
||||
*stage.shown::<LayerMemory>(memory_slot(layer.id)) = memory;
|
||||
@@ -115,32 +136,6 @@ fn area_id(id: Id) -> Id {
|
||||
sub(id, "area")
|
||||
}
|
||||
|
||||
/// The viewport whose pass shows the layer `id` of `overlay`, opened in the running viewport: the popup window's when
|
||||
/// it shows there ([`host_in_popup`]), else the running one. That pass is where the layer is stamped
|
||||
/// (`overlay::begin_layer`), and where a body's read step and the host read what it appeared and remembers.
|
||||
pub(crate) fn layer_viewport(ctx: &Context, overlay: &Overlay, id: Id) -> ViewportId {
|
||||
if !overlay.is_full_window() && windows::popup_room(ctx).is_some() {
|
||||
crate::runtime::egui::viewports::viewport_id(id)
|
||||
} else {
|
||||
crate::runtime::egui::pass::current_viewport(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
/// A right-click on a context opener while its layer is open hangs the layer at the new pointer: what the layer
|
||||
/// remembered of the pass it appeared in (how its opener opened it, and the pointer it hung from) is dropped, so both
|
||||
/// are taken again in this pass.
|
||||
fn reanchor(layer: &Layer<'_>, memory: &mut LayerMemory) {
|
||||
let pointed = layer
|
||||
.overlay
|
||||
.opener
|
||||
.as_ref()
|
||||
.is_some_and(|first| first.all().any(|opener| opener.fired && opener.trigger == Trigger::Context && opener.opening == Opening::Pointer));
|
||||
if pointed {
|
||||
memory.opening = None;
|
||||
memory.pointer_at = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// The overlay host: shows `body` on an egui layer for `layer` and decides its dismissal. A layer opened in a palette
|
||||
/// window shows in a popup window of its own ([`host_in_popup`]); a full-window layer covers its own window.
|
||||
pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut Ui)) -> LayerOut {
|
||||
@@ -149,11 +144,8 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
{
|
||||
return host_in_popup(ctx, layer, popup, body);
|
||||
}
|
||||
// A layer that appears starts with nothing it remembered while shown before, also when it opens again during its
|
||||
// exit fade or its host never saw it hide: the focus that was inside it does not close it as `focus_left`.
|
||||
let appears = overlay::appears(ctx, layer.id, layer.exiting);
|
||||
let mut memory = if appears { LayerMemory::default() } else { recall(layer, ctx) };
|
||||
reanchor(layer, &mut memory);
|
||||
let mut memory = recall_shown(layer, ctx, appears);
|
||||
let opened = opened_overlay(ctx, layer.overlay, memory.opening);
|
||||
if let Some((_, opening)) = &opened {
|
||||
memory.opening.get_or_insert(*opening);
|
||||
@@ -308,13 +300,8 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
/// laid out in the popup's pass first, in the room its unplaced form has, and placed by the size it took there.
|
||||
/// A popup that takes keys (a menu, a flyout) takes the OS focus; a tooltip takes none and lets the pointer through.
|
||||
fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut dyn FnMut(&mut Ui)) -> LayerOut {
|
||||
// The layer's body runs in the popup window's pass, which stamps the layer's appearance in that window's record:
|
||||
// this pass, which decides the window, reads it there. The opener's own record never holds the layer, so a layer
|
||||
// that appeared once would read as appearing in every pass.
|
||||
let viewport = layer_viewport(ctx, layer.overlay, layer.id);
|
||||
let appears = overlay::appears_in(ctx, viewport, layer.id, layer.exiting);
|
||||
let mut memory = if appears { LayerMemory::default() } else { recall(layer, ctx) };
|
||||
reanchor(layer, &mut memory);
|
||||
let appears = overlay::note_appeared(ctx, layer.id, layer.exiting);
|
||||
let mut memory = recall_shown(layer, ctx, appears);
|
||||
let opened = opened_overlay(ctx, layer.overlay, memory.opening);
|
||||
if let Some((_, opening)) = &opened {
|
||||
memory.opening.get_or_insert(*opening);
|
||||
@@ -340,10 +327,6 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut
|
||||
let spec = WindowSpec::popup().takes_focus(!tooltip && (scope.is_some() || overlay.rank.takes_keys())).passes_pointer(tooltip);
|
||||
let known = measured.map(|size| Rect::from_min_size(unplaced.at, size));
|
||||
let open = PopupOpen { id: layer.id, spec: &spec, rect: known.map(|rect| rect.translate(popup.origin.to_vec2())) };
|
||||
// The popup's pass runs nested in this one and its begin pass stamps a layer's first appearance with its own
|
||||
// number: read that number before the pass runs, so this pass tells a layer appearing in it from one that appeared
|
||||
// in an earlier pass of the frame.
|
||||
let popup_pass = crate::runtime::egui::pass::pass_nr(ctx, viewport);
|
||||
let mut shown = None;
|
||||
windows::show_popup(ctx, &open, |ui| {
|
||||
let at = unplaced.at.to_vec2();
|
||||
@@ -368,7 +351,8 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut
|
||||
entry.window = true;
|
||||
entry.popup = true;
|
||||
overlay::record(ctx, entry);
|
||||
let dismissed = if layer.exiting { None } else { dismissed.or_else(|| popup_dismissal(ctx, layer, rect, anchor, viewport, popup_pass, appears)) };
|
||||
let viewport = crate::runtime::egui::viewports::viewport_id(layer.id);
|
||||
let dismissed = if layer.exiting { None } else { dismissed.or_else(|| popup_dismissal(ctx, layer, rect, anchor, viewport)) };
|
||||
close_family(ctx, layer, layer.exiting || dismissed.is_some(), &mut memory);
|
||||
remember(layer, ctx, memory);
|
||||
LayerOut { dismissed }
|
||||
|
||||
@@ -83,8 +83,8 @@ pub(crate) fn note_pass_end(ctx: &Context) {
|
||||
/// ending viewport's, or forgets that viewport's update while AccessKit is off.
|
||||
pub(crate) fn settle_output(ctx: &Context, output: &mut egui::FullOutput) {
|
||||
settle_focus(output);
|
||||
// A closed window never runs again to replace or drop its entry, so the frame's end hook prunes the store to the
|
||||
// viewports that are open.
|
||||
// A closed window never runs again to replace or drop its entry, so the begin hook prunes the store to the viewports
|
||||
// that are open as a frame begins.
|
||||
crate::runtime::frame::register_prune(ctx, std::any::TypeId::of::<Settled>(), prune_settled);
|
||||
let update = output.platform_output.accesskit_update.clone();
|
||||
memory::with::<Settled, _>(ctx, |settled| {
|
||||
|
||||
@@ -39,11 +39,17 @@ pub(crate) fn content_rect(ctx: &Context) -> egui::Rect {
|
||||
ctx.content_rect()
|
||||
}
|
||||
|
||||
/// The viewports egui reports for the running pass.
|
||||
/// The viewports egui reports for the running pass: the windows open when its frame began, so one that opens in the
|
||||
/// frame joins the list in the next, and one that closes in it leaves it there.
|
||||
pub(crate) fn live_viewports(ctx: &Context) -> Vec<ViewportId> {
|
||||
ctx.input(|input| input.raw.viewports.keys().copied().collect())
|
||||
}
|
||||
|
||||
/// Whether the running pass is the first of its frame: not one that repeats a discarded pass.
|
||||
pub(crate) fn first_of_frame(ctx: &Context) -> bool {
|
||||
ctx.current_pass_index() == 0
|
||||
}
|
||||
|
||||
/// The pass's time in seconds.
|
||||
pub(crate) fn now(ctx: &Context) -> f64 {
|
||||
ctx.input(|input| input.time)
|
||||
|
||||
@@ -69,7 +69,7 @@ pub(crate) fn request_discard(ctx: &Context, rerun: Rerun) {
|
||||
/// Why the running pass runs again: `None` in a frame's first pass, else the reasons the discarded pass asked for
|
||||
/// (empty when egui discarded it on its own).
|
||||
pub(crate) fn rerun_reasons(ctx: &Context) -> Option<Vec<Rerun>> {
|
||||
if ctx.current_pass_index() == 0 {
|
||||
if super::pass::first_of_frame(ctx) {
|
||||
return None;
|
||||
}
|
||||
let (id, pass) = (asked_id(ctx), running_pass(ctx));
|
||||
|
||||
@@ -34,9 +34,10 @@ pub struct FrameInput {
|
||||
pub latched: Mods,
|
||||
/// The window in which the app's own egui code shows a modal this frame (a dialog the app draws itself, not a
|
||||
/// framework layer). It blocks the app's other windows as a framework app-modal layer open in it does: their
|
||||
/// presses, keys, wheel and text go nowhere, a press there brings the modal's window forward, and they refuse to
|
||||
/// close. A panel floated into a window of its own is one of them. `None` (the default) when the app shows no such
|
||||
/// modal; set every frame from the app's own state.
|
||||
/// presses, keys, wheel and text go nowhere, a press there brings the modal's window forward, they refuse to close,
|
||||
/// and the modal's window takes the keyboard if one of them has it when the modal opens. A panel floated into a
|
||||
/// window of its own is one of them. `None` (the default) when the app shows no such modal; set every frame from
|
||||
/// the app's own state.
|
||||
pub app_modal: Option<ViewportId>,
|
||||
/// Whether the window system's input reaches the OS windows the runtime hosts.
|
||||
pub window_input: WindowInput,
|
||||
@@ -175,6 +176,8 @@ pub struct FrameOutput {
|
||||
#[derive(Default)]
|
||||
pub(crate) struct FrameState {
|
||||
input: Option<FrameInput>,
|
||||
/// The root pass number when `set_input` was last called, so test drivers know whether a frame's input is set.
|
||||
input_pass: Option<u64>,
|
||||
/// The window of `FrameInput::app_modal` and the root frame its modal first showed in: its place in the modal stack
|
||||
/// (`overlay::modal_viewport`). It stays while the app names the same window frame after frame.
|
||||
app_modal: Option<(ViewportId, u64)>,
|
||||
@@ -190,6 +193,7 @@ pub(crate) struct FrameState {
|
||||
passes_open: u32,
|
||||
/// How many root-viewport passes the begin hook has run for: egui counts a pass when it ends.
|
||||
root_passes_hooked: u64,
|
||||
/// What drops the records of closed viewports as a frame begins.
|
||||
prunes: HashMap<TypeId, fn(&Context, &[ViewportId])>,
|
||||
sweeps: HashMap<TypeId, fn(&Context)>,
|
||||
/// What a layer above the runtime reads at the begin hook, after the pointer snapshot and before any component runs.
|
||||
@@ -219,8 +223,8 @@ struct PendingToggle {
|
||||
/// How many passes a shell has to take its toggle before the toggle is dropped.
|
||||
const TOGGLE_PASSES: u64 = 2;
|
||||
|
||||
/// Records of one runtime service, one per viewport. A viewport egui stops reporting has its record dropped
|
||||
/// at once, by the frame loop's end hook.
|
||||
/// Records of one runtime service, one per viewport, kept from the viewport's first pass until it closes: the root's
|
||||
/// begin hook drops the records of the viewports egui no longer reports as a frame begins.
|
||||
#[doc(hidden)]
|
||||
pub struct PerViewport<T> {
|
||||
/// One or two entries: a linear search beats hashing.
|
||||
@@ -374,13 +378,25 @@ impl<T: Stored> PerViewport<Stamped<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers the end hook's prune of a service's per-viewport records, once per service type.
|
||||
/// Registers the prune of a service's per-viewport records to the open viewports ([`prune_closed`]), once per service
|
||||
/// type.
|
||||
pub(crate) fn register_prune(ctx: &Context, key: TypeId, prune: fn(&Context, &[ViewportId])) {
|
||||
pass_state::with::<FrameState, _>(ctx, |state| {
|
||||
state.prunes.entry(key).or_insert(prune);
|
||||
});
|
||||
}
|
||||
|
||||
/// Drops the records of the viewports that have closed, at the start of a frame. A pass's list of viewports dates from
|
||||
/// the start of its frame, so only there does it name every viewport with a record that is still open: later in the
|
||||
/// frame it lacks the ones the frame opened.
|
||||
fn prune_closed(ctx: &Context) {
|
||||
let live = pass::live_viewports(ctx);
|
||||
let prunes: Vec<fn(&Context, &[ViewportId])> = pass_state::with::<FrameState, _>(ctx, |state| state.prunes.values().copied().collect());
|
||||
for prune in prunes {
|
||||
prune(ctx, &live);
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers a sweep the end hook runs for the running viewport's pass, once per service type.
|
||||
pub(crate) fn register_end_sweep(ctx: &Context, key: TypeId, sweep: fn(&Context)) {
|
||||
pass_state::with::<FrameState, _>(ctx, |state| {
|
||||
@@ -413,6 +429,7 @@ pub fn set_input(ctx: &Context, input: FrameInput) {
|
||||
(viewport, _) => viewport.map(|viewport| (viewport, pass::root_frame_nr(ctx))),
|
||||
};
|
||||
state.input = Some(input);
|
||||
state.input_pass = Some(root_passes);
|
||||
ran
|
||||
});
|
||||
commands::set_input(ctx, &commands);
|
||||
@@ -422,6 +439,14 @@ pub fn set_input(ctx: &Context, input: FrameInput) {
|
||||
scale::set_interface_scale(ctx, scale.0);
|
||||
}
|
||||
|
||||
/// Whether [`set_input`] has already run for the upcoming root pass.
|
||||
#[cfg(feature = "testing")]
|
||||
#[doc(hidden)]
|
||||
pub fn input_pending(ctx: &Context) -> bool {
|
||||
let root_passes = pass::pass_nr(ctx, ViewportId::ROOT);
|
||||
pass_state::with::<FrameState, _>(ctx, |state| state.input_pass == Some(root_passes))
|
||||
}
|
||||
|
||||
/// The tokens the app's `sizes` give the default density: the built-in sets and the overrides apply in
|
||||
/// `craft_theme`'s resolve, whichever theme carries them.
|
||||
fn resolved_default(sizes: &AppSizes) -> craft_theme::Tokens {
|
||||
@@ -822,6 +847,9 @@ pub(crate) fn begin_pass(ui: &mut Ui) {
|
||||
running.push(RunningPass { ctx: ctx.clone(), facts: PassFacts { viewport, pass_nr, frame_nr, now, elapsed } });
|
||||
});
|
||||
pass_state::hold(&ctx);
|
||||
if root_pass.is_some() && pass::first_of_frame(&ctx) {
|
||||
prune_closed(&ctx);
|
||||
}
|
||||
if cancelled {
|
||||
raw_input::stop_dragging(&ctx);
|
||||
}
|
||||
@@ -885,14 +913,7 @@ pub(crate) fn end_pass(ui: &mut Ui) {
|
||||
motion::end_pass(&ctx);
|
||||
windows::end(&ctx);
|
||||
ime::end_pass(&ctx);
|
||||
let live = pass::live_viewports(&ctx);
|
||||
let prunes: Vec<fn(&Context, &[ViewportId])> = pass_state::with::<FrameState, _>(&ctx, |state| {
|
||||
state.passes_open = state.passes_open.saturating_sub(1);
|
||||
state.prunes.values().copied().collect()
|
||||
});
|
||||
for prune in prunes {
|
||||
prune(&ctx, &live);
|
||||
}
|
||||
pass_state::with::<FrameState, _>(&ctx, |state| state.passes_open = state.passes_open.saturating_sub(1));
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::egui::access::check_parents_acyclic(&ctx);
|
||||
RUNNING.with(|running| {
|
||||
|
||||
@@ -314,7 +314,8 @@ pub(crate) struct Persist {
|
||||
popup_over_modal: bool,
|
||||
/// The layers that first showed while the primary button was held, until that press ends.
|
||||
held_open: IdSet,
|
||||
/// The root frame and pass each shown layer first ran its body in; gone with the layer's last entry.
|
||||
/// The root frame and pass each shown layer first ran its body in, and for a layer of this window that shows in a
|
||||
/// popup window of its own, the pass it first asked for it in; gone with the layer's last entry.
|
||||
appeared: IdMap<(u64, u64)>,
|
||||
/// The roots whose asked raise ran in a pass where a floating window (re)appeared: egui raises every layer that
|
||||
/// shows again, and its area order keeps the old order among the layers raised in one pass, so the raise is asked
|
||||
@@ -553,19 +554,29 @@ fn reopened(ctx: &Context, id: Id, exiting: bool) -> bool {
|
||||
!exiting && with_pass(ctx, |pass| pass.last.iter().any(|entry| entry.id == id && entry.exiting))
|
||||
}
|
||||
|
||||
/// Whether the layer `id` appears in this pass, read before its `begin_layer`: it was hidden in the last pass, or it
|
||||
/// Whether the layer `id` appears in this pass, read before its `note_appeared`: it was hidden in the last pass, or it
|
||||
/// faded out and is open again. What the layer remembers starts fresh then; a discard pass that repeats the frame
|
||||
/// keeps what the first pass of the frame recorded.
|
||||
pub(crate) fn appears(ctx: &Context, id: Id, exiting: bool) -> bool {
|
||||
appears_in(ctx, pass::current_viewport(ctx), id, exiting)
|
||||
reopened(ctx, id, exiting) || with_persist(ctx, pass::current_viewport(ctx), |persist| !persist.appeared.contains_key(&id))
|
||||
}
|
||||
|
||||
/// Whether the layer `id` appears in [`begin_layer`]'s pass of `viewport`, read before it: a layer shown in a popup
|
||||
/// window is stamped there, by the popup's own pass, so its host reads that viewport's record rather than its opener's,
|
||||
/// which stamps nothing for it. A layer that faded out is seen in the stack of the running pass, whose host shows the
|
||||
/// window that decides it.
|
||||
pub(crate) fn appears_in(ctx: &Context, viewport: ViewportId, id: Id, exiting: bool) -> bool {
|
||||
reopened(ctx, id, exiting) || with_persist(ctx, viewport, |persist| !persist.appeared.contains_key(&id))
|
||||
/// Records that the layer `id` shows in the running viewport in this pass; returns whether it appears in it
|
||||
/// ([`appears`]). A layer shown in a popup window is recorded in its opener's viewport too, where its host runs.
|
||||
pub(crate) fn note_appeared(ctx: &Context, id: Id, exiting: bool) -> bool {
|
||||
let appears = appears(ctx, id, exiting);
|
||||
if appears {
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let first = (pass::root_frame_nr(ctx), pass::pass_nr(ctx, viewport));
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.insert(id, first));
|
||||
}
|
||||
appears
|
||||
}
|
||||
|
||||
/// Whether the layer `id` first showed in the running viewport in this root frame, in any of its passes.
|
||||
pub(crate) fn appeared_this_frame(ctx: &Context, id: Id) -> bool {
|
||||
let now = pass::root_frame_nr(ctx);
|
||||
with_persist(ctx, pass::current_viewport(ctx), |persist| persist.appeared.get(&id).is_some_and(|(frame, _)| *frame == now))
|
||||
}
|
||||
|
||||
/// Marks the layer `id`'s body as running, so layers opened from inside it become its children, with the `side` of
|
||||
@@ -573,7 +584,7 @@ pub(crate) fn appears_in(ctx: &Context, viewport: ViewportId, id: Id, exiting: b
|
||||
pub(crate) fn begin_layer(ctx: &Context, id: Id, tier: Tier, exiting: bool, side: Option<Side>) {
|
||||
// Which layers a press opened reads the presses and releases.
|
||||
crate::runtime::replay::note_input(ctx, crate::runtime::inputs::Input::Press);
|
||||
let reopened = reopened(ctx, id, exiting);
|
||||
let new = note_appeared(ctx, id, exiting);
|
||||
with_pass(ctx, |pass| {
|
||||
pass.drawing.push((id, tier));
|
||||
pass.exiting.push(exiting);
|
||||
@@ -581,19 +592,11 @@ pub(crate) fn begin_layer(ctx: &Context, id: Id, tier: Tier, exiting: bool, side
|
||||
pass.sides.push((id, side));
|
||||
}
|
||||
});
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let first = (pass::root_frame_nr(ctx), pass::pass_nr(ctx, viewport));
|
||||
let (down, released) = pointer::with_pass_raw(ctx, |read| {
|
||||
let released = read.frame.as_ref().filter(|frame| frame.release == Some(craft_behavior::PointerButton::Primary)).map(|frame| frame.pos);
|
||||
(read.primary_down, released)
|
||||
});
|
||||
let release = with_persist(ctx, viewport, |persist| {
|
||||
let new = reopened || !persist.appeared.contains_key(&id);
|
||||
if reopened {
|
||||
persist.appeared.insert(id, first);
|
||||
} else {
|
||||
persist.appeared.entry(id).or_insert(first);
|
||||
}
|
||||
let release = with_persist(ctx, pass::current_viewport(ctx), |persist| {
|
||||
if exiting {
|
||||
return None;
|
||||
}
|
||||
@@ -625,17 +628,6 @@ pub fn opening(ctx: &Context, id: Id) -> bool {
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.get(&id) == Some(&now))
|
||||
}
|
||||
|
||||
/// Whether the layer `id` first ran its body in the pass `pass` of the popup window `viewport`, in the running frame: a
|
||||
/// layer shown in a popup window appears in the popup's pass, which runs inside its opener's, so the opener's pass reads
|
||||
/// it once that pass ended, where [`opening`] reads the layer's own. `pass_nr` of a passed viewport names the pass after
|
||||
/// the one that showed the layer, but the opener's pass reads the popup's number before it runs, which is the number the
|
||||
/// popup's begin pass stamps the layer with: the two numbers name one pass, so a layer that appeared in an earlier pass of
|
||||
/// the same frame (a discard) is not one that appears in this one.
|
||||
pub(crate) fn appeared_in_pass(ctx: &Context, viewport: ViewportId, id: Id, pass: u64) -> bool {
|
||||
let now = (pass::root_frame_nr(ctx), pass);
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.get(&id) == Some(&now))
|
||||
}
|
||||
|
||||
/// Queues a close of every layer opened from inside the layer `id`, so the open state of a popup in its body does
|
||||
/// not outlive it. The closes are carried: with no motion the layer's body hides in the same frame, so the owner of
|
||||
/// a popup in it runs again only when the layer reopens, and takes the close then.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use crate::runtime::cursor;
|
||||
use crate::runtime::egui::input::{self as raw_input, RawInput};
|
||||
use crate::runtime::egui::{injected, pass, viewports};
|
||||
use crate::runtime::egui::{injected, pass, repaint, viewports};
|
||||
use crate::runtime::frame::PerViewport;
|
||||
use crate::runtime::ime;
|
||||
use crate::runtime::overlay;
|
||||
@@ -56,6 +56,11 @@ pub(crate) use viewport::{PopupOpen, ViewportOpen, close_popup, place_popup, sho
|
||||
/// Seconds between writes of a changed placement store.
|
||||
const FLUSH_SECONDS: f64 = 1.0;
|
||||
|
||||
/// Seconds after an app-modal layer opens until its window takes the keyboard from a window it blocks: an OS dialog
|
||||
/// the app opens with the modal (a file dialog) takes the focus a little later, and a focus request sent before then
|
||||
/// could bring the modal's window over it.
|
||||
const MODAL_FOCUS_WAIT: f64 = 0.2;
|
||||
|
||||
/// Install-time inputs and the cross-window records of one context.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Shared {
|
||||
@@ -93,6 +98,8 @@ pub(crate) struct Shared {
|
||||
lowered: bool,
|
||||
/// Where the raise of the modal's window above the palettes it lowered stands.
|
||||
raise: Raise,
|
||||
/// The pass time at which the modal's window takes the keyboard from a window it blocks, until then.
|
||||
modal_focus: Option<f64>,
|
||||
/// Whether the root window showed an app-modal or popup layer in the last root pass: palette windows are hidden
|
||||
/// meanwhile, and one that opens meanwhile opens hidden.
|
||||
palettes_yield: bool,
|
||||
@@ -522,8 +529,8 @@ pub(crate) fn popup_room(ctx: &Context) -> Option<PopupRoom> {
|
||||
Some(PopupRoom { origin, room })
|
||||
}
|
||||
|
||||
/// Whether a primary press landed, in this root frame (or in the last one, unless the popup window `popup` just
|
||||
/// `appeared`), in a window of the app other than the running viewport (the popup's opener, whose own presses its
|
||||
/// Whether a primary press landed, in this root frame (or in the last one, unless the popup window `popup` `appeared`
|
||||
/// in this one), in a window of the app other than the running viewport (the popup's opener, whose own presses its
|
||||
/// layer stack judges) and the popup window and the popup windows opened from it.
|
||||
pub(crate) fn pressed_elsewhere(ctx: &Context, popup: ViewportId, appeared: bool) -> bool {
|
||||
let opener = pass::current_viewport(ctx);
|
||||
@@ -533,18 +540,23 @@ pub(crate) fn pressed_elsewhere(ctx: &Context, popup: ViewportId, appeared: bool
|
||||
if viewport == opener {
|
||||
return false;
|
||||
}
|
||||
// A press in a popup window opened from the popup, at any depth, is inside its family.
|
||||
let mut at = Some(viewport);
|
||||
while let Some(window) = at {
|
||||
if window == popup {
|
||||
return false;
|
||||
}
|
||||
at = PerViewport::<Record>::with_existing(ctx, window, |record| record.opener).flatten();
|
||||
}
|
||||
true
|
||||
// A press in a popup window opened from the popup is inside its family.
|
||||
!in_family(ctx, viewport, popup)
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether `viewport`'s window is `window` or a popup window opened from it, at any depth.
|
||||
fn in_family(ctx: &Context, viewport: ViewportId, window: ViewportId) -> bool {
|
||||
let mut at = Some(viewport);
|
||||
while let Some(shown) = at {
|
||||
if shown == window {
|
||||
return true;
|
||||
}
|
||||
at = PerViewport::<Record>::with_existing(ctx, shown, |record| record.opener).flatten();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Whether no window of the app has focus, as the last frame's windows reported.
|
||||
pub(crate) fn app_away(ctx: &Context) -> bool {
|
||||
shared(ctx, |shared| shared.app.away)
|
||||
@@ -674,6 +686,8 @@ fn flush_store(ctx: &Context) {
|
||||
/// window reports focus: the batch that took focus from one window gave it to no other.
|
||||
///
|
||||
/// Once a palette has stood lowered under an app-modal layer, the modal's window is raised above it, once per modal.
|
||||
/// A window that has the keyboard when a modal comes to block it drops the keys the modal needs, so the modal's window
|
||||
/// takes the keyboard from it ([`focus_modal`]).
|
||||
fn follow_activity(ctx: &Context) {
|
||||
let windows = viewports::reported(ctx);
|
||||
let focused: Vec<ViewportId> = windows
|
||||
@@ -683,13 +697,18 @@ fn follow_activity(ctx: &Context) {
|
||||
.collect();
|
||||
let modal = overlay::app_modal_viewport(ctx);
|
||||
let minimized = viewports::current(ctx).minimized;
|
||||
let now = pass::now(ctx);
|
||||
let (repaint, raise) = shared(ctx, |shared| {
|
||||
shared.stacking.retain(|viewport| windows.iter().any(|(open, _)| open == viewport) && !focused.contains(viewport));
|
||||
shared.stacking.extend(&focused);
|
||||
let app = AppState { away: focused.is_empty(), modal, minimized };
|
||||
let lowered = std::mem::take(&mut shared.lowered);
|
||||
let modal_changed = app.modal != shared.app.modal;
|
||||
if modal_changed {
|
||||
shared.modal_focus = app.modal.map(|_| now + MODAL_FOCUS_WAIT);
|
||||
}
|
||||
let (step, raise) = match shared.raise {
|
||||
_ if app.modal != shared.app.modal => (Raise::Waiting, None),
|
||||
_ if modal_changed => (Raise::Waiting, None),
|
||||
Raise::Waiting if lowered => (Raise::Due, None),
|
||||
Raise::Due => (Raise::Done, app.modal),
|
||||
step => (step, None),
|
||||
@@ -701,11 +720,36 @@ fn follow_activity(ctx: &Context) {
|
||||
if let Some(modal) = raise {
|
||||
act(ctx, modal, WindowAction::Raise);
|
||||
}
|
||||
if let Some(modal) = modal {
|
||||
focus_modal(ctx, modal, &windows);
|
||||
}
|
||||
if repaint {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives the window of `modal`, the app's top modal, the OS focus when one of `windows` that it blocks still has it
|
||||
/// [`MODAL_FOCUS_WAIT`] after the modal opened; once per modal. With the focus elsewhere by then (in the modal's own
|
||||
/// window, in an OS dialog, in another app) nothing is sent.
|
||||
fn focus_modal(ctx: &Context, modal: ViewportId, windows: &[(ViewportId, viewports::Facts)]) {
|
||||
let Some(due) = shared(ctx, |shared| shared.modal_focus) else { return };
|
||||
let blocked = |viewport: ViewportId| overlay::modal_viewport(ctx, viewport) == Some(modal) && !in_family(ctx, viewport, modal);
|
||||
let wait = due - pass::now(ctx);
|
||||
if wait > 0.0 {
|
||||
if windows.iter().any(|(viewport, _)| blocked(*viewport)) {
|
||||
repaint::request_after(ctx, ViewportId::ROOT, wait);
|
||||
}
|
||||
return;
|
||||
}
|
||||
shared(ctx, |shared| shared.modal_focus = None);
|
||||
let focused = |viewport: ViewportId| {
|
||||
PerViewport::<Record>::with_existing(ctx, viewport, |record| record.facts.is_some_and(|facts| facts.focus_reported)).unwrap_or(false)
|
||||
};
|
||||
if !focused(modal) && windows.iter().any(|(viewport, _)| focused(*viewport) && blocked(*viewport)) {
|
||||
act(ctx, modal, WindowAction::Focus);
|
||||
}
|
||||
}
|
||||
|
||||
/// Records whether the root window shows an app-modal or popup layer: palette windows hide meanwhile, so a click on a
|
||||
/// palette cannot bring it over the layer, and the palettes' mounts hide and show them as they do for the app's state
|
||||
/// ([`show_viewport`]), asked for by a repaint when it changes. Runs at the end of the root pass, where the
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
//! `runtime::windows`: the input hook per viewport, window info per viewport, the press release after an OS
|
||||
//! resize (H4), the raise of a modal's window, the mount of a full-window container (in a window of its own, or in a
|
||||
//! full-screen or Wayland-maximized main window), the size of a content-sized window, the app id of child windows, a
|
||||
//! palette's level under a modal and its visibility while the main window is minimized, a layer shown in a popup
|
||||
//! window and what it remembers while it shows (a scrolled body's offset, a context opener clicked again), injected
|
||||
//! keys across a focus loss, non-finite injected points, a
|
||||
//! repeated injected press, the window that has the keys, a wheel with no known pointer, the placement of a minimized
|
||||
//! window, the root frame decided again, a held close, `act`, and a hosted window's Control-click and window-input
|
||||
//! policy.
|
||||
//! `runtime::windows`: the input hook per viewport, window info per viewport, the press release after an OS resize
|
||||
//! (H4), the raise of a modal's window and the keyboard it takes from a window it blocks, the mount of a full-window
|
||||
//! container (in a window of its own, or in a full-screen or Wayland-maximized main window), the size of a
|
||||
//! content-sized window, the app id of child windows, a palette's level under a modal and its visibility while the main
|
||||
//! window is minimized, injected keys across a focus loss, non-finite injected points, a repeated injected press, the
|
||||
//! window that has the keys, a wheel with no known pointer, what a layer in a popup window keeps while it is open, the
|
||||
//! placement of a minimized window, the root frame decided again, a held close, `act`, and a hosted window's
|
||||
//! Control-click and window-input policy.
|
||||
|
||||
use craft_behavior::{Cursor, CursorIcon, PointerButton, Sense};
|
||||
use craft_host::target::{Backend, Caps, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind};
|
||||
use craft_keymap::{Key, Mods};
|
||||
use craft_ui::contract::{
|
||||
Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Dismiss, Mount, Overlay, Props as _, Role, Show as _, ShowContainer as _,
|
||||
Trigger,
|
||||
};
|
||||
use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Scroll, Show as _, ShowContainer as _};
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::focus::FocusPolicy;
|
||||
use craft_ui::runtime::overlay::CloseReason;
|
||||
use craft_ui::runtime::windows::{WindowHost, WindowLevel, WindowSpec};
|
||||
use craft_ui::style::StyleCx;
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::layout::Block;
|
||||
use craft_ui::testing::pointer::{moved, press, release, secondary, wheel};
|
||||
use craft_ui::testing::pointer::{moved, press, release, wheel};
|
||||
use craft_ui::testing::windows::{FakeSystem, NoWindows};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui_test_kit::contract::{PlainStyle, Probe, Seen};
|
||||
@@ -334,6 +329,216 @@ fn an_app_modal_in_one_window_blocks_the_cursor_and_the_close_of_the_others() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Window facts with the focus as given, at a place the window system tells.
|
||||
fn focus(on: bool) -> ViewportInfo {
|
||||
ViewportInfo { focused: Some(on), inner_rect: Some(Rect::from_min_size(Pos2::ZERO, Vec2::splat(300.0))), ..ViewportInfo::default() }
|
||||
}
|
||||
|
||||
fn on_x11() -> Windows {
|
||||
Windows::with(InstallSpec::new(ShellInfo::default().backend(Backend::X11), Arc::new(FakeSystem::new())))
|
||||
}
|
||||
|
||||
/// How many focus requests `out` sent to `viewport`.
|
||||
fn focus_requests(out: &Out, viewport: ViewportId) -> usize {
|
||||
out.commands.iter().filter(|(id, command)| *id == viewport && *command == ViewportCommand::Focus).count()
|
||||
}
|
||||
|
||||
/// Frames that last longer than a modal's window waits before it takes the keyboard.
|
||||
const PAST_THE_WAIT: usize = 40;
|
||||
|
||||
/// The app's own modal that opens while a window it blocks has the keyboard (a command typed in a floated panel opens
|
||||
/// the save prompt in the main window) gets the keys it needs: its window takes the OS focus from the blocked one,
|
||||
/// once, and the wait before it wakes an idle app. Nothing is sent when no blocked window has the focus by then (an OS
|
||||
/// dialog that opened with the modal took it, or the modal's window has it) or the modal closed meanwhile.
|
||||
#[trial]
|
||||
fn an_app_modal_takes_the_keyboard_from_a_window_it_blocks() {
|
||||
// The frames after the modal opens in which the main window, which shows it, got a focus request, with the main
|
||||
// window and a child window focused as given and `before` run before each frame.
|
||||
let requests = |root: bool, float: bool, before: &dyn Fn(&Windows, usize)| -> Vec<usize> {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(root));
|
||||
windows.child_info(focus(float));
|
||||
let frame = || windows.frame(vec![], vec![], |ui| ui.ctx().show_viewport_immediate(child(), ViewportBuilder::default(), |_, _| {}));
|
||||
for _ in 0..4 {
|
||||
frame();
|
||||
}
|
||||
windows.app_modal(Some(ViewportId::ROOT));
|
||||
(0..PAST_THE_WAIT)
|
||||
.flat_map(|at| {
|
||||
before(&windows, at);
|
||||
vec![at; focus_requests(&frame(), ViewportId::ROOT)]
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let none: [usize; 0] = [];
|
||||
let sent = requests(false, true, &|_, _| {});
|
||||
let &[handed] = sent.as_slice() else { panic!("the main window takes the keyboard from the float once: {sent:?}") };
|
||||
assert!(handed > 1, "not before an OS dialog that opens with the modal could take it: frame {handed}");
|
||||
let closes = |windows: &Windows, at| {
|
||||
if at == handed {
|
||||
windows.app_modal(None);
|
||||
}
|
||||
};
|
||||
assert_eq!(requests(false, true, &closes), none, "the modal closed meanwhile");
|
||||
let os_dialog = |windows: &Windows, at| {
|
||||
if at == 1 {
|
||||
windows.child_info(focus(false));
|
||||
}
|
||||
};
|
||||
assert_eq!(requests(false, true, &os_dialog), none, "an OS dialog took the focus");
|
||||
assert_eq!(requests(false, false, &|_, _| {}), none, "no window of the app has the focus");
|
||||
assert_eq!(requests(true, false, &|_, _| {}), none, "the modal's window has the focus");
|
||||
|
||||
let woken = Arc::new(Mutex::new(false));
|
||||
let settled = |windows: &Windows, at| {
|
||||
if at == 2 {
|
||||
let woken = woken.clone();
|
||||
windows.ctx.set_request_repaint_callback(move |info| *woken.lock().unwrap() |= !info.delay.is_zero());
|
||||
}
|
||||
};
|
||||
requests(false, true, &settled);
|
||||
assert!(*woken.lock().unwrap(), "an idle app wakes for the hand-over");
|
||||
}
|
||||
|
||||
/// A framework modal in a window of its own takes the keyboard from the main window it blocks.
|
||||
#[trial]
|
||||
fn a_framework_modal_takes_the_keyboard_from_the_window_it_blocks() {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(true));
|
||||
windows.child_info(focus(false));
|
||||
let sent: usize = (0..PAST_THE_WAIT).map(|_| focus_requests(&modal_frame(&windows), child())).sum();
|
||||
assert_eq!(sent, 1, "once");
|
||||
}
|
||||
|
||||
/// A menu's layer hung from a place near its window's corner: opened in a palette it shows in a popup window.
|
||||
fn menu_layer() -> ContainerProps {
|
||||
use craft_behavior::overlay::{Align, Side};
|
||||
use craft_ui::contract::overlay::{Anchor, Place};
|
||||
let anchor = Rect::from_min_size(Pos2::new(20.0, 20.0), Vec2::splat(10.0));
|
||||
ContainerProps::new().mount(Mount::Layer(Overlay::menu().place(Place::anchored(Anchor::Rect(anchor), Side::Below, Align::Start))))
|
||||
}
|
||||
|
||||
/// The popup window `out` shows beside the main window and `palette`.
|
||||
fn popup_window(out: &Out, palette: ViewportId) -> Option<ViewportId> {
|
||||
out.builders.iter().map(|(id, _)| *id).find(|id| ![ViewportId::ROOT, palette].contains(id))
|
||||
}
|
||||
|
||||
/// A popup window opened from the window that shows the app's modal keeps the keyboard.
|
||||
#[trial]
|
||||
fn a_popup_window_of_the_modals_window_keeps_the_keyboard() {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(false));
|
||||
windows.child_info(focus(true));
|
||||
let open = Cell::new(false);
|
||||
let frame = || {
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
if open.get() {
|
||||
Modal { common: Common::new(), props: menu_layer() }.id_salt("popup").show(ui, |_, _| {});
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
let palette = builder_titled(&frame(), "tool").0;
|
||||
windows.app_modal(Some(palette));
|
||||
open.set(true);
|
||||
frame();
|
||||
windows.child_info(focus(false));
|
||||
let outs: Vec<Out> = (0..PAST_THE_WAIT).map(|_| frame()).collect();
|
||||
let popup = outs.last().and_then(|out| popup_window(out, palette)).expect("the layer opened in the palette shows in a popup window");
|
||||
assert_eq!(windows.facts(popup).focused, Some(true), "the popup window has the keyboard");
|
||||
assert_eq!(outs.iter().map(|out| focus_requests(out, palette)).sum::<usize>(), 0, "the modal's window leaves it there");
|
||||
}
|
||||
|
||||
/// A layer in a popup window keeps the scroll that a focus move below its view gave it while it is open, and starts at
|
||||
/// the top when it opens again.
|
||||
#[trial]
|
||||
fn a_layer_in_a_popup_window_keeps_its_scroll_until_it_closes() {
|
||||
use craft_ui::runtime::focus::{FocusTarget, request};
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(true));
|
||||
windows.child_info(focus(true));
|
||||
let (open, reveal, top) = (Cell::new(false), Cell::new(false), Cell::new(0.0));
|
||||
let (tall, last) = (RefCell::new(Seen::default()), RefCell::new(Seen::default()));
|
||||
let frame = || {
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
if open.get() {
|
||||
let props = menu_layer().scroll(Scroll::vertical());
|
||||
Modal { common: Common::new(), props }.id_salt("popup").show(ui, |ui, _| {
|
||||
if !craft_ui::testing::is_measuring(ui.ctx()) {
|
||||
top.set(ui.next_widget_position().y);
|
||||
}
|
||||
Probe::new(&tall).id_salt("tall").size(Vec2::new(100.0, 2000.0)).show(ui);
|
||||
Probe::new(&last).id_salt("last").show(ui);
|
||||
if let Some(id) = last.borrow().id.filter(|_| reveal.take()) {
|
||||
request(ui.ctx(), FocusTarget::Id(id));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
let settled = || {
|
||||
let mut out = frame();
|
||||
for _ in 1..PAST_THE_WAIT {
|
||||
out = frame();
|
||||
}
|
||||
out
|
||||
};
|
||||
let palette = builder_titled(&frame(), "tool").0;
|
||||
open.set(true);
|
||||
assert!(popup_window(&settled(), palette).is_some(), "the layer opened in the palette shows in a popup window");
|
||||
let start = top.get();
|
||||
reveal.set(true);
|
||||
settled();
|
||||
let scrolled = top.get();
|
||||
assert!(scrolled < start - 1.0, "the layer stays scrolled: its content starts at {scrolled}, {start} unscrolled");
|
||||
open.set(false);
|
||||
assert_eq!(popup_window(&settled(), palette), None, "the layer closed");
|
||||
open.set(true);
|
||||
settled();
|
||||
assert!((top.get() - start).abs() < 0.5, "opened again, it starts at the top: {} after {scrolled}, {start} unscrolled", top.get());
|
||||
}
|
||||
|
||||
/// A popup that a press in another window of the app opened stays open, also when its opener runs a second pass of the
|
||||
/// frame it opens in, and a later press there closes it.
|
||||
#[trial]
|
||||
fn a_popup_window_stays_after_the_press_in_another_window_that_opened_it() {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(true));
|
||||
windows.child_info(focus(true));
|
||||
let (open, again, closed) = (Cell::new(false), Cell::new(false), RefCell::new(Vec::new()));
|
||||
let frame = |root: Vec<Event>| {
|
||||
windows.frame(root, vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
if open.get() {
|
||||
Capture { common: Common::new(), props: menu_layer(), closed: &closed }.id_salt("popup").show(ui, |_, _| {});
|
||||
if again.take() {
|
||||
craft_ui::runtime::frame::discard_pass(ui.ctx(), "test");
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
let at = Pos2::new(250.0, 250.0);
|
||||
frame(vec![]);
|
||||
let out = frame(vec![moved(at)]);
|
||||
let palette = builder_titled(&out, "tool").0;
|
||||
frame(vec![press(at), release(at)]);
|
||||
open.set(true);
|
||||
again.set(true);
|
||||
let mut out = frame(vec![]);
|
||||
for _ in 0..4 {
|
||||
out = frame(vec![]);
|
||||
}
|
||||
assert!(!again.get() && popup_window(&out, palette).is_some(), "the popup opened, its opener's pass repeated");
|
||||
assert_eq!(*closed.borrow(), [], "the press that opened it leaves it open");
|
||||
frame(vec![press(at), release(at)]);
|
||||
frame(vec![]);
|
||||
assert_eq!(closed.borrow().first(), Some(&CloseReason::Outside), "a later press in the main window closes it");
|
||||
}
|
||||
|
||||
/// A window that a modal in another window blocks takes no wheel, as it takes no press or key: what is under the
|
||||
/// pointer there does not scroll.
|
||||
#[trial]
|
||||
@@ -1306,260 +1511,38 @@ fn a_palette_hides_while_the_root_shows_a_modal_or_popup_and_returns_when_it_clo
|
||||
assert_eq!(back, Some(true), "the palette returns once the modal closed");
|
||||
}
|
||||
|
||||
/// A layer mounted with `props`, its open state in the caller's binding, recording the closes it is given.
|
||||
#[derive(craft_ui::contract::Component)]
|
||||
#[component(container)]
|
||||
struct Sheet<'a> {
|
||||
#[common]
|
||||
common: Common,
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
open: Bind<'a, bool>,
|
||||
closed: &'a RefCell<Vec<CloseReason>>,
|
||||
}
|
||||
|
||||
impl Component for Sheet<'_> {
|
||||
const ROLE: Role = Role::GROUP;
|
||||
type Style = PlainStyle;
|
||||
type Output = Response;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: SheetStyleKey) -> PlainStyle {
|
||||
PlainStyle::min(Vec2::new(120.0, 60.0))
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Container for Sheet<'_> {
|
||||
fn open(&mut self) -> Option<BindMut<'_, bool>> {
|
||||
Some(self.open.reborrow())
|
||||
}
|
||||
|
||||
fn closed(&mut self, why: CloseReason) {
|
||||
self.closed.borrow_mut().push(why);
|
||||
}
|
||||
}
|
||||
|
||||
/// The palette window's rect, in desktop points: the room its layers may take.
|
||||
const PALETTE_AT: Rect = Rect { min: Pos2::new(200.0, 150.0), max: Pos2::new(500.0, 350.0) };
|
||||
|
||||
/// One frame of the main window showing a palette-level window whose body shows `overlay`'s layer, the layer's open
|
||||
/// state carried back out to `open`.
|
||||
fn palette_layer_frame(windows: &Windows, overlay: &Overlay, open: &Cell<bool>, closed: &RefCell<Vec<CloseReason>>) -> Out {
|
||||
let mut is_open = open.get();
|
||||
let out = windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
let props = ContainerProps::new().mount(Mount::Layer(overlay.clone()));
|
||||
Sheet { common: Common::new(), props, open: Bind::bound(&mut is_open), closed }.id_salt("sheet").show(ui, |_, _| {});
|
||||
});
|
||||
});
|
||||
open.set(is_open);
|
||||
out
|
||||
}
|
||||
|
||||
/// A layer shown in a popup window of a palette window keeps what it remembered while it shows: its timed dismissal
|
||||
/// counts from the pass it appeared, not from the last pass, so it closes after its timeout with no input at all. The
|
||||
/// layer's body runs in the popup's pass, which stamps its appearance in that window's record; its host decides the
|
||||
/// window in the palette's pass, where the opener's record never holds the layer.
|
||||
/// A palette that opens while the palettes still yield to a modal or popup of the root window that has just closed
|
||||
/// opens hidden and appears in the frames after.
|
||||
#[trial]
|
||||
fn a_layer_in_a_popup_window_closes_after_its_timeout() {
|
||||
fn a_palette_opened_as_the_roots_modal_or_popup_closes_appears() {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(ViewportInfo { focused: Some(true), ..ViewportInfo::default() });
|
||||
// The palette's window: a tool window, whose layers show in popup windows of their own.
|
||||
let palette = ViewportInfo {
|
||||
focused: Some(true),
|
||||
inner_rect: Some(PALETTE_AT),
|
||||
outer_rect: Some(PALETTE_AT),
|
||||
native_pixels_per_point: Some(1.0),
|
||||
..ViewportInfo::default()
|
||||
};
|
||||
windows.child_info(palette);
|
||||
// A menu that closes by itself a quarter second after it appears: fifteen frames at the kit's sixty a second.
|
||||
const TIMEOUT: f32 = 0.25;
|
||||
let overlay = Overlay::menu().dismiss(Dismiss::new().timeout(Some(TIMEOUT)));
|
||||
let open = Cell::new(true);
|
||||
let closed = RefCell::new(Vec::new());
|
||||
let mut out = palette_layer_frame(&windows, &overlay, &open, &closed);
|
||||
for _ in 0..2 {
|
||||
out = palette_layer_frame(&windows, &overlay, &open, &closed);
|
||||
}
|
||||
let shown: Vec<ViewportId> = out.builders.iter().map(|(viewport, _)| *viewport).filter(|viewport| *viewport != ViewportId::ROOT).collect();
|
||||
assert_eq!(shown.len(), 2, "the palette's window and the layer's own popup window: {shown:?}");
|
||||
assert!(open.get(), "the layer is open early in its timeout: {:?}", closed.borrow());
|
||||
// Well past a quarter second of frames, with no input at all.
|
||||
for _ in 0..30 {
|
||||
palette_layer_frame(&windows, &overlay, &open, &closed);
|
||||
}
|
||||
assert!(!open.get(), "the layer closes after its timeout");
|
||||
assert_eq!(*closed.borrow(), [CloseReason::Timeout], "the timeout closed it, and no other rule did");
|
||||
}
|
||||
|
||||
/// A scrolled body of a layer shown in a popup window keeps its offset while the layer shows. The read step that starts
|
||||
/// a layer's body at the top when it opens runs in the opener's pass, before the popup window's pass, which is where the
|
||||
/// layer is stamped: it reads the layer's appearance in that window's record, not in the opener's, which never holds it.
|
||||
#[trial]
|
||||
fn a_scrolled_body_of_a_layer_in_a_popup_window_keeps_its_offset() {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(ViewportInfo { focused: Some(true), ..ViewportInfo::default() });
|
||||
// The palette's window: a tool window, whose layers show in popup windows of their own.
|
||||
let palette = ViewportInfo {
|
||||
focused: Some(true),
|
||||
inner_rect: Some(PALETTE_AT),
|
||||
outer_rect: Some(PALETTE_AT),
|
||||
native_pixels_per_point: Some(1.0),
|
||||
..ViewportInfo::default()
|
||||
};
|
||||
windows.child_info(palette);
|
||||
// A dropdown list, whose body is capped by the room its popup window leaves, holding more than it shows: it scrolls.
|
||||
let overlay = Overlay::dropdown();
|
||||
let owner = egui::Id::unique("a tall body in a popup window");
|
||||
let seen = RefCell::new(Seen::default());
|
||||
let open = Cell::new(true);
|
||||
let closed = RefCell::new(Vec::new());
|
||||
let frame = || {
|
||||
let mut is_open = open.get();
|
||||
let out = windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
let props = ContainerProps::new().mount(Mount::Layer(overlay.clone()));
|
||||
Sheet { common: Common::new(), props, open: Bind::bound(&mut is_open), closed: &closed }.id(owner).show(ui, |ui, _| {
|
||||
for _ in 0..8 {
|
||||
Block::new(Vec2::new(60.0, 40.0)).show(ui);
|
||||
}
|
||||
Probe::new(&seen).id_salt("lowest row").show(ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
open.set(is_open);
|
||||
out
|
||||
};
|
||||
for _ in 0..4 {
|
||||
frame();
|
||||
}
|
||||
let at_top = seen.borrow().rect;
|
||||
assert!(at_top.height() > 0.0, "the layer's body laid its content out: {at_top:?}");
|
||||
// Show the lowest row, which lies below the room the popup window leaves.
|
||||
craft_ui::testing::contract::queue_reveal(&windows.ctx, owner, at_top);
|
||||
frame();
|
||||
frame();
|
||||
let scrolled = seen.borrow().rect;
|
||||
assert!(scrolled.min.y < at_top.min.y - 1.0, "the reveal scrolled the body: {at_top:?} then {scrolled:?}");
|
||||
for _ in 0..4 {
|
||||
frame();
|
||||
}
|
||||
assert_eq!(seen.borrow().rect, scrolled, "the offset stays while the layer shows, with no input at all");
|
||||
assert!(closed.borrow().is_empty(), "scrolling the body closed nothing: {:?}", closed.borrow());
|
||||
}
|
||||
|
||||
/// A layer mounted as `props`' layer whose open state is its opener's: a menu a context opener opens, with the body the
|
||||
/// trial gives it and the closes it is given.
|
||||
#[derive(craft_ui::contract::Component)]
|
||||
#[component(container)]
|
||||
struct OpenedMenu<'a> {
|
||||
#[common]
|
||||
common: Common,
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
closed: &'a RefCell<Vec<CloseReason>>,
|
||||
}
|
||||
|
||||
impl Component for OpenedMenu<'_> {
|
||||
const ROLE: Role = Role::GROUP;
|
||||
type Style = PlainStyle;
|
||||
type Output = Response;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: OpenedMenuStyleKey) -> PlainStyle {
|
||||
PlainStyle::min(Vec2::new(80.0, 24.0))
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Container for OpenedMenu<'_> {
|
||||
fn closed(&mut self, why: CloseReason) {
|
||||
self.closed.borrow_mut().push(why);
|
||||
}
|
||||
}
|
||||
|
||||
/// A second right-click on a context opener hangs its menu at the new pointer while the menu stays open, also when the
|
||||
/// menu shows in a popup window of a palette window: the pointer the layer opened at goes when its opener fires again.
|
||||
#[trial]
|
||||
fn a_second_right_click_hangs_a_menu_in_a_popup_window_at_the_new_pointer() {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(ViewportInfo { focused: Some(true), ..ViewportInfo::default() });
|
||||
let palette = ViewportInfo {
|
||||
focused: Some(true),
|
||||
inner_rect: Some(PALETTE_AT),
|
||||
outer_rect: Some(PALETTE_AT),
|
||||
native_pixels_per_point: Some(1.0),
|
||||
..ViewportInfo::default()
|
||||
};
|
||||
windows.child_info(palette);
|
||||
let overlay = Overlay::menu();
|
||||
let opener_at = RefCell::new(Seen::default());
|
||||
let closed = RefCell::new(Vec::new());
|
||||
let frame = |events: Vec<Event>| {
|
||||
windows.frame(vec![], events, |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
let opener = Probe::new(&opener_at).size(Vec2::new(240.0, 140.0)).sense(Sense::CLICK).id_salt("opener").show(ui);
|
||||
let props = ContainerProps::new().mount(Mount::Layer(overlay.clone().opened_by(&opener, Trigger::Context)));
|
||||
OpenedMenu { common: Common::new(), props, closed: &closed }.id_salt("rows").show(ui, |ui, _| {
|
||||
for _ in 0..3 {
|
||||
Block::new(Vec2::new(80.0, 24.0)).show(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
let frame = |modal: bool, palette: bool| {
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
if modal {
|
||||
let props = ContainerProps::new().mount(Mount::Layer(Overlay::modal()));
|
||||
Modal { common: Common::new(), props }.id_salt("modal").show(ui, |_, _| {});
|
||||
}
|
||||
if palette {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |_, _| {});
|
||||
}
|
||||
})
|
||||
};
|
||||
// Where the menu shows: the window of its own that the frame opened besides the palette's.
|
||||
let menu_window = |out: &Out| -> Rect {
|
||||
let (palette, _) = builder_titled(out, "tool");
|
||||
let (viewport, _) = out
|
||||
.builders
|
||||
.iter()
|
||||
.find(|(viewport, _)| *viewport != ViewportId::ROOT && *viewport != palette)
|
||||
.expect("the menu shows in a popup window of the palette's");
|
||||
let facts = windows.facts(*viewport);
|
||||
facts.outer_rect.or(facts.inner_rect).expect("the menu's window is placed")
|
||||
};
|
||||
for _ in 0..2 {
|
||||
frame(vec![]);
|
||||
for _ in 0..3 {
|
||||
frame(true, false);
|
||||
}
|
||||
let at = opener_at.borrow().rect;
|
||||
assert!(at.height() > 0.0, "the opener showed: {at:?}");
|
||||
// Two points well inside the opener, the second above the first where the menu hanging below it does not reach:
|
||||
// the palette's body lies within its window's points, and either way both right-clicks land on the opener.
|
||||
let (first, second) = (at.center() + Vec2::new(0.0, 20.0), at.center() - Vec2::new(30.0, 20.0));
|
||||
// A right-click on the opener opens the menu at that point.
|
||||
frame(vec![moved(first)]);
|
||||
frame(vec![secondary(first, true)]);
|
||||
let mut out = frame(vec![secondary(first, false)]);
|
||||
for _ in 0..2 {
|
||||
out = frame(vec![]);
|
||||
frame(false, false);
|
||||
let out = frame(false, true);
|
||||
let (tool, builder) = builder_titled(&out, "tool");
|
||||
let mut shown = builder.visible != Some(false);
|
||||
assert!(!shown, "it opens hidden while the palettes yield");
|
||||
for out in [out].into_iter().chain((0..3).map(|_| frame(false, true))) {
|
||||
for (id, command) in out.commands {
|
||||
if let (true, ViewportCommand::Visible(visible)) = (id == tool, command) {
|
||||
shown = visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(closed.borrow().is_empty(), "the right-click opened the menu and closed nothing: {:?}", closed.borrow());
|
||||
let opened = menu_window(&out);
|
||||
// A second right-click on the same opener, while the menu is open, hangs the menu at the new pointer.
|
||||
frame(vec![moved(second)]);
|
||||
frame(vec![secondary(second, true)]);
|
||||
let mut out = frame(vec![secondary(second, false)]);
|
||||
for _ in 0..2 {
|
||||
out = frame(vec![]);
|
||||
}
|
||||
// The press lands outside the menu's own rect, so it closes the menu and the release opens it again. The layer shows
|
||||
// in the pass between them (the close is decided after its body ran), so it never shows nothing and keeps what it
|
||||
// remembered: where its opener first hung it. No other rule closed it.
|
||||
assert!(closed.borrow().iter().all(|why| *why == CloseReason::Outside), "only an outside press closed the menu: {:?}", closed.borrow());
|
||||
let after = menu_window(&out);
|
||||
let moved = after.min - opened.min;
|
||||
let pointer = second - first;
|
||||
assert!(
|
||||
(moved - pointer).length() < 1.0,
|
||||
"the menu hangs where the pointer is now: it stood at {opened:?}, stands at {after:?}, and the pointer moved {pointer:?}"
|
||||
);
|
||||
assert!(shown, "it appears once the modal is gone");
|
||||
}
|
||||
|
||||
/// A key automation holds is in `keys::held` while it is held and not after its release.
|
||||
|
||||
@@ -36,6 +36,7 @@ pub(crate) mod workspace_dialogs;
|
||||
|
||||
pub(crate) mod native;
|
||||
pub(crate) mod native_drag;
|
||||
pub(crate) mod native_float;
|
||||
pub(crate) mod panes;
|
||||
|
||||
/// The docking sizes of the default theme with the given divider gap, least pane and strip height.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Native dock windows: when a float gets an OS window, what the dock records when the OS moves it, the OS close, and
|
||||
//! docking the whole window by dragging its title row. A context menu opened in a palette places its popup window as
|
||||
//! it places the menu in the main window.
|
||||
//! it places the menu in the main window; the palette's own menus keep their place and take the arrow keys in theirs.
|
||||
|
||||
use craft_behavior::Intent;
|
||||
use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, Workspace};
|
||||
@@ -17,10 +17,10 @@ use craft_ui::popover::DropVeil;
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::{drag, keys};
|
||||
use craft_ui::testing::access::AccessTree;
|
||||
use craft_ui::testing::access::{AccessTree, focused_key};
|
||||
use craft_ui::testing::focus::key_release;
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::pointer::{moved, press, release, secondary};
|
||||
use craft_ui::testing::pointer::{gone, moved, press, release, secondary};
|
||||
use craft_ui::testing::trial;
|
||||
use craft_ui::testing::windows::{FakeSystem, HeldButtons};
|
||||
use craft_ui::text::NumberField;
|
||||
@@ -1931,3 +1931,77 @@ fn a_context_menu_a_palette_opens_is_not_closed_by_the_press_that_opened_it() {
|
||||
);
|
||||
assert!(!palette_menu_shows(&dock, &out, "Second action"), "and the second menu closed:\n{}", trace.join("\n"));
|
||||
}
|
||||
|
||||
/// Opens the menu a secondary click at `at`, a point of the palette's window, asks for; returns its popup window.
|
||||
fn open_menu(dock: &mut NativeDock, rect: &mut Rect, at: Pos2) -> ViewportId {
|
||||
for events in [vec![moved(at)], vec![secondary(at, true)], vec![secondary(at, false)], vec![], vec![]] {
|
||||
collapsed_frame(dock, &mut Palettes, rect, vec![], events);
|
||||
}
|
||||
let out = collapsed_frame(dock, &mut Palettes, rect, vec![], vec![]);
|
||||
let opened = popups(dock, &out).into_iter().find(|viewport| !tree_of_viewport(&out, *viewport).with_role(Role::MENU).is_empty());
|
||||
opened.expect("the menu shows in a popup window")
|
||||
}
|
||||
|
||||
/// The arrow keys move the focus in a native palette's tab menu, and Enter runs the row they reach: Dock Panel, which
|
||||
/// is not the first row, docks the panel. Opened again after Escape, the menu starts as it opened first.
|
||||
#[trial]
|
||||
fn the_arrow_keys_reach_a_row_of_a_native_palettes_tab_menu() {
|
||||
let mut dock = NativeDock::on(Os::Windows, Arc::new(FakeSystem::new()));
|
||||
let mut at = FLOAT_AT;
|
||||
dock.windows.root_info(scaled(true, MAIN_AT, COLLAPSED_SCALE));
|
||||
dock.windows.child_info(scaled(true, at, COLLAPSED_SCALE));
|
||||
let out = collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], vec![]);
|
||||
let palette = dock.palette.expect("the palette's window opened");
|
||||
let tab = node_rect(tree_of_viewport(&out, palette), PALETTE_TITLE, Role::TAB).expect("the palette shows the panel's tab").center();
|
||||
// A key in the menu's window, and the row focused in the frame after it.
|
||||
let key = |dock: &mut NativeDock, at: &mut Rect, menu: ViewportId, key: Key| -> Option<String> {
|
||||
dock.windows.send(menu, vec![key_press(key, Modifiers::NONE)]);
|
||||
collapsed_frame(dock, &mut Palettes, at, vec![], vec![]);
|
||||
dock.windows.send(menu, vec![key_release(key, Modifiers::NONE)]);
|
||||
collapsed_frame(dock, &mut Palettes, at, vec![], vec![]);
|
||||
let out = collapsed_frame(dock, &mut Palettes, at, vec![], vec![]);
|
||||
let tree = &out.trees.iter().find(|(shown, _)| *shown == menu)?.1;
|
||||
tree.name_of(focused_key(tree)).map(str::to_owned)
|
||||
};
|
||||
let menu = open_menu(&mut dock, &mut at, tab);
|
||||
let first = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
let second = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
assert_ne!(first, second, "the second arrow moves the focus on");
|
||||
key(&mut dock, &mut at, menu, Key::Escape);
|
||||
for _ in 0..30 {
|
||||
collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], vec![]);
|
||||
}
|
||||
let out = collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], vec![]);
|
||||
assert!(!popups(&dock, &out).contains(&menu), "Escape closed the menu");
|
||||
let menu = open_menu(&mut dock, &mut at, tab);
|
||||
let mut row = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
assert_eq!(row, first, "the menu starts at the same row again");
|
||||
for _ in 0..4 {
|
||||
if row.as_deref() == Some("Dock Panel") {
|
||||
break;
|
||||
}
|
||||
row = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
}
|
||||
key(&mut dock, &mut at, menu, Key::Enter);
|
||||
let layout = dock.workspace.layout();
|
||||
assert!(layout.floating.is_empty(), "Enter ran {row:?}, which docks the panel: {layout:?}");
|
||||
}
|
||||
|
||||
/// The menu a secondary click on a native palette's title row hangs at the pointer stays there while the pointer
|
||||
/// leaves the palette for the menu's window and comes back, and hangs at the new place of a second secondary click.
|
||||
#[trial]
|
||||
fn a_native_palettes_title_row_menu_stays_where_it_opened() {
|
||||
let mut dock = NativeDock::on(Os::Windows, Arc::new(FakeSystem::new()));
|
||||
let mut at = FLOAT_AT;
|
||||
dock.windows.root_info(scaled(true, MAIN_AT, COLLAPSED_SCALE));
|
||||
dock.windows.child_info(scaled(true, at, COLLAPSED_SCALE));
|
||||
let menu = open_menu(&mut dock, &mut at, ROW_AT);
|
||||
let opened = window_rect(&dock, menu);
|
||||
for events in [vec![gone()], vec![], vec![moved(ROW_AT + Vec2::new(-60.0, 80.0))], vec![]] {
|
||||
collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], events);
|
||||
assert_eq!(window_rect(&dock, menu), opened, "the menu stays where it opened");
|
||||
}
|
||||
let menu = open_menu(&mut dock, &mut at, ROW_AT - Vec2::new(40.0, 0.0));
|
||||
let moved = window_rect(&dock, menu);
|
||||
assert!(moved.min.x < opened.min.x - 1.0, "it hangs at the second click: {moved:?}, first {opened:?}");
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
//! Float in a docked tab's menu, in a dock that opens its floats in OS windows: the panel's window opens hidden, as the
|
||||
//! palettes yield to the open menu, and shows once the menu is gone.
|
||||
|
||||
use super::Numbered;
|
||||
use craft_behavior::dock::{Layout, Node, Permissions, Workspace};
|
||||
use craft_host::target::{Caps, Os, ShellInfo};
|
||||
use craft_ui::contract::{Bind, BodyCx, Role, Tracked};
|
||||
use craft_ui::docking::{DockConfig, DockPanels};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::testing::access::{AccessTree, focused_key, name};
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::pointer::{moved, press, release, secondary};
|
||||
use craft_ui::testing::trial;
|
||||
use craft_ui::testing::windows::FakeSystem;
|
||||
use craft_ui_test_kit::windows::Windows;
|
||||
use egui::{Event, Key, Modifiers, Pos2, Rect, Ui, ViewportCommand, ViewportId, ViewportInfo};
|
||||
use std::sync::Arc;
|
||||
|
||||
const FLOATED: usize = 1;
|
||||
const LEFT: usize = 2;
|
||||
/// The main window on the desktop.
|
||||
const MAIN_AT: Rect = Rect { min: Pos2::new(100.0, 100.0), max: Pos2::new(900.0, 700.0) };
|
||||
/// Where the OS puts the float's window.
|
||||
const FLOAT_AT: Rect = Rect { min: Pos2::new(200.0, 180.0), max: Pos2::new(440.0, 480.0) };
|
||||
/// The frames a menu's fade or a focus move may take.
|
||||
const SETTLED: usize = 60;
|
||||
|
||||
/// The panel left behind asks for a second pass when it first shows, as egui's own containers do (`Grid`): in the frame
|
||||
/// that opens the other panel's window.
|
||||
struct Panels<'a> {
|
||||
left_shown: &'a mut bool,
|
||||
}
|
||||
|
||||
impl DockPanels<usize> for Panels<'_> {
|
||||
fn body(&mut self, panel: &usize, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
if *panel == LEFT && !std::mem::replace(self.left_shown, true) {
|
||||
ui.ctx().request_discard("the panel left behind shows first");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A dock of one group of two panels, in a host that keeps the workspace and applies the dock's actions after its pass.
|
||||
struct Host {
|
||||
windows: Windows,
|
||||
workspace: Arc<Workspace<usize>>,
|
||||
specs: Tracked<Numbered>,
|
||||
left_shown: bool,
|
||||
/// What the main window's last pass produced.
|
||||
tree: Option<AccessTree>,
|
||||
/// The float's OS window and whether it is visible: as its first builder opened it, then as the commands left it.
|
||||
window: Option<(ViewportId, bool)>,
|
||||
}
|
||||
|
||||
impl Host {
|
||||
fn new() -> Self {
|
||||
let shell = ShellInfo::default().os(Os::Windows).caps(Caps::native(Os::Windows));
|
||||
let windows = Windows::with(InstallSpec::new(shell, Arc::new(FakeSystem::new())));
|
||||
windows.root_info(info(MAIN_AT));
|
||||
windows.child_info(info(FLOAT_AT));
|
||||
let workspace = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(vec![FLOATED, LEFT], 0)), Vec::new())));
|
||||
let mut host = Host { windows, workspace, specs: Tracked::new(Numbered), left_shown: false, tree: None, window: None };
|
||||
for _ in 0..3 {
|
||||
host.frame(vec![]);
|
||||
}
|
||||
host
|
||||
}
|
||||
|
||||
fn frame(&mut self, events: Vec<Event>) {
|
||||
let shown = Arc::clone(&self.workspace);
|
||||
let mut actions = Vec::new();
|
||||
let (specs, left_shown) = (&self.specs, &mut self.left_shown);
|
||||
let out = self.windows.frame(events, vec![], |ui| {
|
||||
let mut panels = Panels { left_shown: &mut *left_shown };
|
||||
actions = DockArea::new("Dock", Bind::given(Arc::clone(&shown)), specs, &mut panels, DockConfig::default()).show(ui).actions;
|
||||
});
|
||||
for action in actions {
|
||||
Arc::make_mut(&mut self.workspace).apply(action, false, |_| Permissions::ALL).expect("the dock's action applies");
|
||||
}
|
||||
if self.window.is_none() {
|
||||
let opened = out.builders.iter().find(|(viewport, _)| *viewport != ViewportId::ROOT);
|
||||
self.window = opened.map(|(viewport, builder)| (*viewport, builder.visible != Some(false)));
|
||||
}
|
||||
for (viewport, command) in &out.commands {
|
||||
if let (ViewportCommand::Visible(visible), Some((window, shown))) = (command, &mut self.window)
|
||||
&& viewport == window
|
||||
{
|
||||
*shown = *visible;
|
||||
}
|
||||
}
|
||||
self.tree = out.trees.into_iter().find(|(viewport, _)| *viewport == ViewportId::ROOT).map(|(_, tree)| tree);
|
||||
}
|
||||
|
||||
fn tree(&self) -> &AccessTree {
|
||||
self.tree.as_ref().expect("the main window ran a pass")
|
||||
}
|
||||
|
||||
/// A frame with `event`, then the frames the app asks for.
|
||||
fn settle(&mut self, event: Event) {
|
||||
self.frame(vec![event]);
|
||||
for _ in 0..SETTLED {
|
||||
if !self.windows.ctx.has_requested_repaint() {
|
||||
return;
|
||||
}
|
||||
self.frame(vec![]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the main window shows the `role` named `name`.
|
||||
fn at(&self, name: &str, role: Role) -> Option<Pos2> {
|
||||
let tree = self.tree();
|
||||
let key = tree.with_role(role).into_iter().find(|key| tree.name_of(*key) == Some(name))?;
|
||||
tree.bounds_of(key).map(|rect| rect.center())
|
||||
}
|
||||
|
||||
fn assert_floats_in_a_shown_window(&self) {
|
||||
let layout = self.workspace.layout();
|
||||
assert!(layout.floating.iter().any(|window| window.contains(&FLOATED)), "the panel floats: {layout:?}");
|
||||
assert!(self.window.is_some_and(|(_, shown)| shown), "its OS window shows: {:?}", self.window);
|
||||
}
|
||||
}
|
||||
|
||||
fn info(rect: Rect) -> ViewportInfo {
|
||||
ViewportInfo {
|
||||
focused: Some(true),
|
||||
inner_rect: Some(rect),
|
||||
outer_rect: Some(rect),
|
||||
native_pixels_per_point: Some(1.0),
|
||||
..ViewportInfo::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Float clicked in the menu a secondary click on the tab opens.
|
||||
#[trial]
|
||||
fn float_in_a_docked_tabs_menu_shows_the_panels_os_window() {
|
||||
let mut host = Host::new();
|
||||
let tab = host.at("Panel 1", Role::TAB).expect("the docked tab shows");
|
||||
for event in [moved(tab), secondary(tab, true), secondary(tab, false)] {
|
||||
host.settle(event);
|
||||
}
|
||||
let row = host.at("Float", Role::MENU_ITEM).expect("the tab menu's Float row");
|
||||
for event in [moved(row), press(row), release(row)] {
|
||||
host.settle(event);
|
||||
}
|
||||
host.assert_floats_in_a_shown_window();
|
||||
}
|
||||
|
||||
/// Float picked with Enter in the menu Shift+F10 opens on the focused tab.
|
||||
#[trial]
|
||||
fn float_in_a_tab_menu_opened_by_the_keyboard_shows_the_panels_os_window() {
|
||||
let mut host = Host::new();
|
||||
host.settle(key_press(Key::Tab, Modifiers::NONE));
|
||||
host.settle(key_press(Key::F10, Modifiers::SHIFT));
|
||||
let rows = host.tree().with_role(Role::MENU_ITEM).len();
|
||||
assert!(rows > 0, "the tab menu opened");
|
||||
for _ in 0..rows {
|
||||
if name(host.tree(), focused_key(host.tree())) == Some("Float") {
|
||||
break;
|
||||
}
|
||||
host.settle(key_press(Key::ArrowDown, Modifiers::NONE));
|
||||
}
|
||||
host.settle(key_press(Key::Enter, Modifiers::NONE));
|
||||
host.assert_floats_in_a_shown_window();
|
||||
}
|
||||
@@ -1,17 +1,20 @@
|
||||
//! An app that drives its own frames hosts the runtime through the `embed` hooks alone.
|
||||
|
||||
use craft_behavior::Intent;
|
||||
use craft_ui::contract::{Bind, Role, ShowContainer as _};
|
||||
use craft_ui::contract::{Bind, Props as _, Role, ShowContainer as _};
|
||||
use craft_ui::dialog::Dialog;
|
||||
use craft_ui::fonts::{I18nScripts, UiFonts};
|
||||
use craft_ui::runtime::commands::{AppCatalog, Binding, CommandDef, CommandInput, FirePhase, Scope};
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::frame::FrameInput;
|
||||
use craft_ui::runtime::keys;
|
||||
use craft_ui::sections::{DialogRole, FooterButton};
|
||||
use craft_ui::shell::DocumentWindow;
|
||||
use craft_ui::shell::embed::{self, CloseDecision};
|
||||
use craft_ui::testing::focus::key_release;
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::{Frames, install_spec, trial};
|
||||
use craft_ui_test_kit::windows::Windows;
|
||||
use egui::{Event, Key, Modifiers};
|
||||
|
||||
/// The app's own state: its dialog's open state and the Escapes it read at window level.
|
||||
@@ -71,3 +74,40 @@ fn an_app_with_its_own_frame_loop_hosts_a_dialog_and_reads_the_escape_no_compone
|
||||
escape(&mut frames, &mut app);
|
||||
assert_eq!(app.window_escapes, 1, "the app reads the Escape no component took");
|
||||
}
|
||||
|
||||
/// A `FrameInput` installed via `embed::before_input` survives `Windows::frame` and reaches a child viewport pass.
|
||||
#[trial]
|
||||
fn before_input_survives_windows_frame_and_reaches_child_viewport() {
|
||||
const CLOSE: &str = "trialEmbed.close";
|
||||
let catalog = AppCatalog::new(
|
||||
vec![CommandDef::new(CLOSE, "Close", Scope::app()).with_default(Binding::parse("Cmd+W").expect("the trial's chord parses"))],
|
||||
1,
|
||||
)
|
||||
.expect("the trial's catalog is valid");
|
||||
let windows = Windows::new();
|
||||
let frame_input = || FrameInput::new(RootEnv::default()).commands(CommandInput::new().catalog(catalog.clone()));
|
||||
let show = |root: Vec<Event>, child: Vec<Event>| {
|
||||
windows.frame(root, child, |ui| {
|
||||
embed::logic(ui.ctx(), || CloseDecision::Close);
|
||||
DocumentWindow::new("Document").id_salt("doc").show(ui, |_, _| {});
|
||||
});
|
||||
};
|
||||
|
||||
embed::before_input(&windows.ctx, |_| frame_input());
|
||||
show(vec![], vec![]);
|
||||
|
||||
embed::before_input(&windows.ctx, |_| frame_input());
|
||||
show(vec![], vec![key_press(Key::W, Modifiers::COMMAND)]);
|
||||
|
||||
let mut fired = Vec::new();
|
||||
embed::before_input(&windows.ctx, |out| {
|
||||
fired = out.fired;
|
||||
frame_input()
|
||||
});
|
||||
show(vec![], vec![key_release(Key::W, Modifiers::COMMAND)]);
|
||||
|
||||
assert!(
|
||||
fired.iter().any(|item| item.command.id == CLOSE && item.phase == FirePhase::Press),
|
||||
"the shortcut installed by embed::before_input must survive Windows::frame and fire in the child viewport; got {fired:?}",
|
||||
);
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
use craft_host::target::ShellInfo;
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::frame::{FrameInput, WindowInput, set_input};
|
||||
use craft_ui::runtime::frame::{FrameInput, WindowInput, input_pending, set_input};
|
||||
use craft_ui::testing::Frames;
|
||||
use craft_ui::testing::access::{AccessTree, tree_of};
|
||||
use craft_ui::testing::windows::FakeSystem;
|
||||
@@ -22,8 +22,9 @@ const ROOT_SIZE: Vec2 = Vec2::new(800.0, 600.0);
|
||||
const CHILD_SIZE: Vec2 = Vec2::new(400.0, 300.0);
|
||||
|
||||
thread_local! {
|
||||
/// The events the next child pass receives (the renderer runs on the trial's thread).
|
||||
static CHILD_EVENTS: RefCell<Vec<Event>> = const { RefCell::new(Vec::new()) };
|
||||
/// The events of the running frame's child passes (the renderer runs on the trial's thread), each for the child it
|
||||
/// is addressed to, or else for the first child pass.
|
||||
static CHILD_EVENTS: RefCell<Vec<(Option<ViewportId>, Event)>> = const { RefCell::new(Vec::new()) };
|
||||
/// The files hovering over and dropped on the child's window in the next child pass.
|
||||
static CHILD_FILES: RefCell<(Vec<HoveredFile>, Vec<String>)> = const { RefCell::new((Vec::new(), Vec::new())) };
|
||||
/// The window facts every child opened from the root reports.
|
||||
@@ -203,7 +204,13 @@ impl egui::DroppedFile for DroppedPath {
|
||||
fn render_child(ctx: &Context, viewport: egui::ImmediateViewport<'_>) {
|
||||
patch_window(viewport.ids, viewport.builder);
|
||||
let mut callback = viewport.viewport_ui_cb;
|
||||
let events = CHILD_EVENTS.with(|events| std::mem::take(&mut *events.borrow_mut()));
|
||||
let this = viewport.ids.this;
|
||||
let events = CHILD_EVENTS.with(|events| {
|
||||
let mut events = events.borrow_mut();
|
||||
let (own, others): (Vec<_>, Vec<_>) = events.drain(..).partition(|(to, _)| to.is_none_or(|to| to == this));
|
||||
*events = others;
|
||||
own.into_iter().map(|(_, event)| event).collect()
|
||||
});
|
||||
let (hovered_files, dropped) = CHILD_FILES.with(|files| std::mem::take(&mut *files.borrow_mut()));
|
||||
let dropped_files = dropped.into_iter().map(|name| Arc::new(DroppedPath(name.into())) as egui::DroppedFileHandle).collect();
|
||||
let mut info = with_facts(viewport.ids.this, |info| info.clone());
|
||||
@@ -380,8 +387,14 @@ impl Windows {
|
||||
*self.root.borrow_mut() = root;
|
||||
}
|
||||
|
||||
/// One frame: `root` events go to the root viewport, `child` events to the child's next pass. Returns the
|
||||
/// window commands of the frame.
|
||||
/// Gives the next frame's pass of the child `viewport` these `events`, as a popup window's, which runs inside its
|
||||
/// opener's pass.
|
||||
pub fn send(&self, viewport: ViewportId, events: Vec<Event>) {
|
||||
CHILD_EVENTS.with(|kept| kept.borrow_mut().extend(events.into_iter().map(|event| (Some(viewport), event))));
|
||||
}
|
||||
|
||||
/// One frame: `root` events go to the root viewport, `child` events to the first child pass, and each other child
|
||||
/// gets the events [`send`](Self::send) gave it. Returns what the frame sent out.
|
||||
pub fn frame(&self, root: Vec<Event>, child: Vec<Event>, ui: impl FnMut(&mut Ui)) -> Out {
|
||||
self.frame_with_files(root, child, FilesOver::Root, Vec::new(), Vec::new(), ui)
|
||||
}
|
||||
@@ -397,7 +410,7 @@ impl Windows {
|
||||
dropped: Vec<String>,
|
||||
ui: impl FnMut(&mut Ui),
|
||||
) -> Out {
|
||||
CHILD_EVENTS.with(|events| *events.borrow_mut() = child);
|
||||
CHILD_EVENTS.with(|events| events.borrow_mut().extend(child.into_iter().map(|event| (None, event))));
|
||||
let ((root_hovered, root_dropped), child_files) = match over {
|
||||
FilesOver::Root => ((hovered, dropped), Default::default()),
|
||||
FilesOver::Child => (Default::default(), (hovered, dropped)),
|
||||
@@ -407,7 +420,9 @@ impl Windows {
|
||||
CHILD_FILES.with(|files| *files.borrow_mut() = child_files);
|
||||
TREES.with(|kept| kept.borrow_mut().clear());
|
||||
SHAPES.with(|kept| kept.borrow_mut().clear());
|
||||
set_input(&self.ctx, FrameInput::new(self.root.borrow().clone()).app_modal(self.app_modal.get()).window_input(self.window_input.get()));
|
||||
if !input_pending(&self.ctx) {
|
||||
set_input(&self.ctx, FrameInput::new(self.root.borrow().clone()).app_modal(self.app_modal.get()).window_input(self.window_input.get()));
|
||||
}
|
||||
let mut input = RawInput {
|
||||
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, ROOT_SIZE)),
|
||||
events: root,
|
||||
@@ -422,6 +437,7 @@ impl Windows {
|
||||
ROOT_INFO.with(|info| *info.borrow_mut() = self.root_info.borrow().clone());
|
||||
input.viewports = all_viewports();
|
||||
let mut output = self.ctx.run_ui(input, ui);
|
||||
CHILD_EVENTS.with(|events| events.borrow_mut().clear());
|
||||
// A child the frame no longer shows has closed: like an integration, the kit drops its window, so later inputs
|
||||
// stop listing it (and what its last pass left, such as a modal, stops counting), and a window opened again
|
||||
// opens anew.
|
||||
|
||||
@@ -100,6 +100,7 @@ pub struct ComboBox<'a> {
|
||||
preview: Preview<String>,
|
||||
/// Whether the combo box sizes to its options alone, as in a toolbar or ribbon.
|
||||
#[style_key]
|
||||
#[prop]
|
||||
compact: bool,
|
||||
}
|
||||
|
||||
@@ -120,13 +121,6 @@ impl<'a> ComboBox<'a> {
|
||||
.label(label)
|
||||
}
|
||||
|
||||
/// Sets whether the combo box sizes to its options alone, as in a toolbar or ribbon.
|
||||
#[must_use]
|
||||
pub fn compact(mut self, compact: bool) -> Self {
|
||||
self.compact = compact;
|
||||
self
|
||||
}
|
||||
|
||||
/// Previews `text`, led by the pointer or by the keys. The pass reports it only when the previewed text changes,
|
||||
/// so a second pass of a frame, which sees the lead its first pass stored, reports nothing.
|
||||
fn show_preview(&mut self, cx: &mut Cx<'_, Self>, text: String, by_pointer: bool) {
|
||||
|
||||
@@ -21,6 +21,8 @@ suite = ["screen-testing", "craft-ui/suite"]
|
||||
# Opt-in migration of first party Flatpak bundles to the ArtCraft OCI remote.
|
||||
oci_migration = []
|
||||
default = []
|
||||
# Developer builds only: downloads from a mirror on loopback, and plain HTTP from remote hosts. No other feature turns it on.
|
||||
local-mirror = []
|
||||
ui = ["dep:egui", "dep:image", "dep:craft-ui", "dep:craft-host", "dep:craft-theme"]
|
||||
# The dialog stories, the updater's test seams and the integration binary `tests/it`.
|
||||
screen-testing = ["ui", "craft-ui/testing"]
|
||||
|
||||
@@ -76,14 +76,14 @@ impl Http {
|
||||
/// `user_agent` names the product and its version (`PhotoCraft/0.9.0`) and nothing about the
|
||||
/// person using it.
|
||||
pub fn new(user_agent: &str) -> Result<Self, String> {
|
||||
Self::build(user_agent)
|
||||
Self::build(user_agent, !cfg!(feature = "local-mirror"))
|
||||
}
|
||||
|
||||
/// The agents for remote hosts, and every redirect they follow, stay on HTTPS in every build:
|
||||
/// `https_only` keeps the agents for remote hosts, and every redirect they follow, on HTTPS:
|
||||
/// a release download that GitHub's file host redirected to `http://` is refused, not read in
|
||||
/// plain text. The `direct` agents only ever fetch `is_loopback` links (a local mirror), which
|
||||
/// are plain HTTP.
|
||||
fn build(user_agent: &str) -> Result<Self, String> {
|
||||
fn build(user_agent: &str, https_only: bool) -> Result<Self, String> {
|
||||
// The OS checks each certificate chain itself: Windows fetches roots it hasn't stored yet
|
||||
// and trusts what antivirus HTTPS scanning installs. Reading the store ourselves missed
|
||||
// both ("invalid peer certificate: UnknownIssuer").
|
||||
@@ -93,7 +93,7 @@ impl Http {
|
||||
let small = ureq::Agent::config_builder()
|
||||
.tls_config(tls())
|
||||
.proxy(proxy.clone())
|
||||
.https_only(true)
|
||||
.https_only(https_only)
|
||||
.timeout_global(Some(Duration::from_secs(20)))
|
||||
.http_status_as_error(false)
|
||||
.user_agent(user_agent)
|
||||
@@ -102,7 +102,7 @@ impl Http {
|
||||
let feed = ureq::Agent::config_builder()
|
||||
.tls_config(tls())
|
||||
.proxy(proxy.clone())
|
||||
.https_only(true)
|
||||
.https_only(https_only)
|
||||
.timeout_connect(Some(Duration::from_secs(5)))
|
||||
.timeout_global(Some(Duration::from_secs(10)))
|
||||
.http_status_as_error(false)
|
||||
@@ -112,7 +112,7 @@ impl Http {
|
||||
let no_redirect = ureq::Agent::config_builder()
|
||||
.tls_config(tls())
|
||||
.proxy(proxy.clone())
|
||||
.https_only(true)
|
||||
.https_only(https_only)
|
||||
.timeout_global(Some(Duration::from_secs(20)))
|
||||
.http_status_as_error(false)
|
||||
.max_redirects(0)
|
||||
@@ -123,7 +123,7 @@ impl Http {
|
||||
let download = ureq::Agent::config_builder()
|
||||
.tls_config(tls())
|
||||
.proxy(proxy.clone())
|
||||
.https_only(true)
|
||||
.https_only(https_only)
|
||||
.timeout_connect(Some(Duration::from_secs(20)))
|
||||
.timeout_recv_response(Some(Duration::from_secs(60)))
|
||||
// ureq has no idle timeout: cap each attempt instead, and resume where it stopped.
|
||||
|
||||
@@ -148,6 +148,34 @@ fn gzip(data: &[u8]) -> Vec<u8> {
|
||||
enc.finish().unwrap()
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_remote_agents_refuse_plain_http_before_connecting() {
|
||||
// ureq checks every hop, redirects included, before it connects; `.invalid` never
|
||||
// resolves, so an agent that tried would fail on DNS instead.
|
||||
let http = Http::build(crate::TEST_AGENT, true).unwrap();
|
||||
let refused = |r: Result<_, String>| r.is_err_and(|e| e.contains("refused plain HTTP to example.invalid") && !e.contains("secret"));
|
||||
assert!(refused(http.get_api("http://example.invalid/repos/x/y/releases?secret", None).map(|_| ())));
|
||||
assert!(refused(http.get_text("http://example.invalid/SHA256SUMS.txt?secret").map(|_| ())));
|
||||
// The scheme is case-insensitive, and an upper-case one isn't a loopback link either.
|
||||
assert!(refused(http.get_text("HTTP://example.invalid/SHA256SUMS.txt").map(|_| ())));
|
||||
assert!(refused(http.get_bytes("http://example.invalid/icon.png", 100).map(|_| ())));
|
||||
assert!(refused(http.redirect_target("http://example.invalid/releases/latest").map(|_| ())));
|
||||
assert!(http.get_feed("http://example.invalid/feed.json").is_err_and(|e| e.why.contains("refused plain HTTP")));
|
||||
// A download fails at once rather than retrying until it pauses.
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, sha) = body();
|
||||
let result = http.download("http://example.invalid/file.bin?secret", &dir.path().join("file.bin"), 10, &sha, &Stop::default(), &mut |_| {});
|
||||
assert_eq!(result.unwrap_err(), "the download led to plain HTTP at example.invalid, so it wasn't fetched");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn https_only_still_reaches_a_loopback_link() {
|
||||
let (body, _) = body();
|
||||
let (url, _) = serve(body.clone(), vec![Reply::Full]);
|
||||
let http = Http::build(crate::TEST_AGENT, true).unwrap();
|
||||
assert_eq!(http.get_bytes(&url, body.len()).unwrap(), Some(body));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_rate_limited_release_check_is_typed_not_english_text() {
|
||||
let http = Http::new(crate::TEST_AGENT).unwrap();
|
||||
|
||||
@@ -232,12 +232,14 @@ pub(crate) fn bind_artifact_version(app: &App, release: &Release, asset: &Asset)
|
||||
/// the download is checked against. A `+` may be written plainly or as `%2B`
|
||||
/// ([`release::same_download_url`]).
|
||||
///
|
||||
/// This crate's tests accept a loopback link as well, as their downloads come from a server on
|
||||
/// 127.0.0.1.
|
||||
/// With this crate's `local-mirror` feature, the developer's loopback mirror is accepted too. The
|
||||
/// consumer confines those links (the launcher's feed parser does) and must turn the feature on
|
||||
/// itself (`craft-update/local-mirror`): its own feature of that name doesn't. This crate's tests
|
||||
/// accept loopback as well, as their downloads come from a server on 127.0.0.1.
|
||||
pub fn check_download_link(app: &App, release: &Release, asset: &Asset) -> Result<(), String> {
|
||||
let repo = if release.repo.is_empty() { app.repo } else { release.repo.as_str() };
|
||||
let own = |a: &Asset| {
|
||||
(cfg!(test) && crate::http::is_loopback(&a.url))
|
||||
(cfg!(any(test, feature = "local-mirror")) && crate::http::is_loopback(&a.url))
|
||||
|| release::expected_download_url(repo, &release.tag, &a.name).is_some_and(|expected| release::same_download_url(&a.url, &expected))
|
||||
};
|
||||
if own(asset) && release.sums_asset().is_none_or(own) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! `Http::new` as an app gets it, through the public API only.
|
||||
//! `Http::new` as an app gets it, through the public API only: the release configuration, or the `local-mirror` one with
|
||||
//! that feature on.
|
||||
|
||||
use craft_ui::testing::trial;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
@@ -30,7 +31,7 @@ fn serve() -> (String, Arc<AtomicUsize>) {
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_remote_agents_refuse_plain_http_and_loopback_links_use_the_direct_agents() {
|
||||
fn the_remote_agents_take_plain_http_only_with_a_local_mirror_and_loopback_links_use_the_direct_agents() {
|
||||
let (base, seen) = serve();
|
||||
let http = Http::new("craft-update-tests/0").unwrap();
|
||||
// A loopback link goes to the direct agents, which serve plain HTTP in every build.
|
||||
@@ -42,6 +43,11 @@ fn the_remote_agents_refuse_plain_http_and_loopback_links_use_the_direct_agents(
|
||||
assert_eq!(seen.load(Ordering::SeqCst), 3);
|
||||
// Any other plain-HTTP link is refused before it connects, in debug builds too. An upper-case scheme isn't a
|
||||
// loopback link, so it goes to a remote agent.
|
||||
assert!(http.get_text(&format!("HTTP{}", &base[4..])).is_err_and(|e| e.contains("refused plain HTTP")));
|
||||
assert_eq!(seen.load(Ordering::SeqCst), 3, "a refused request never connects");
|
||||
let remote = http.get_text(&format!("HTTP{}", &base[4..]));
|
||||
if cfg!(feature = "local-mirror") {
|
||||
assert_eq!(remote.unwrap().as_deref(), Some("{}"));
|
||||
} else {
|
||||
assert!(remote.as_ref().is_err_and(|e| e.contains("refused plain HTTP")), "{remote:?}");
|
||||
assert_eq!(seen.load(Ordering::SeqCst), 3, "a refused request never connects");
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ An app with its own eframe `App` calls the hooks in `craft::ui::shell::embed`. `
|
||||
| Quit | egui's quit shortcuts are cleared. ⌘Q (Ctrl+Q on Windows and Linux) is the default of the command `QuitCommand::Quit` (id `window.quit`), which the runtime runs from any source: it asks the root window to close through the close path below, so the app's close decision asks about unsaved work. It fires with a modal open; the close path then refuses under an app-modal layer. Its default is bound and yielded as F6 is; an app whose own shortcut table reads its quit key from egui unbinds it there. |
|
||||
| Close path | The runtime's window host owns the root window's close request. `embed::logic` asks the app through its closure, then hands the close to the platform quit where there is one (macOS). |
|
||||
| Wheel | `RootEnv::wheel_speed` scales each wheel delta once; a Ctrl or Cmd wheel keeps the device's distance. The install's `WheelModifiers` set egui's zoom and sideways modifiers. On Windows and Linux, a Ctrl+wheel in fractions of a notch (a point-unit one on Linux) is a touchpad pinch and arrives as `Event::Zoom`, at egui's Ctrl-scroll zoom speed: Windows hands a precision touchpad's pinch to apps only that way. Whole notches stay wheel events, except within 0.25 s of a pinch step. An app whose Ctrl+wheel does something else, or zooms at its own rate, sets `RootEnv::ctrl_wheel_pinch(false)` and reads the wheel events itself. |
|
||||
| App modals | A modal the app draws with its own egui code blocks nothing outside egui by itself. While one shows, the app names its window each frame with `FrameInput::app_modal(Some(viewport))`: the app's other windows, panels floated into windows of their own among them, are then blocked as under a framework app-modal layer (their presses, keys, wheel and text are dropped, a press there brings the modal's window forward, and they refuse to close). |
|
||||
| App modals | A modal the app draws with its own egui code blocks nothing outside egui by itself. While one shows, the app names its window each frame with `FrameInput::app_modal(Some(viewport))`: the app's other windows, panels floated into windows of their own among them, are then blocked as under a framework app-modal layer (their presses, keys, wheel and text are dropped, a press there brings the modal's window forward, they refuse to close, and the modal's window takes the keyboard if one of them has it when the modal opens). |
|
||||
| Input pacing | One press per pass: extra presses in one frame wait for the next passes. A press outside an open framework menu closes the menus that were open when it was made; a primary press goes no further, and a secondary or middle press reaches what it lands on, so a right-click opens that part's menu. After an OS resize of the window, the held pointer is released. |
|
||||
|
||||
The window's keys are the ones the runtime routes to no component: an Escape or a plain Enter while nothing has the focus, neither a framework stop nor one of the app's own widgets or popups, and the arrows' nudge. The window's plain Enter also stays in egui's input. `with_window_intents` offers them to its closure while nothing has framework focus. The closure takes what it handles (`Intents::take(Intent::Cancel)`; `Intent` and the other types `Intents` reads are in `ui::runtime::keys`) and returns whether it took anything; the rest stays for later readers. A framework scope that ran earlier in the pass takes them first (an open dialog takes the Escape that closes it), so the app reads them last in its UI to see what no component took. App code that read `Key::Escape`, `Key::Tab`, F6 or F10 from egui while none of its own widgets had focus reads these intents and `FrameOutput::chrome_toggles` instead; its own focused widgets and popups keep reading Escape and the plain Enter from egui (Tab only where the widget keeps it or a popup is open), and no window intent comes of them. An Escape pressed in the OS window of a floated dock panel that nothing there takes, not even a reader of that window's intents, is the Cancel of the window the dock is in, in its next pass, so the app reads it where it reads its own; a popup or a modal open over the panel keeps it, and any other OS window (an app's own viewport, a dialog or document window) keeps its Escape to itself (`WindowSpec::hands_on_cancel`).
|
||||
|
||||
Reference in new issue
Block a user