mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-19 00:27:49 +00:00
Merge pull request #2133 from TrevorBrown-dev/fix/present-hidpi-detail-2127
Presenter: a tall frame is sharp on HiDPI displays (device-scale texture over the view, #2127)
This commit is contained in:
8 files changed
+367
-7
No files matched your search
@@ -414,6 +414,11 @@ pub fn render_area(doc: &Document, ids: &[NodeId], b: Rect, scale: f64) -> Optio
|
||||
area_at(doc, ids, None, b, scale, 0.0)
|
||||
}
|
||||
|
||||
/// [`render_area`] `time` seconds into animated GIFs (the presenter plays them).
|
||||
pub fn render_area_at(doc: &Document, ids: &[NodeId], b: Rect, scale: f64, time: f64) -> Option<Pixmap> {
|
||||
area_at(doc, ids, None, b, scale, time)
|
||||
}
|
||||
|
||||
/// [`render_area`] for an export of layers that sit among `page_layers` (the page's top-level
|
||||
/// layers, in z-order): a background blur or glass in `ids` reads what lies under the first of
|
||||
/// them on that page, clipped to the area (#2213). Only `ids` are drawn; the layers above stay
|
||||
|
||||
@@ -292,6 +292,9 @@ pub struct Presenter {
|
||||
anim_tex: Option<egui::TextureHandle>,
|
||||
temp: Option<Temp>,
|
||||
textures: HashMap<NodeId, FrameTex>,
|
||||
/// The part of the presented frame in view, drawn at device scale over the (capped) whole-frame
|
||||
/// texture; `bounds` is the page area it covers.
|
||||
detail: Option<(NodeId, FrameTex)>,
|
||||
/// Small current-screen preview in the full-window bar, cached until its content changes.
|
||||
bar_thumb: Option<(NodeId, usize, egui::TextureHandle)>,
|
||||
arrived: f64,
|
||||
@@ -375,6 +378,7 @@ impl Presenter {
|
||||
anim_tex: None,
|
||||
temp: None,
|
||||
textures: HashMap::new(),
|
||||
detail: None,
|
||||
bar_thumb: None,
|
||||
arrived: -1.0,
|
||||
delays_fired: HashSet::new(),
|
||||
|
||||
@@ -255,7 +255,8 @@ impl Presenter {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn texture(&mut self, ctx: &egui::Context, doc: &Document, id: NodeId, px_scale: f64, now: f64) -> Option<FrameTex> {
|
||||
/// Seconds into the frame's animated GIFs, and the frame of them showing (see [`Self::texture`]).
|
||||
fn frame_clock(&self, ctx: &egui::Context, doc: &Document, id: NodeId, now: f64) -> (f64, Option<(u64, f64)>) {
|
||||
// Animated GIFs play from when the frame arrived: a new texture when one of them moves on,
|
||||
// and a wake-up for that moment (nothing else draws frames while it shows). egui wakes a
|
||||
// display frame before the time asked for, a little earlier still at times: ask that much
|
||||
@@ -265,6 +266,54 @@ impl Presenter {
|
||||
if let Some((_, next)) = clock {
|
||||
crate::repaint_in(ctx, next + f64::from(ctx.input(|i| i.predicted_dt)));
|
||||
}
|
||||
(t, clock)
|
||||
}
|
||||
|
||||
/// The part of the frame `id` (its whole texture covering `whole`, page units) in view
|
||||
/// (`visible`) at the full pixel scale `px`, for a frame whose whole texture is capped below it
|
||||
/// (see [`detail_plan`]). While the view moves (`moving`) it only returns a detail already
|
||||
/// rendered, and only while it covers the whole view: past it the capped texture shows alone
|
||||
/// (no sharp edge across the view) until the view settles and a detail for it is rendered.
|
||||
pub(super) fn detail_texture(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
doc: &Document,
|
||||
id: NodeId,
|
||||
px: f64,
|
||||
whole: figcraft_geom::Rect,
|
||||
visible: figcraft_geom::Rect,
|
||||
moving: bool,
|
||||
now: f64,
|
||||
) -> Option<FrameTex> {
|
||||
// Converted back from the screen, the view can stand a rounding error outside the frame,
|
||||
// which a detail (always inside the frame) never covers: a still view would then render a
|
||||
// new detail every frame.
|
||||
let visible = visible.intersect(whole);
|
||||
let (t, clock) = self.frame_clock(ctx, doc, id, now);
|
||||
let key = (self.rev, px.to_bits(), clock.map_or(0, |c| c.0));
|
||||
let covers = |b: &figcraft_geom::Rect| b.x0 <= visible.x0 && b.y0 <= visible.y0 && b.x1 >= visible.x1 && b.y1 >= visible.y1;
|
||||
if let Some((did, d)) = &self.detail
|
||||
&& *did == id
|
||||
&& d.key == key
|
||||
&& covers(&d.bounds)
|
||||
{
|
||||
return Some(d.clone());
|
||||
}
|
||||
if moving {
|
||||
return None;
|
||||
}
|
||||
let side = ctx.input(|i| i.max_texture_side) as f64 - 2.0;
|
||||
let rect = detail_plan(whole, visible, px, side)?;
|
||||
let pix = figcraft_render::render_area_at(doc, &[id], rect, texture_scale_for(rect, px, side), t)?;
|
||||
let img = crate::render_worker::screen_image(&pix, doc.color_profile);
|
||||
let tex = ctx.load_texture(format!("present-detail-{}", id.0), img, egui::TextureOptions::LINEAR);
|
||||
let ft = FrameTex { key, tex, bounds: rect };
|
||||
self.detail = Some((id, ft.clone()));
|
||||
Some(ft)
|
||||
}
|
||||
|
||||
pub(super) fn texture(&mut self, ctx: &egui::Context, doc: &Document, id: NodeId, px_scale: f64, now: f64) -> Option<FrameTex> {
|
||||
let (t, clock) = self.frame_clock(ctx, doc, id, now);
|
||||
let key = (self.rev, px_scale.to_bits(), clock.map_or(0, |c| c.0));
|
||||
if let Some(t) = self.textures.get(&id)
|
||||
&& t.key == key
|
||||
@@ -288,12 +337,41 @@ const MAX_TEXTURE_PIXELS: f64 = 16_777_216.0;
|
||||
/// The pixel scale, at most `px`, at which `bounds` makes a texture the GPU takes (no side past
|
||||
/// its limit) of at most [`MAX_TEXTURE_PIXELS`].
|
||||
pub(super) fn texture_scale(ctx: &egui::Context, bounds: figcraft_geom::Rect, px: f64) -> f64 {
|
||||
let side = ctx.input(|i| i.max_texture_side) as f64 - 2.0;
|
||||
texture_scale_for(bounds, px, ctx.input(|i| i.max_texture_side) as f64 - 2.0)
|
||||
}
|
||||
|
||||
/// [`texture_scale`] for a GPU taking textures up to `side` pixels a side.
|
||||
pub(super) fn texture_scale_for(bounds: figcraft_geom::Rect, px: f64, side: f64) -> f64 {
|
||||
let (w, h) = (bounds.width().max(1.0), bounds.height().max(1.0));
|
||||
let s = px.min(side / w.max(h)).min((MAX_TEXTURE_PIXELS / (w * h)).sqrt());
|
||||
if s.is_finite() && s > 0.0 { s } else { 1e-3 }
|
||||
}
|
||||
|
||||
/// The page area to draw at the full pixel scale `px` over the whole frame's capped texture, when
|
||||
/// that texture is below `px`: the part in `visible` with a margin (a quarter of its size each
|
||||
/// way, shrunk until the area makes a texture the GPU takes), inside `bounds`. `None` when the
|
||||
/// whole frame is already at `px`, or nothing of it is in view. When the view alone is past the
|
||||
/// caps it is returned all the same, and drawn at the scale [`texture_scale_for`] gives it.
|
||||
pub(super) fn detail_plan(bounds: figcraft_geom::Rect, visible: figcraft_geom::Rect, px: f64, side: f64) -> Option<figcraft_geom::Rect> {
|
||||
if texture_scale_for(bounds, px, side) >= px || !(px.is_finite() && px > 0.0) {
|
||||
return None;
|
||||
}
|
||||
let view = visible.intersect(bounds);
|
||||
if !(view.width() > 0.0 && view.height() > 0.0 && view.width().is_finite() && view.height().is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let fits = |r: &figcraft_geom::Rect| r.width() * px <= side && r.height() * px <= side && r.area() * px * px <= MAX_TEXTURE_PIXELS;
|
||||
let mut margin = 0.25;
|
||||
for _ in 0..8 {
|
||||
let r = view.inflate(view.width() * margin, view.height() * margin).intersect(bounds);
|
||||
if fits(&r) {
|
||||
return Some(r);
|
||||
}
|
||||
margin /= 2.0;
|
||||
}
|
||||
Some(view)
|
||||
}
|
||||
|
||||
/// The first interaction index on `id` whose trigger satisfies `want`.
|
||||
pub(super) fn find_trigger(doc: &Document, id: NodeId, want: impl Fn(&Trigger) -> bool) -> Option<usize> {
|
||||
doc.node(id)?.interactions.iter().position(|it| want(&it.trigger))
|
||||
|
||||
@@ -74,7 +74,26 @@ pub(super) fn draw(p: &mut Presenter, painter: &egui::Painter, ctx: &egui::Conte
|
||||
}
|
||||
}
|
||||
if !drawn && let Some(to) = &to_tex {
|
||||
painter.with_clip_rect(l.clip).image(to.tex.id(), l.place.rect(to.bounds), uv, Color32::WHITE);
|
||||
let on_clip = painter.with_clip_rect(l.clip);
|
||||
// A frame too big for one texture at device scale is drawn from a smaller one: the part in
|
||||
// view is drawn from a texture at device scale instead. The detail REPLACES that part of the
|
||||
// whole-frame texture (the base is drawn only around it): both start from a transparent
|
||||
// pixmap, so drawn over it a translucent layer would count twice.
|
||||
let shown = l.clip.intersect(l.place.rect(to.bounds));
|
||||
let mut detail = None;
|
||||
if shown.is_positive() {
|
||||
let (a, b) = (l.place.page(shown.min), l.place.page(shown.max));
|
||||
let visible = figcraft_geom::Rect::new(a.x, a.y, b.x, b.y);
|
||||
let moving = p.fling.is_some() || p.drag_scroll.is_some() || p.wheel.is_some();
|
||||
detail = p.detail_texture(ctx, &l.disp, p.current, px, to.bounds, visible, moving, now);
|
||||
}
|
||||
let hole = detail.as_ref().map(|d| l.clip.intersect(l.place.rect(d.bounds)));
|
||||
for part in base_parts(l.clip, hole) {
|
||||
painter.with_clip_rect(part).image(to.tex.id(), l.place.rect(to.bounds), uv, Color32::WHITE);
|
||||
}
|
||||
if let Some(d) = detail {
|
||||
on_clip.image(d.tex.id(), l.place.rect(d.bounds), uv, Color32::WHITE);
|
||||
}
|
||||
}
|
||||
// Overlays (each with its background and opening transition); closing ones run it backwards.
|
||||
let mut ovs: Vec<(f64, OverlayState)> =
|
||||
@@ -121,3 +140,23 @@ pub(super) fn draw(p: &mut Presenter, painter: &egui::Painter, ctx: &egui::Conte
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/// The parts of `clip` outside `hole` (up to four disjoint rectangles; `clip` itself with no hole).
|
||||
pub(super) fn base_parts(clip: Rect, hole: Option<Rect>) -> Vec<Rect> {
|
||||
let Some(h) = hole.filter(|h| h.is_positive()) else {
|
||||
return vec![clip];
|
||||
};
|
||||
let h = h.intersect(clip);
|
||||
if !h.is_positive() {
|
||||
return vec![clip];
|
||||
}
|
||||
[
|
||||
Rect::from_min_max(clip.min, egui::pos2(clip.max.x, h.min.y)),
|
||||
Rect::from_min_max(egui::pos2(clip.min.x, h.max.y), clip.max),
|
||||
Rect::from_min_max(egui::pos2(clip.min.x, h.min.y), egui::pos2(h.min.x, h.max.y)),
|
||||
Rect::from_min_max(egui::pos2(h.max.x, h.min.y), egui::pos2(clip.max.x, h.max.y)),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|r| r.is_positive())
|
||||
.collect()
|
||||
}
|
||||
@@ -437,6 +437,232 @@ fn smart_animate_frame_cost() {
|
||||
eprintln!("smart animate: {per:.2} ms per frame (80 layers, 400x800 px)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tall_frame_detail_plan_renders_the_view_at_device_scale() {
|
||||
use figcraft_geom::Rect as PageRect;
|
||||
let bounds = PageRect::new(0.0, 0.0, 1440.0, 9701.0);
|
||||
let visible = PageRect::new(0.0, 0.0, 1440.0, 860.0);
|
||||
let side = 16382.0;
|
||||
assert!(actions::texture_scale_for(bounds, 2.0, side) < 1.1, "the whole frame is capped below device scale");
|
||||
let r = actions::detail_plan(bounds, visible, 2.0, side).expect("a capped frame gets a detail");
|
||||
assert!(r.x0 <= visible.x0 && r.y0 <= visible.y0 && r.x1 >= visible.x1 && r.y1 >= visible.y1, "covers the view");
|
||||
assert!(r.x0 >= bounds.x0 && r.y0 >= bounds.y0 && r.x1 <= bounds.x1 && r.y1 <= bounds.y1, "inside the frame");
|
||||
assert!(r.width() * 2.0 <= side && r.height() * 2.0 <= side);
|
||||
assert!(r.width() * r.height() * 4.0 <= 16_777_216.0);
|
||||
let small = PageRect::new(0.0, 0.0, 1440.0, 900.0);
|
||||
assert!(actions::detail_plan(small, PageRect::new(0.0, 0.0, 1440.0, 860.0), 2.0, side).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presenting_a_tall_frame_on_a_hidpi_display_draws_the_view_at_device_scale() {
|
||||
let mut session = figcraft_engine::Session::new();
|
||||
let frame = id(&session.execute("node.create", &json!({"type": "frame", "width": 1440, "height": 9701})).unwrap());
|
||||
session.execute("node.create", &json!({"type": "rectangle", "parent": frame, "x": 100, "y": 100, "width": 300, "height": 200})).unwrap();
|
||||
let mut ui = Ui::new(session);
|
||||
ui.hidpi = Some((2.0, 16_384));
|
||||
ui.run("proto.present", json!({"start": frame}));
|
||||
ui.app.ui.present.as_mut().unwrap().view.scale = PresentScale::FitWidth;
|
||||
ui.frames(2, Vec::new);
|
||||
|
||||
let textures = ui.ctx.tex_manager();
|
||||
let textures = textures.read();
|
||||
let present: Vec<_> = textures.allocated().filter(|(_, m)| m.name.starts_with("present-")).map(|(_, m)| m.size).collect();
|
||||
assert!(!present.is_empty());
|
||||
assert!(present.iter().any(|s| s[0] >= 2878), "some texture shows the view at 2 px a unit: {present:?}");
|
||||
for s in &present {
|
||||
// The scale caps the area; each side then rounds up to a whole pixel.
|
||||
assert!(s[0] * s[1] <= 16_777_216 + s[0] + s[1] && s[0] <= 16_384 && s[1] <= 16_384, "{s:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A tall frame on a 2x display, presented, and the page area its detail texture shows.
|
||||
fn tall_hidpi(side: usize) -> Ui {
|
||||
let mut session = figcraft_engine::Session::new();
|
||||
let frame = id(&session.execute("node.create", &json!({"type": "frame", "width": 1440, "height": 9701})).unwrap());
|
||||
session.execute("node.create", &json!({"type": "rectangle", "parent": frame, "x": 100, "y": 100, "width": 300, "height": 200})).unwrap();
|
||||
let mut ui = Ui::new(session);
|
||||
ui.hidpi = Some((2.0, side));
|
||||
ui.run("proto.present", json!({"start": frame}));
|
||||
ui.app.ui.present.as_mut().unwrap().view.scale = PresentScale::FitWidth;
|
||||
ui.frames(2, Vec::new);
|
||||
ui
|
||||
}
|
||||
|
||||
fn detail_bounds(ui: &Ui) -> Option<figcraft_geom::Rect> {
|
||||
ui.app.ui.present.as_ref().and_then(|p| p.detail.as_ref().map(|(_, d)| d.bounds))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_detail_is_kept_while_nothing_changes_and_made_again_when_the_frame_does() {
|
||||
let mut ui = tall_hidpi(16_384);
|
||||
let tex_id = |ui: &Ui| ui.app.ui.present.as_ref().and_then(|p| p.detail.as_ref().map(|(_, d)| d.tex.id()));
|
||||
let first = tex_id(&ui).expect("a detail is drawn");
|
||||
let bounds = detail_bounds(&ui).unwrap();
|
||||
assert!(
|
||||
bounds.x0 == 0.0 && bounds.y0 == 0.0 && bounds.x1 == 1440.0 && bounds.y1 > 860.0 && bounds.y1 < 9701.0,
|
||||
"the view and a margin: {bounds:?}"
|
||||
);
|
||||
ui.frames(5, Vec::new);
|
||||
assert_eq!(tex_id(&ui), Some(first), "the same view makes no new render");
|
||||
let rect = ui.app.session.doc().unwrap().node(ui.app.session.doc().unwrap().first_page().unwrap()).unwrap().children[0];
|
||||
let child = ui.app.session.doc().unwrap().node(rect).unwrap().children[0];
|
||||
ui.run("node.set", json!({"id": child, "props": {"x": 120}}));
|
||||
ui.frames(3, Vec::new);
|
||||
assert_ne!(tex_id(&ui), Some(first), "an edit renders the detail again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_view_a_rounding_error_past_the_frame_keeps_its_detail() {
|
||||
let mut ui = tall_hidpi(16_384);
|
||||
let ctx = ui.ctx.clone();
|
||||
let doc = ui.app.session.doc().unwrap().clone();
|
||||
let now = ui.time;
|
||||
let p = ui.app.ui.present.as_mut().unwrap();
|
||||
let id = p.current;
|
||||
let whole = figcraft_geom::Rect::new(0.0, 0.0, 1440.0, 9701.0);
|
||||
// The screen-to-page round trip can put the view a hair outside the frame.
|
||||
let view = figcraft_geom::Rect::new(-1e-9, 0.0, 1440.0 + 1e-9, 860.0);
|
||||
let first = p.detail_texture(&ctx, &doc, id, 2.0, whole, view, false, now).expect("a detail").tex.id();
|
||||
let again = p.detail_texture(&ctx, &doc, id, 2.0, whole, view, false, now).expect("a detail").tex.id();
|
||||
assert_eq!(again, first, "the same view reuses its detail instead of rendering a new one");
|
||||
}
|
||||
|
||||
/// While the view moves, the detail is drawn only while it covers the whole view: past its edge
|
||||
/// the capped whole-frame texture shows alone, so no sharp/soft boundary crosses the view, and
|
||||
/// once the view settles a detail for it is rendered.
|
||||
#[test]
|
||||
fn a_moving_view_past_its_detail_shows_the_capped_frame_alone_until_it_settles() {
|
||||
use figcraft_geom::Rect as R;
|
||||
let mut ui = tall_hidpi(16_384);
|
||||
let ctx = ui.ctx.clone();
|
||||
let doc = ui.app.session.doc().unwrap().clone();
|
||||
let now = ui.time;
|
||||
let p = ui.app.ui.present.as_mut().unwrap();
|
||||
let id = p.current;
|
||||
let whole = R::new(0.0, 0.0, 1440.0, 9701.0);
|
||||
let covers = |b: R, v: R| b.x0 <= v.x0 && b.y0 <= v.y0 && b.x1 >= v.x1 && b.y1 >= v.y1;
|
||||
let first = p.detail_texture(&ctx, &doc, id, 2.0, whole, R::new(0.0, 0.0, 1440.0, 860.0), false, now).expect("a detail");
|
||||
// Moving within the detail's margin: it is reused.
|
||||
let shift = (first.bounds.y1 - 860.0) / 2.0;
|
||||
assert!(shift > 0.0, "{:?}", first.bounds);
|
||||
let inside = R::new(0.0, shift, 1440.0, 860.0 + shift);
|
||||
let moved = p.detail_texture(&ctx, &doc, id, 2.0, whole, inside, true, now).expect("still covered");
|
||||
assert_eq!(moved.tex.id(), first.tex.id());
|
||||
// Moving past its edge: no detail, the capped texture shows alone.
|
||||
let past = R::new(0.0, first.bounds.y1 - 430.0, 1440.0, first.bounds.y1 + 430.0);
|
||||
assert!(!covers(first.bounds, past));
|
||||
assert!(p.detail_texture(&ctx, &doc, id, 2.0, whole, past, true, now).is_none(), "the old detail is not drawn over part of the view");
|
||||
// Settled there: a new detail for that view.
|
||||
let settled = p.detail_texture(&ctx, &doc, id, 2.0, whole, past, false, now).expect("a new detail");
|
||||
assert_ne!(settled.tex.id(), first.tex.id());
|
||||
assert!(covers(settled.bounds, past), "{:?} covers {past:?}", settled.bounds);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_still_view_keeps_its_detail_at_fractional_scales() {
|
||||
// Frame widths that give fractional fit-width scales: the view's page rect then comes back
|
||||
// from the screen with rounding, a hair past the frame's edge.
|
||||
let mut with_detail = 0;
|
||||
for w in [1001.3, 1111.1, 1234.5, 1337.7, 1440.9, 1555.5, 1666.6, 1777.7, 1888.8, 1999.9, 2345.6] {
|
||||
let mut session = figcraft_engine::Session::new();
|
||||
let frame = id(&session.execute("node.create", &json!({"type": "frame", "width": w, "height": 9701})).unwrap());
|
||||
session.execute("node.create", &json!({"type": "rectangle", "parent": frame, "x": 100, "y": 100, "width": 300, "height": 200})).unwrap();
|
||||
let mut ui = Ui::new(session);
|
||||
ui.hidpi = Some((2.0, 16_384));
|
||||
ui.run("proto.present", json!({"start": frame}));
|
||||
ui.app.ui.present.as_mut().unwrap().view.scale = PresentScale::FitWidth;
|
||||
ui.frames(2, Vec::new);
|
||||
let tex_id = |ui: &Ui| ui.app.ui.present.as_ref().and_then(|p| p.detail.as_ref().map(|(_, d)| d.tex.id()));
|
||||
let Some(first) = tex_id(&ui) else { continue };
|
||||
with_detail += 1;
|
||||
ui.frames(4, Vec::new);
|
||||
assert_eq!(tex_id(&ui), Some(first), "width {w}: a still view keeps its detail");
|
||||
}
|
||||
assert!(with_detail >= 3, "most of these widths need a detail texture: {with_detail}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detail_plan_edge_cases() {
|
||||
use figcraft_geom::Rect as R;
|
||||
let bounds = R::new(0.0, 0.0, 1440.0, 9701.0);
|
||||
let side = 16382.0;
|
||||
// Nothing in view, an empty or invalid view, a bad scale: no detail.
|
||||
for v in [R::new(0.0, 10_000.0, 1440.0, 11_000.0), R::new(0.0, 100.0, 0.0, 100.0)] {
|
||||
assert!(actions::detail_plan(bounds, v, 2.0, side).is_none(), "{v:?}");
|
||||
}
|
||||
for px in [0.0, -1.0, f64::NAN] {
|
||||
assert!(actions::detail_plan(bounds, R::new(0.0, 0.0, 1440.0, 860.0), px, side).is_none(), "{px}");
|
||||
}
|
||||
// Partly outside: the part inside.
|
||||
let r = actions::detail_plan(bounds, R::new(0.0, -500.0, 1440.0, 360.0), 2.0, side).unwrap();
|
||||
assert!(r.y0 == 0.0 && r.y1 >= 360.0, "{r:?}");
|
||||
// A view whose quarter margin passes the pixel cap gets a smaller margin that fits.
|
||||
let r = actions::detail_plan(bounds, R::new(0.0, 3000.0, 1440.0, 5000.0), 2.0, side).unwrap();
|
||||
assert!(r.height() > 2000.0 && r.height() < 3000.0 && r.width() * r.height() * 4.0 <= 16_777_216.0, "{r:?}");
|
||||
// A view past the caps by itself is returned as it is.
|
||||
let tall = R::new(0.0, 1000.0, 1440.0, 5000.0);
|
||||
assert_eq!(actions::detail_plan(bounds, tall, 2.0, side), Some(tall));
|
||||
// A small texture limit: the view alone is over it, so it is the view.
|
||||
let view = R::new(0.0, 0.0, 1440.0, 860.0);
|
||||
assert_eq!(actions::detail_plan(bounds, view, 2.0, 2048.0), Some(view));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_detail_replaces_the_whole_frame_texture_instead_of_drawing_over_it() {
|
||||
// A frame with no fill holding a 50% rectangle: both textures start from a transparent pixmap,
|
||||
// so drawn over each other the rectangle would count twice (75%, not 50%).
|
||||
let mut session = figcraft_engine::Session::new();
|
||||
let frame = id(&session.execute("node.create", &json!({"type": "frame", "width": 1440, "height": 9701, "props": {"fills": []}})).unwrap());
|
||||
let r =
|
||||
id(&session.execute("node.create", &json!({"type": "rectangle", "parent": frame, "x": 0, "y": 0, "width": 1440, "height": 9701})).unwrap());
|
||||
session.execute("node.set", &json!({"id": r, "props": {"fill": "#ff0000", "opacity": 0.5}})).unwrap();
|
||||
let mut ui = Ui::new(session);
|
||||
ui.hidpi = Some((2.0, 16_384));
|
||||
ui.run("proto.present", json!({"start": frame}));
|
||||
ui.app.ui.present.as_mut().unwrap().view.scale = PresentScale::FitWidth;
|
||||
ui.frames(2, Vec::new);
|
||||
|
||||
// The pixel's alpha is the rectangle's 0.5 in the whole-frame render and in the detail render.
|
||||
let doc = ui.app.session.doc().unwrap();
|
||||
let alpha = |pix: &figcraft_render::Pixmap| pix.data()[3];
|
||||
let whole = figcraft_render::render_node_at(doc, frame, 0.5, 0.0).unwrap();
|
||||
let detail = figcraft_render::render_area_at(doc, &[frame], figcraft_geom::Rect::new(0.0, 0.0, 100.0, 100.0), 2.0, 0.0).unwrap();
|
||||
assert!((i32::from(alpha(&whole)) - 128).abs() <= 1 && (i32::from(alpha(&detail)) - 128).abs() <= 1);
|
||||
|
||||
// On screen, no whole-frame texture is drawn under the detail: one texture covers its centre.
|
||||
let out = ui.frame_output(Vec::new());
|
||||
let prims = ui.ctx.tessellate(out.shapes, 2.0);
|
||||
let names: std::collections::HashMap<egui::TextureId, String> =
|
||||
ui.ctx.tex_manager().read().allocated().map(|(id, m)| (*id, m.name.clone())).collect();
|
||||
let mut present: Vec<(String, egui::Rect, egui::Rect)> = Vec::new();
|
||||
for prim in &prims {
|
||||
if let egui::epaint::Primitive::Mesh(m) = &prim.primitive
|
||||
&& let Some(n) = names.get(&m.texture_id).filter(|n| n.starts_with("present-"))
|
||||
{
|
||||
let bbox = m.vertices.iter().fold(egui::Rect::NOTHING, |r, v| r.union(egui::Rect::from_min_max(v.pos, v.pos)));
|
||||
present.push((n.clone(), bbox, prim.clip_rect));
|
||||
}
|
||||
}
|
||||
let (_, dbox, dclip) = present.iter().find(|(n, ..)| n.starts_with("present-detail-")).expect("the detail is drawn");
|
||||
let centre = dbox.intersect(*dclip).center();
|
||||
let covering: Vec<_> = present.iter().filter(|(_, b, c)| b.contains(centre) && c.contains(centre)).map(|(n, ..)| n.as_str()).collect();
|
||||
assert_eq!(covering.len(), 1, "only the detail covers the view's centre:: {covering:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn base_parts_leave_the_hole_out() {
|
||||
use egui::{Rect, pos2};
|
||||
let clip = Rect::from_min_max(pos2(0.0, 0.0), pos2(100.0, 100.0));
|
||||
assert_eq!(draw::base_parts(clip, None), vec![clip]);
|
||||
let hole = Rect::from_min_max(pos2(10.0, 20.0), pos2(60.0, 70.0));
|
||||
let parts = draw::base_parts(clip, Some(hole));
|
||||
assert_eq!(parts.len(), 4);
|
||||
let area: f32 = parts.iter().map(|r| r.width() * r.height()).sum();
|
||||
assert_eq!(area, 100.0 * 100.0 - 50.0 * 50.0);
|
||||
assert!(parts.iter().all(|r| !r.intersects(hole.shrink(0.01))));
|
||||
assert!(draw::base_parts(clip, Some(clip)).is_empty());
|
||||
}
|
||||
|
||||
/// The preview pane's 24 pt bar buttons paint their glyphs at 16 pt (#2238).
|
||||
#[test]
|
||||
fn pane_bar_buttons_paint_16pt() {
|
||||
|
||||
@@ -13,11 +13,13 @@ pub(crate) struct Ui {
|
||||
pub(crate) ctx: egui::Context,
|
||||
pub(crate) app: FigApp,
|
||||
pub(crate) time: f64,
|
||||
/// A display's pixels per point and the biggest texture side its GPU takes (None: egui's defaults).
|
||||
pub(crate) hidpi: Option<(f32, usize)>,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub(crate) fn new(s: Session) -> Self {
|
||||
let mut u = Self { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0 };
|
||||
let mut u = Self { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, hidpi: None };
|
||||
u.frames(3, Vec::new);
|
||||
u
|
||||
}
|
||||
@@ -29,8 +31,12 @@ impl Ui {
|
||||
/// [`Self::frame`], returning what egui output (the AccessKit tree when it's enabled).
|
||||
pub(crate) fn frame_output(&mut self, events: Vec<Event>) -> egui::FullOutput {
|
||||
self.time += 1.0 / 60.0;
|
||||
let input =
|
||||
let mut input =
|
||||
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
|
||||
if let Some((ppp, side)) = self.hidpi {
|
||||
input.max_texture_side = Some(side);
|
||||
input.viewports.entry(egui::ViewportId::ROOT).or_default().native_pixels_per_point = Some(ppp);
|
||||
}
|
||||
let app = &mut self.app;
|
||||
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
|
||||
out.textures_delta.clear();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Prototyping parity
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-09 · **Change:** patch (in the presenter's comment mode (C) a click on the presented frame starts a comment there and the mode stays on for the next one, Escape closes the draft and then the mode, measured in Figma's web app 2026-11-10 (#2209); a connection dragged from a variant, or a layer in it, onto a sibling variant makes Change to, On click, Instant, with the sibling outlined (#2158); `proto.settings` refuses an unknown device with the list of devices instead of saving it, takes a known one in any case, and answers the page's settings, so `proto.settings {}` reads them (#2027); Hide UI in the presenter's Options menu, and Cmd/Ctrl+\ as in the editor: the bar above the prototype and the navigation bar under it go away, a toast names the key that brings them back, `proto.presentOptions {hideUi}` (#1820); the Controller menu names each button as PlayStation and Switch controllers do; "Open in new tab" on Open link: off, the web build's own tab goes to the link; a manual overlay's position can be dragged on the canvas (#405); Open link notices now cover mail links, and skipping them covers only links the viewer fired (#1096); overlay positions relative to the layer that opens them; the Triggers row no longer lists delays on mouse triggers as missing; top-level frames bigger than the device's screen scroll in the player; Change to, set variable and set variable mode lay out what they change in the player, as the canvas does; presentation tabs, one per page of a file; a Present tab with device and scale controls (#537); core editor leftovers: delays on mouse triggers and manual overlay offsets; controller buttons on key/gamepad triggers, widgets that react in prototypes, `proto.evaluate` and the mode lookup rules pinned) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-10 · **Change:** patch (in the presenter's comment mode (C) a click on the presented frame starts a comment there and the mode stays on for the next one, Escape closes the draft and then the mode, measured in Figma's web app 2026-11-10 (#2209); presenting a tall frame is sharp on a HiDPI display: a frame too big for one texture at device scale (a 1440 by 9701 frame at 2 pixels a unit) is still drawn from the capped whole-frame texture, with the part in view drawn again over it from a texture at device scale (#2127); a connection dragged from a variant, or a layer in it, onto a sibling variant makes Change to, On click, Instant, with the sibling outlined (#2158); `proto.settings` refuses an unknown device with the list of devices instead of saving it, takes a known one in any case, and answers the page's settings, so `proto.settings {}` reads them (#2027); Hide UI in the presenter's Options menu, and Cmd/Ctrl+\ as in the editor: the bar above the prototype and the navigation bar under it go away, a toast names the key that brings them back, `proto.presentOptions {hideUi}` (#1820); the Controller menu names each button as PlayStation and Switch controllers do; "Open in new tab" on Open link: off, the web build's own tab goes to the link; a manual overlay's position can be dragged on the canvas (#405); Open link notices now cover mail links, and skipping them covers only links the viewer fired (#1096); overlay positions relative to the layer that opens them; the Triggers row no longer lists delays on mouse triggers as missing; top-level frames bigger than the device's screen scroll in the player; Change to, set variable and set variable mode lay out what they change in the player, as the canvas does; presentation tabs, one per page of a file; a Present tab with device and scale controls (#537); core editor leftovers: delays on mouse triggers and manual overlay offsets; controller buttons on key/gamepad triggers, widgets that react in prototypes, `proto.evaluate` and the mode lookup rules pinned) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
**Breadth ~92%, ready ~74% (estimated).** Every Figma trigger except media, every action except
|
||||
media control, every transition and easing exist; key/gamepad triggers take controller buttons,
|
||||
@@ -92,7 +92,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
|
||||
| Widgets react to clicks in a presented prototype | done | clicks only, like on the canvas |
|
||||
| Interactive components: instances play their variant's interactions, overridden per trigger | done | |
|
||||
| Drag-driven animations that follow the pointer, in their direction | done | |
|
||||
| Presenter: device frames and colours, rotation, custom sizes, fit/fill/100%, responsive frames | done | device bodies drawn in code. Presenting opens a tab for the page, named "file - page", which keeps its screen and history while you go back to the design, with a thumbnail of the current frame, previous / next, device presets and scale choices; the frame is laid out again for the device's screen on the prototype's copy (constraints and auto layout; the file is untouched); on phones and tablets overflowing content drags while the device stays put: a top-level frame bigger than the screen always scrolls (as in Figma, with no overflow setting), content past the frame's own edges as its overflow setting allows ("No scrolling" clips it); closing the window asks about unsaved changes above the presentation (#537). Devices not compared with Figma's |
|
||||
| Presenter: device frames and colours, rotation, custom sizes, fit/fill/100%, responsive frames | done | device bodies drawn in code. Presenting opens a tab for the page, named "file - page", which keeps its screen and history while you go back to the design, with a thumbnail of the current frame, previous / next, device presets and scale choices; the frame is laid out again for the device's screen on the prototype's copy (constraints and auto layout; the file is untouched); on phones and tablets overflowing content drags while the device stays put: a top-level frame bigger than the screen always scrolls (as in Figma, with no overflow setting), content past the frame's own edges as its overflow setting allows ("No scrolling" clips it); closing the window asks about unsaved changes above the presentation (#537); a frame too big for one texture at device scale (taller than about 2900 units at 1440 wide on a 2x display) shows the part in view from a second texture at device scale over the capped whole-frame one, drawn again when it stops covering the view and not while the view moves, when past it the capped texture shows alone until the view settles (#2127). Devices not compared with Figma's |
|
||||
| Hotspot hints, inspect panel in the presenter, comments in the presenter | done | in comment mode (C) a click on the presented frame starts a comment there (a click off the frame does nothing, and the prototype's own click interactions don't fire) and the mode stays on for the next comment; Escape closes the draft, then the mode (the presentation stays open), as measured in Figma's web app 2026-11-10 (#2209). No comments sidebar in the presenter |
|
||||
| Hide UI in the presenter (Options menu, Cmd/Ctrl+\) | done | the bar above the prototype and the navigation bar under it go away and the prototype takes their room; a toast names the key that brings them back; `proto.presentOptions {hideUi}`, kept for later presentations (#1820) |
|
||||
| Preview pane following edits live | done | |
|
||||
@@ -111,6 +111,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
|
||||
| 2026-11-14 | patch | M5, #2352: a chain of variant changes on After delay plays to the end (A to B to C to D); before, the step a variant had fired stayed marked as fired when the instance changed variant, so the chain stopped after one step, and now each step's delay counts from when its variant appears (`crates/ui-egui/src/present/afterdelay_chain_tests.rs`). Numbers unchanged |
|
||||
| 2026-11-09 | patch | M7, #2158: a connection dragged from a variant (or a layer in it) onto a sibling variant of its set did nothing, because the drop looked only for top-level frames and a variant's top-level frame is its set. It now creates Change to the sibling (On click, Instant, as measured in Figma's web app) and outlines the sibling while dragging; the set's background and the variant itself still add nothing, and a frame outside the set still gets Navigate to |
|
||||
| 2026-11-10 | patch | M7, #2209: the presenter's comment mode showed the frame's pins but nothing started a comment. Measured in Figma's web app: with the mode on (C or the bar's comment button) a click on the presented frame drops a pin at the click and opens an "Add a comment" composer beside it; Enter posts, the pin stays at the same frame-relative spot and the mode stays on; a click on the background does nothing; Escape closes a composer, and with none open turns the mode off; the comment shows on the frame in the editor. Now the same: the click starts the draft at the point mapped back through the presenter's placement, the editor's composer is shared, the post carries the frame's page, the player ignores the pointer while the mode is on (no click interactions or hotspots fire), and Escape closes the draft, then the mode. Tests: `comments_tests::a_click_in_the_presenters_comment_mode_adds_a_comment_on_the_frame` and four more. |
|
||||
| 2026-11-09 | patch | M5, #2127: presenting a frame taller than about 2900 units at 1440 wide on a 2x display (Fit width, or 100%) drew it blurry: the whole frame is rasterised once, capped at 16.8 million pixels (a 1440 by 9701 frame at 1.1 pixels a unit, 1579 by 10632), and stretched up 1.8 times with linear filtering, while the canvas, which renders only what is in view, stayed sharp. Now the part in view plus a quarter of its size each way is drawn again over that texture from one more at the full pixel scale (never past the GPU's side or the same pixel cap), rendered when it stops covering the view and not while a fling, drag or the wheel moves it (while the view moves, a detail is drawn only while it covers the whole view: past it the capped texture shows alone, with no sharp edge across the view, until the view settles); transitions, smart animate, overlays and thumbnails keep the capped texture. Tests: `present::tests::tall_frame_detail_plan_renders_the_view_at_device_scale`, `presenting_a_tall_frame_on_a_hidpi_display_draws_the_view_at_device_scale`. Numbers unchanged |
|
||||
| 2026-11-06 | patch | M5, #2027: `proto.settings` took any string as the device (`"Pixel Nonexistent"`, `"iphone 16"`) and saved it in the file; the presenter then drew no device while its picker showed the name as if it were one, and the settings couldn't be read back over MCP (`proto.settings {}` answered `{ok: true}`). An unknown name (or a non-string) is now refused with every name the picker offers (`None`, `Custom size` and the devices), as an unknown colour is refused with the device's colours, and nothing changes; a known name is taken in any case and stored as the picker spells it. Every call answers the page's settings after it: device, background, rotation, the colour shown, the screen as presented, the custom size and responsive. Test: `proto_present_tests::unknown_devices_are_refused_and_settings_read_back` |
|
||||
| 2026-10-31 | minor | Gap 15: the Controller menu names buttons as PlayStation and Switch controllers do; that item leaves the missing list. Estimate unchanged. Test: `present::tail_tests`. |
|
||||
| 2026-10-30 | minor | Opening a link in place: Open link has "Open in new tab", on by default; off, the web build's own tab goes to the link after the notice (or at once with it skipped); the desktop app has no tab of its own and opens the browser either way. Saved in files only when off (`openInNewTab`) and read from REST files. |
|
||||
|
||||
@@ -652,6 +652,7 @@ Carried over from the ROADMAP's "Shipped so far" (2026-10-10). The test count th
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-18 | minor | M9, gap 6: the browser build uses team libraries and plugin directories on a server, through its WebSocket requests: adding a library by its link, its styles and components, publishing to it, Show usage and the reports a file sends; browsing a directory and installing from it, for the page only. Scripts through `window.figcraft` still can't, as commands there don't wait for the server. Numbers unchanged. Tests: `exchange_tests`. |
|
||||
| 2026-11-09 | patch | M5, #2127: presenting a frame taller than about 2900 units at 1440 wide on a 2x display (Fit width, or 100%) drew it blurry: the whole frame is rasterised once, capped at 16.8 million pixels (a 1440 by 9701 frame at 1.1 pixels a unit, 1579 by 10632), and stretched up 1.8 times with linear filtering, while the canvas, which renders only what is in view, stayed sharp. Now the part in view plus a quarter of its size each way is drawn again over that texture from one more at the full pixel scale (never past the GPU's side or the same pixel cap), rendered when it stops covering the view and not while a fling, drag or the wheel moves it (while the view moves, a detail is drawn only while it covers the whole view: past it the capped texture shows alone, with no sharp edge across the view, until the view settles); transitions, smart animate, overlays and thumbnails keep the capped texture. Tests: `present::tests::tall_frame_detail_plan_renders_the_view_at_device_scale`, `presenting_a_tall_frame_on_a_hidpi_display_draws_the_view_at_device_scale`. Numbers unchanged |
|
||||
| 2026-11-08 | minor | M8, #2109: in vector edit mode the Align commands (`align.left` to `align.bottom`, Alt+A/H/D/W/V/S) and Distribute horizontal and vertical spacing act on the selected points when no `ids` are given, as in Figma (measured in Figma on 2026-11-08): each point moves along one axis only, to its box's left, horizontal centre, right, top, vertical centre or bottom, and distribute spaces the points evenly between the outermost two in order along the axis; handles go with their vertex, a single point stays, with no point selected nothing moves (the layer is not aligned to its frame, as measured in Figma), and one undo restores them. The Design panel draws the alignment row first, with a Distribute menu from three points. Numbers unchanged. |
|
||||
| 2026-11-15 | minor | M6 `.fig` export writes text on a path (#2323), list spacing, hanging punctuation and lists, vertical trim (#2305), vector region paints (#2302), image adjustments (#2297) and a page's prototype background (#2326); M8 Tidy up keeps a row's or column's order and sizes and evens the gaps, rounds the gap, tidies overlapping rows and grids along their longer axis, and raises a negative gap, as measured in Figma (#2319); a polygon's or star's Count handle and a double-click on a layer's icon (zoom, range anchor) follow Figma; Tab while renaming moves only the rename; Align is unavailable in an auto layout frame's flow; the Scale tool pivots on the opposite handle; Paste over selection puts copies above the selected layer; Crop from the image fill's menu crops with a drag (#2307); M10 code export writes every colour and gradient fill in paint order for CSS, SwiftUI, Compose and Flutter (#2271); 24 pt icon buttons draw 16 pt glyphs (#2227, #2238); M5 marquee selection follows Figma's measured rules and Select layer lists locked layers (#1560); M7 the Design panel shows the page's variable modes with nothing selected (#2215); M12 mind maps centre in a section or frame without a place, stickies take a Small–Huge text-size menu, and M9 `.jam` shapes with text import as native board shapes (#1808); M4 a boolean group's corner radius rounds its result (#2222), Flatten bakes a point's corner radius (#2195) and loops close through a joining segment (#1951); library links survive moving or cloning the project folder (#2132); a variable group renamed to a path with `/` nests (#2353); SVG import, widget images, batches and grids take bounded work, and a host's server key is never sent over plain `ws://` to another machine (#1923); releases FigCraft v0.18.0 and v0.18.1; the 2026-10-17 menu measurement (212 / 212) and every percentage and hour stand, not re-measured |
|
||||
| 2026-11-10 | minor | M4, #2222: a boolean group's corner radius rounds every sharp corner of its result (row 4). Numbers unchanged |
|
||||
|
||||
Reference in new issue
Block a user