diff --git a/crates/pdf/tests/interpretation.rs b/crates/pdf/tests/interpretation.rs index 612559266b..233860a3d4 100644 --- a/crates/pdf/tests/interpretation.rs +++ b/crates/pdf/tests/interpretation.rs @@ -41,7 +41,7 @@ mod device { fn clips_of(content: &str) -> ClipDevice { let bytes = format!( - "%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj\n3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 40 20] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >> endobj\n4 0 obj << /Length {} >> stream\n{content}\nendstream endobj\n5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj\ntrailer << /Root 1 0 R >>\n%%EOF", + "%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj\n3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 40 20] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> /XObject << /Square 6 0 R >> >> >> endobj\n4 0 obj << /Length {} >> stream\n{content}\nendstream endobj\n5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj\n6 0 obj << /Type /XObject /Subtype /Form /BBox [0 0 10 10] /Length 14 >> stream\n0 0 10 10 re f\nendstream endobj\ntrailer << /Root 1 0 R >>\n%%EOF", content.len() ); let pdf = craft_pdf::open_slice(bytes.as_bytes(), None).unwrap(); @@ -109,7 +109,7 @@ mod rendered { fn red_share(text: &str) -> f64 { let content = format!("q {text} 1 0 0 rg 0 0 40 20 re f Q"); let bytes = format!( - "%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj\n3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 40 20] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >> endobj\n4 0 obj << /Length {} >> stream\n{content}\nendstream endobj\n5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj\ntrailer << /Root 1 0 R >>\n%%EOF", + "%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj\n3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 40 20] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> /XObject << /Square 6 0 R >> >> >> endobj\n4 0 obj << /Length {} >> stream\n{content}\nendstream endobj\n5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj\n6 0 obj << /Type /XObject /Subtype /Form /BBox [0 0 10 10] /Length 14 >> stream\n0 0 10 10 re f\nendstream endobj\ntrailer << /Root 1 0 R >>\n%%EOF", content.len() ); let pdf = craft_pdf::open_slice(bytes.as_bytes(), None).unwrap(); @@ -120,6 +120,14 @@ mod rendered { red as f64 / pixels.len() as f64 } + #[test] + fn a_form_hidden_by_disjoint_clips_does_not_walk_its_artwork() { + let visible = clips_of("/Square Do"); + assert_eq!(visible.paths, 1); + let after_hidden = clips_of("q 0 0 10 10 re W n 20 0 10 10 re W n /Square Do Q /Square Do"); + assert_eq!(after_hidden.paths, visible.paths); + } + #[test] fn an_empty_text_clip_hides_what_follows_and_a_visible_one_shows_its_glyphs() { assert!(red_share("") > 0.99, "no text object: the fill covers the page"); diff --git a/crates/text/src/ui/character.rs b/crates/text/src/ui/character.rs index ddc879ff40..8f464eeb19 100644 --- a/crates/text/src/ui/character.rs +++ b/crates/text/src/ui/character.rs @@ -248,6 +248,8 @@ const SHIFT_RANGE: RangeInclusive = -1296.0..=1296.0; const TRACKING_RANGE: RangeInclusive = -1000.0..=10000.0; /// The range of the scale fields, percent. const SCALE_RANGE: RangeInclusive = 0.0..=1000.0; +/// Percentage shortcuts shared by the vertical and horizontal scale menus. +const SCALE_PRESETS: [f32; 6] = [50.0, 75.0, 100.0, 125.0, 150.0, 200.0]; /// The rotation presets, degrees. pub const ROTATION_PRESETS: [f32; 9] = [-180.0, -135.0, -90.0, -45.0, 0.0, 45.0, 90.0, 135.0, 180.0]; /// The Insert Aki Left and Right presets, thousandths of an em. @@ -352,9 +354,11 @@ impl Cell { presets: &'static [f32], change: fn(f32) -> CharacterChange| PlainCell { label: label.clone(), mark, value, range, percent, presets, change }; Some(match self { - Cell::VerticalScale => cell(&words.vertical_scale, "↕T", values.vertical_scale, SCALE_RANGE, true, &[], CharacterChange::VerticalScale), + Cell::VerticalScale => { + cell(&words.vertical_scale, "↕T", values.vertical_scale, SCALE_RANGE, true, &SCALE_PRESETS, CharacterChange::VerticalScale) + } Cell::HorizontalScale => { - cell(&words.horizontal_scale, "↔T", values.horizontal_scale, SCALE_RANGE, true, &[], CharacterChange::HorizontalScale) + cell(&words.horizontal_scale, "↔T", values.horizontal_scale, SCALE_RANGE, true, &SCALE_PRESETS, CharacterChange::HorizontalScale) } Cell::Rotation => cell(&words.rotation, "↻", values.rotation, ROTATION_RANGE, false, &ROTATION_PRESETS, CharacterChange::Rotation), Cell::AkiLeft => cell(&words.aki_left, "|A", values.aki_left, AKI_RANGE, false, &AKI_PRESETS, CharacterChange::AkiLeft), diff --git a/crates/text/tests/it/character.rs b/crates/text/tests/it/character.rs index cf7bf67a4c..3766fdc127 100644 --- a/crates/text/tests/it/character.rs +++ b/crates/text/tests/it/character.rs @@ -140,3 +140,27 @@ fn the_digits_select_reports_the_picked_tag() { let picked: Vec = edits.borrow().iter().filter_map(|e| e.value().cloned()).collect(); assert_eq!(picked, vec![CharacterChange::Digits("devanagari".to_owned())]); } + +#[trial] +fn character_scale_menus_apply_the_selected_percentage() { + use craft_text::ui::character::CharacterChange; + use std::{cell::RefCell, rc::Rc}; + + for (label, expected) in + [("Vertical scale", CharacterChange::VerticalScale(125.0)), ("Horizontal scale", CharacterChange::HorizontalScale(125.0))] + { + let picked = Rc::new(RefCell::new(Vec::new())); + let sink = picked.clone(); + let mut fixture = Fixture::new(move |ui| { + let values = CharacterValues { vertical_scale: Some(121.0), horizontal_scale: Some(100.0), ..CharacterValues::default() }; + let out = CharacterControls::new("Character", &values, &[], &[]).show(ui); + sink.borrow_mut().extend(out.edits.iter().filter_map(|event| event.value().cloned())); + }); + fixture.room(vec2(402.0, 800.0)).settle(); + let field = fixture.by_label(label).expect("scale field").rect; + fixture.click_at(egui::pos2(field.right() - 8.0, field.center().y)).settle(); + let row = fixture.texts().iter().find(|run| run.text == "125").expect("125 percent preset").rect; + fixture.click_at(row.center()).settle(); + assert!(picked.borrow().contains(&expected), "{label} applies the selected percentage"); + } +} diff --git a/crates/ui-canvas/src/canvas/pasteboard/mod.rs b/crates/ui-canvas/src/canvas/pasteboard/mod.rs index 07ca5269c5..ce0a256bee 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/mod.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/mod.rs @@ -487,10 +487,13 @@ impl Component for Pasteboard<'_> { let fill = space.pasteboard().fill(); let look = style.surround.shown(cx.env.canvas_pattern()); let surround = || { - for quad in Self::quads(&view, self.pages, self.uncovered).iter().filter(|quad| bounds(quad).intersects(view.rect)) { - match fill { - Some(color) => draw.data_fill(&polygon(quad), color), - None => paint_surround(&edges.painter, CheckerArea::Quad(*quad), &look), + let visible = Self::quads(&view, self.pages, self.uncovered).into_iter().filter(|quad| bounds(quad).intersects(view.rect)); + if let Some(color) = fill { + let pieces: Vec<_> = visible.map(|quad| quad.to_vec()).collect(); + draw.data_fill_tiled(&pieces, color); + } else { + for quad in visible { + paint_surround(&edges.painter, CheckerArea::Quad(quad), &look); } } }; diff --git a/crates/ui-contract/src/contract/overlay/host.rs b/crates/ui-contract/src/contract/overlay/host.rs index dd4aa45443..7c4a32ed9b 100644 --- a/crates/ui-contract/src/contract/overlay/host.rs +++ b/crates/ui-contract/src/contract/overlay/host.rs @@ -185,7 +185,10 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U Backdrop::None => egui::Color32::TRANSPARENT, }; let through = crate::runtime::sampler::through(ctx, crate::runtime::egui::pass::current_viewport(ctx), layer.id); - areas::show_cover_layer(ctx, areas::CoverLayer { id: cover_id, tier, screen: bounds, scrim, through, absorbs: !layer.exiting }); + // Work-area constraints place the dialog. Its modal cover spans the whole + // client region, including the part on a neighbouring monitor. + let screen = layer.region.map_or_else(|| ctx.content_rect(), |region| region.intersect(ctx.content_rect())); + areas::show_cover_layer(ctx, areas::CoverLayer { id: cover_id, tier, screen, scrim, through, absorbs: !layer.exiting }); Some(areas::layer_of(tier, cover_id)) } _ => None, diff --git a/crates/ui-contract/src/primitives/surround.rs b/crates/ui-contract/src/primitives/surround.rs index 65df35a0ab..cd21948fc3 100644 --- a/crates/ui-contract/src/primitives/surround.rs +++ b/crates/ui-contract/src/primitives/surround.rs @@ -21,10 +21,8 @@ pub fn paint_surround(painter: &egui::Painter, area: CheckerArea, look: &Surroun painter.add(Shape::Rect(RectShape::filled(rect, radius, look.fill))); } CheckerArea::Quad(corners) => { - let feather = painter.ctx().tessellation_options(|options| { - if options.feathering { options.feathering_size_in_pixels / painter.pixels_per_point() } else { 0.0 } - }); - let mesh = fill_polygon(&corners, look.fill, feather); + // Adjacent pasteboard quads share their edges. Feathering each exposes the canvas underneath. + let mesh = fill_polygon(&corners, look.fill, 0.0); if !mesh.is_empty() { painter.add(Shape::mesh(mesh)); } diff --git a/crates/ui-contract/src/primitives/textures/mod.rs b/crates/ui-contract/src/primitives/textures/mod.rs index 340bdae793..81ce93137e 100644 --- a/crates/ui-contract/src/primitives/textures/mod.rs +++ b/crates/ui-contract/src/primitives/textures/mod.rs @@ -29,14 +29,42 @@ use egui::{Color32, ColorImage, Context, TextureHandle, TextureId, TextureOption use std::any::TypeId; use std::collections::HashMap; use std::hash::{DefaultHasher, Hash, Hasher}; +use std::sync::Arc; /// One cached texture and the frame that last asked for it. struct Entry { /// `None` for a key whose image had nothing to draw. - handle: Option, + handle: Option>, used: u64, } +/// A replayed mesh refers to its texture by ID. Keep the image alive for the lifetime of the +/// recorded paint, even when new icons evict its entry from the lookup cache. +#[derive(Clone, PartialEq)] +struct RecordedTexture(Arc); + +impl std::fmt::Debug for RecordedTexture { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Debug::fmt(&self.0.id(), f) + } +} + +impl crate::runtime::Shift for RecordedTexture { + fn shifted(&self, _: &egui::RecordShift) -> Self { + self.clone() + } + + fn snapped(&self, _: &Self, _: f32) -> Self { + self.clone() + } +} + +fn texture_id(ctx: &Context, handle: Arc) -> TextureId { + let id = handle.id(); + crate::runtime::replay::journal_distinct(ctx, || RecordedTexture(handle), |_, _| {}); + id +} + /// The textures of one context by key hash. A handle that is dropped frees its texture, so the cache owns them. #[derive(Default)] struct Loaded { @@ -98,19 +126,20 @@ impl TextureCache { let known = memory::with(ctx, |loaded: &mut Loaded| { loaded.handles.get_mut(&hash).map(|entry| { entry.used = frame; - entry.handle.as_ref().map(TextureHandle::id) + entry.handle.clone() }) }); - if let Some(id) = known { - return id; + if let Some(handle) = known { + return handle.map(|handle| texture_id(ctx, handle)); } // The image is built and uploaded outside the service lock: neither calls back into the cache. - let handle = image().map(|image| textures::load(ctx, format!("craft_ui/{hash:016x}"), image, options)); - memory::with(ctx, |loaded: &mut Loaded| { - let id = loaded.handles.entry(hash).or_insert(Entry { handle, used: frame }).handle.as_ref().map(TextureHandle::id); + let handle = image().map(|image| Arc::new(textures::load(ctx, format!("craft_ui/{hash:016x}"), image, options))); + let handle = memory::with(ctx, |loaded: &mut Loaded| { + let handle = loaded.handles.entry(hash).or_insert(Entry { handle, used: frame }).handle.clone(); loaded.evict(frame); - id - }) + handle + }); + handle.map(|handle| texture_id(ctx, handle)) } /// The number of textures the context holds. @@ -128,3 +157,23 @@ impl TextureCache { memory::with(ctx, |loaded: &mut Loaded| loaded.handles.clear()); } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn recorded_icon_texture_survives_cache_eviction_until_the_record_drops() { + let ctx = Context::default(); + let mut output = ctx.run_ui(Default::default(), |ui| { + crate::runtime::replay::open(&ctx); + let id = TextureCache::texture(&ctx, "recorded", || ColorImage::filled([2, 2], Color32::WHITE)); + let record = crate::runtime::replay::close(&ctx, ui.layer_id()); + TextureCache::clear(&ctx); + assert!(ctx.tex_manager().read().meta(id).is_some()); + drop(record); + assert!(ctx.tex_manager().read().meta(id).is_none()); + }); + output.textures_delta.clear(); + } +} diff --git a/crates/ui-contract/src/runtime/egui/areas.rs b/crates/ui-contract/src/runtime/egui/areas.rs index d1d4c46eb9..715f189433 100644 --- a/crates/ui-contract/src/runtime/egui/areas.rs +++ b/crates/ui-contract/src/runtime/egui/areas.rs @@ -433,10 +433,22 @@ pub(crate) fn safe_rect(ctx: &Context) -> Rect { /// `safe_rect` without noting the read: for the root env, which moves `Input::Shell` by it. pub(crate) fn safe_rect_raw(ctx: &Context) -> Rect { let content = ctx.content_rect(); - ctx.input(|input| { + let (size, inner, state) = ctx.input(|input| { let viewport = input.viewport(); - craft_window::desktop::visible_part(content, viewport.monitor_size, viewport.inner_rect, craft_window::desktop::WindowState::of(viewport)) - }) + (viewport.monitor_size, viewport.inner_rect, craft_window::desktop::WindowState::of(viewport)) + }); + if state != craft_window::desktop::WindowState::FullScreen + && let Some(window) = inner + && let Some(visible) = craft_window::desktop::visible_part_on_monitors( + content, + window, + ctx.pixels_per_point(), + &crate::runtime::windows::WindowHost::of(ctx).monitors(), + ) + { + return visible; + } + craft_window::desktop::visible_part(content, size, inner, state) } /// Hands egui the whole layer order of the running pass, bottom first. egui consumes it by the end of the pass. diff --git a/crates/ui-contract/src/runtime/windows/viewport.rs b/crates/ui-contract/src/runtime/windows/viewport.rs index a717ebb6f0..3ccb32dc84 100644 --- a/crates/ui-contract/src/runtime/windows/viewport.rs +++ b/crates/ui-contract/src/runtime/windows/viewport.rs @@ -54,11 +54,20 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im }); let opened = PerViewport::::with(ctx, viewport, |record| record.seen.is_some()); let (size, pos) = saved_geometry(ctx, open, opened).map_or((open.size, None), |(size, pos)| (Some(size), pos)); - let pos = pos.or(open.position); - if opened { - keep_placed(ctx, viewport, pos, size.filter(|_| open.follows_size)); - } let spec = open.spec; + let user_moves_dialog = spec.kind == WindowKind::Dialog && open.position.is_none() && !open.moved_by_app; + let pos = if user_moves_dialog && !opened && base_shell(ctx).window_positions() { + let owner = viewports::current(ctx); + let owner_rect = owner.inner.or(owner.outer); + let display = super::host::monitor_of(ctx, &owner).map(|monitor| monitor.points_at(monitor.scale)); + dialog_position(owner_rect, display, size, pos) + } else { + pos.or(open.position) + }; + if opened { + // A remembered position initializes a dialog once. Sending it back during an OS drag pins the window. + keep_placed(ctx, viewport, pos.filter(|_| !user_moves_dialog), size.filter(|_| open.follows_size)); + } let cancel_to = spec.hands_on_cancel.then(|| crate::runtime::egui::pass::current_viewport(ctx)); let state = shared(ctx, |shared| shared.app); let os = os_of(ctx); @@ -206,6 +215,16 @@ pub(crate) fn close_popup(ctx: &Context, id: Id) { } } +/// On first open put an unplaced dialog on its owner's display and keep its saved spot on that display. +fn dialog_position(owner: Option, display: Option, size: Option, saved: Option) -> Option { + let (Some(owner), Some(size)) = (owner, size) else { return saved }; + if saved.is_some_and(|p| display.is_none_or(|screen| screen.contains(p + size * 0.5))) { + return saved; + } + let at = owner.center() - size * 0.5; + Some(display.map_or(at, |screen| at.clamp(screen.min, screen.min.max(screen.max - size)))) +} + /// Fits saved geometry to the current display layout once, before the viewport opens. fn saved_geometry(ctx: &Context, open: &ViewportOpen<'_>, opened: bool) -> Option<(Vec2, Option)> { let saved = saved_placement(ctx, open.save?)?.repaired()?; @@ -297,3 +316,20 @@ pub(super) fn at_known(ctx: &Context, viewport: ViewportId, facts: viewports::Fa ..facts } } + +#[cfg(test)] +mod dialog_position_tests { + use super::*; + use egui::{pos2, vec2}; + + #[test] + fn a_dialog_opens_on_its_owners_monitor() { + let monitor = Rect::from_min_size(pos2(-1600.0, 0.0), vec2(1600.0, 900.0)); + let owner = Rect::from_min_size(pos2(-1500.0, 80.0), vec2(1000.0, 700.0)); + let size = vec2(600.0, 480.0); + let place = |saved| dialog_position(Some(owner), Some(monitor), Some(size), saved); + assert_eq!(place(None), Some(pos2(-1300.0, 190.0))); + assert_eq!(place(Some(pos2(200.0, 120.0))), place(None)); + assert_eq!(place(Some(pos2(-1500.0, 90.0))), Some(pos2(-1500.0, 90.0))); + } +} diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 1180a9bb08..7f63f288de 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1139,6 +1139,16 @@ fn show_area( edit.push(event); } + // The collapsed column shows the panel named by its flyout binding. Activating a tab in + // the underlying layout alone leaves the flyout displaying the previously opened panel. + if report.flyout.is_empty() + && let (Some(open_panel), Some(picked)) = (&open, &report.picked) + && open_panel != picked + && current.layout().place(open_panel).and_then(|at| current.layout().group(&at)).is_some_and(|group| group.panels.contains(picked)) + { + let label = Arc::from(body.words::().panels.as_str()); + report.flyout.push(EditEvent::set(Mixed::Same(open.clone()), Some(picked.clone()), label, None)); + } let mut shown = open; for event in report.flyout.drain(..) { match flyout.as_mut() { diff --git a/crates/ui-patterns/tests/it/docking/columns.rs b/crates/ui-patterns/tests/it/docking/columns.rs index 21f73452af..db0ce4bc22 100644 --- a/crates/ui-patterns/tests/it/docking/columns.rs +++ b/crates/ui-patterns/tests/it/docking/columns.rs @@ -376,6 +376,36 @@ fn rail_footer_stays_clear_of_icons_on_either_dock_side() { } } +#[trial] +fn clicking_a_tab_in_an_open_flyout_switches_the_bound_panel_and_its_body() { + let side = Column::new(vec![Group::new(vec![10, 11], 0)]).with_iconic(true); + let root = Node::split(Axis::X, SplitSize::Ratio(0.6), Node::tabs(vec![1], 0), Node::dock(DockEdge::End, vec![side])); + let mut workspace = Arc::new(Workspace::new(Layout::new(Some(root), Vec::new()))); + let specs = Tracked::new(Sides); + let opened = Rc::new(Cell::new(Some(10))); + let held = Rc::clone(&opened); + let mut fixture = Fixture::new(move |ui| { + let mut panel = held.get(); + let out = DockArea::new("Flyout dock", Bind::given(Arc::clone(&workspace)), &specs, &mut Sides, DockConfig::default()) + .flyout(Bind::bound(&mut panel)) + .show(ui); + held.set(panel); + for action in out.actions { + drop(Arc::make_mut(&mut workspace).apply(action, false, |_: &u32| Permissions::ALL)); + } + }); + fixture.room(Vec2::new(900.0, 500.0)).settle(); + let tab = fixture + .by_role(Role::TAB) + .into_iter() + .find(|tab| craft_ui::testing::access::name(fixture.tree(), tab.node) == Some("Beta")) + .expect("the neighboring tab is visible") + .rect; + fixture.click_at(tab.center()).settle(); + assert_eq!(opened.get(), Some(11)); + assert!(fixture.by_label("Beta body").is_some()); +} + /// With the rail mode, a click on an icon expands its column with that panel in front, and the icons stay beside /// it, between the panel and the window edge; a click on another icon switches the panel, and a click on the icon of /// the panel in front collapses the column again. diff --git a/crates/window/src/desktop.rs b/crates/window/src/desktop.rs index 938345ac78..34050aa34d 100644 --- a/crates/window/src/desktop.rs +++ b/crates/window/src/desktop.rs @@ -6,7 +6,7 @@ mod work_area; #[cfg(feature = "ui")] -pub use work_area::{TASKBAR, WindowState, fits, visible_part}; +pub use work_area::{TASKBAR, WindowState, fits, visible_part, visible_part_on_monitors}; #[cfg(target_os = "linux")] mod icon_theme; diff --git a/crates/window/src/desktop/work_area.rs b/crates/window/src/desktop/work_area.rs index cd10048e39..79d5e41bb1 100644 --- a/crates/window/src/desktop/work_area.rs +++ b/crates/window/src/desktop/work_area.rs @@ -6,6 +6,7 @@ //! window's content rect then run under the taskbar: [`visible_part`] is the content rect cut to //! the monitor less that room. +use craft_behavior::{Monitor, placement::monitor_of}; use egui::{Rect, Vec2, ViewportInfo, pos2, vec2}; /// Room kept free at the monitor's bottom edge for a taskbar or Dock egui can't see (the Windows @@ -84,6 +85,23 @@ pub fn visible_part(content: Rect, monitor: Option, inner: Option, s trusted(content, usable.translate(shift)) } +/// The visible part when the host knows the actual desktop layout. Monitor positions +/// are in physical pixels, while the window rectangle uses the current UI scale. +pub fn visible_part_on_monitors(content: Rect, inner: Rect, pixels_per_point: f32, monitors: &[Monitor]) -> Option { + if !inner.is_finite() || !pixels_per_point.is_finite() || pixels_per_point <= 0.0 { + return None; + } + let window_px = Rect::from_min_max(inner.min * pixels_per_point, inner.max * pixels_per_point); + let monitor = monitor_of(monitors, window_px)?; + let mut work = monitor.points_at(pixels_per_point); + if let Some(([x, y], [w, h])) = monitor.work_px { + work = Rect::from_min_size(pos2(x as f32, y as f32) / pixels_per_point, vec2(w as f32, h as f32) / pixels_per_point); + } else { + work.max.y -= TASKBAR; + } + Some(trusted(content, work.translate(content.min - inner.min))) +} + /// `content` cut to `usable`, unless that leaves too little to be a sensible guess. fn trusted(content: Rect, usable: Rect) -> Rect { let visible = content.intersect(usable); @@ -120,6 +138,17 @@ mod tests { assert_eq!(visible_part(content, Some(MONITOR), Some(inner), Normal).bottom(), 768.0 - TASKBAR); } + #[test] + fn a_staggered_monitors_window_keeps_its_visible_top_left_corner() { + let m = Monitor::new(craft_behavior::MonitorKey::new("secondary", [1920, 1200]), [1200, 770], [1920, 1200], 1.0) + .with_work_px([1200, 770], [1920, 1156]); + for scale in [1.0, 1.5] { + let content = Rect::from_min_size(pos2(0.0, 0.0), vec2(1920.0, 1156.0) / scale); + let inner = content.translate(vec2(1200.0, 770.0) / scale); + assert_eq!(visible_part_on_monitors(content, inner, scale, std::slice::from_ref(&m)), Some(content)); + } + } + #[test] fn maximized_unknown_or_nonsense_input_keeps_the_window() { let (content, inner) = window(0.0, 0.0, 1440.0, 900.0); diff --git a/vendor/hayro-interpret/src/x_object.rs b/vendor/hayro-interpret/src/x_object.rs index 33d4b0398b..eda6ba26ec 100644 --- a/vendor/hayro-interpret/src/x_object.rs +++ b/vendor/hayro-interpret/src/x_object.rs @@ -157,6 +157,13 @@ fn draw_form_xobject_once<'a, 'b>( return; } + // Disjoint inherited clips leave no painted area. Illustrator can reuse a complete + // artboard in such a clip before drawing the visible copy, including all its nested forms. + if context.bbox().is_empty() { + context.end_nested_interpretation(); + return; + } + let has_oc = xobject_oc(&x_object.dict, context); if !context.ocg_state.is_visible() { if has_oc {