mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 10:48:15 +01:00
Merge commit 'e08876e6469a15bd3e9846846dde7f2621edec07' into fix/vectorcraft-framework-app-main
# Conflicts: # crates/text/tests/it/character.rs
This commit is contained in:
commit
1afc2e1f0a
14 files changed
+243
-30
No files matched your search
@@ -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");
|
||||
|
||||
@@ -248,6 +248,8 @@ const SHIFT_RANGE: RangeInclusive<f64> = -1296.0..=1296.0;
|
||||
const TRACKING_RANGE: RangeInclusive<f64> = -1000.0..=10000.0;
|
||||
/// The range of the scale fields, percent.
|
||||
const SCALE_RANGE: RangeInclusive<f64> = 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),
|
||||
|
||||
@@ -140,3 +140,27 @@ fn the_digits_select_reports_the_picked_tag() {
|
||||
let picked: Vec<CharacterChange> = 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");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<TextureHandle>,
|
||||
handle: Option<Arc<TextureHandle>>,
|
||||
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<TextureHandle>);
|
||||
|
||||
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<TextureHandle>) -> 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();
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -54,11 +54,20 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
});
|
||||
let opened = PerViewport::<Record>::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<Rect>, display: Option<Rect>, size: Option<Vec2>, saved: Option<Pos2>) -> Option<Pos2> {
|
||||
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<Pos2>)> {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
@@ -1139,6 +1139,16 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
|
||||
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::<DockWords>().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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Vec2>, inner: Option<Rect>, 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<Rect> {
|
||||
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);
|
||||
|
||||
+7
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user