mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 10:48:15 +01:00
Merge look-fix4-canvas framework work
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
3299b862cb
10 files changed
+206
-53
No files matched your search
@@ -151,11 +151,13 @@ pub enum BoxLook {
|
||||
|
||||
impl BoxLook {
|
||||
/// The handle look of this box look, for the points a host draws beside the box in the same look (a line's ends,
|
||||
/// a connector's sites, edit points): the document looks rim them as their frame.
|
||||
/// a connector's sites, edit points): the document looks rim them as their frame, and fill them with it while the
|
||||
/// box is disabled (a locked shape), so the lock shows on the handles and not only in the missing rotate handle.
|
||||
pub fn handle_look(self, cx: &StyleCx<'_>) -> HandleLook {
|
||||
let mut look = cx.handle();
|
||||
if self != BoxLook::Standard {
|
||||
look.stroke = document_ink(cx);
|
||||
look.fill.off.disabled = document_ink(cx);
|
||||
}
|
||||
look
|
||||
}
|
||||
@@ -347,6 +349,8 @@ pub struct TransformBoxStyle {
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
handle: HandleLook,
|
||||
/// The handle of the document looks ([`BoxLook::handle_look`]).
|
||||
document_handle: HandleLook,
|
||||
line: StyleColor,
|
||||
halo: StyleColor,
|
||||
/// The frame, the handle rims and the rotate handle of the document look.
|
||||
@@ -1228,18 +1232,18 @@ impl TransformBox<'_> {
|
||||
|
||||
/// A handle's `square` (a circle with round handles), filled as the state of `part` shows, or at rest without one.
|
||||
fn paint_handle_shape(&self, draw: &Draw<'_>, cx: &Cx<'_, Self>, square: PaintShape, part: Option<PartRef>) {
|
||||
let look = &cx.style.handle;
|
||||
let look = self.handle_look(cx.style);
|
||||
let fill = match part {
|
||||
Some(part) => cx.resolve_part(part, &look.fill),
|
||||
None => cx.resolve(&look.fill),
|
||||
};
|
||||
draw.fill(&square, fill);
|
||||
draw.stroke(&square, StrokeWidth::Thin, self.ink(self.rim(cx.style)));
|
||||
draw.stroke(&square, StrokeWidth::Thin, self.ink(look.stroke));
|
||||
}
|
||||
|
||||
/// The colour of a handle's rim in this look.
|
||||
fn rim(&self, style: &TransformBoxStyle) -> StyleColor {
|
||||
if self.look == BoxLook::Standard { style.handle.stroke } else { style.neutral }
|
||||
/// The handle of this look.
|
||||
fn handle_look<'s>(&self, style: &'s TransformBoxStyle) -> &'s HandleLook {
|
||||
if self.look == BoxLook::Standard { &style.handle } else { &style.document_handle }
|
||||
}
|
||||
|
||||
/// The frame of the box whose corners are `corners` on the screen, as the look draws it.
|
||||
@@ -1399,6 +1403,7 @@ fn transform_style(cx: &StyleCx<'_>) -> TransformBoxStyle {
|
||||
TransformBoxStyle {
|
||||
metrics: Metrics::new(),
|
||||
handle: cx.handle(),
|
||||
document_handle: BoxLook::Document.handle_look(cx),
|
||||
line: cx.color(overlay.line),
|
||||
halo: cx.color(overlay.halo),
|
||||
neutral: document_ink(cx),
|
||||
|
||||
@@ -73,6 +73,7 @@ struct Config {
|
||||
reach: TransformReach,
|
||||
/// Whether Enter and Escape from the canvas session are the box's.
|
||||
session_commit: bool,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
/// What the host keeps of the box and what the passes reported.
|
||||
@@ -128,6 +129,7 @@ fn defaults() -> Config {
|
||||
twice: false,
|
||||
reach: TransformReach::Box,
|
||||
session_commit: true,
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +226,7 @@ fn harness(state: BoxState, setup: impl FnOnce(&mut Config)) -> Harness {
|
||||
if let Some(side) = config.handle_side {
|
||||
control = control.handle_side(side);
|
||||
}
|
||||
control = control.reach(config.reach).session_commit(config.session_commit);
|
||||
control = control.reach(config.reach).session_commit(config.session_commit).enabled(config.enabled);
|
||||
if config.hover_frame {
|
||||
control = control.id(frame_id);
|
||||
}
|
||||
@@ -1719,6 +1721,31 @@ fn a_host_point_in_the_document_look_takes_the_box_handles_rim() {
|
||||
assert!(painted.contains(&document), "the box's own handles take the same rim: {document:?} in {painted:?}");
|
||||
}
|
||||
|
||||
/// A disabled box in the document look (a locked shape) fills its handles with their rim's ink, where an enabled one
|
||||
/// fills them light: the lock shows on the handles.
|
||||
#[trial]
|
||||
fn a_disabled_document_box_fills_its_handles_with_their_rim() {
|
||||
let fills = |enabled: bool| {
|
||||
let mut h = harness(BoxState::from_rect(RECT), |config| {
|
||||
config.look = BoxLook::Document;
|
||||
config.enabled = enabled;
|
||||
});
|
||||
let shapes = h.fixture.frame_shapes();
|
||||
let fills: Vec<egui::Color32> = shapes
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
Shape::Circle(circle) if circle.fill.a() > 0 => Some(circle.fill),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
(fills, stroke_colors(&shapes))
|
||||
};
|
||||
let ((enabled, enabled_rims), (locked, locked_rims)) = (fills(true), fills(false));
|
||||
assert!(!enabled.is_empty() && !locked.is_empty(), "both boxes paint filled handles");
|
||||
assert!(enabled.iter().all(|fill| !enabled_rims.contains(fill)), "an enabled box's handles are light: {enabled:?} {enabled_rims:?}");
|
||||
assert!(locked.iter().all(|fill| locked_rims.contains(fill)), "a locked box's handles take their rim's ink: {locked:?} {locked_rims:?}");
|
||||
}
|
||||
|
||||
/// A host's handle side draws the corner and side handles at that side: a larger side draws a larger square.
|
||||
#[trial]
|
||||
fn a_host_handle_side_sets_the_drawn_handle_square() {
|
||||
|
||||
@@ -474,11 +474,11 @@ impl Component for Pasteboard<'_> {
|
||||
let (view, style) = (space.view, cx.style);
|
||||
let draw = ui.draw();
|
||||
let edges = ui.content_painter(cx);
|
||||
// What lies under the pages (their shadows and fills) marks where it starts; it moves into the canvas's picture
|
||||
// What lies under the pages (their shadows, fills and line edges) marks where it starts; it moves into the canvas's picture
|
||||
// slot, in show order before the pictures, so every picture lies over it. The surround of plain pages goes
|
||||
// with it, so a picture reaching past the page (copies around it, pixels past the canvas) shows over it; the
|
||||
// surround between artboards paints over the pictures and hides the document there, except where `uncovered`
|
||||
// leaves it open. The page edges and names, which mark the pages, paint in place over the pictures. Outside a
|
||||
// leaves it open. The artboard edges and names, which mark the boards, paint in place over the pictures. Outside a
|
||||
// canvas, or in a space with no slot, everything paints in place.
|
||||
let under = space.picture_slot().map(|_| PaintSlot::reserve(&edges.painter));
|
||||
let artboards = self.pages.iter().any(|page| page.active.is_some()) && !self.shows_outside;
|
||||
@@ -529,6 +529,10 @@ impl Component for Pasteboard<'_> {
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
// A plain page's edge is part of the page, under what the document draws past it.
|
||||
if self.border == PageBorder::Line {
|
||||
edge(&quad, style.outline.egui(), style.outline.into(), false);
|
||||
}
|
||||
}
|
||||
if let Some(under) = under {
|
||||
let ctx = edges.painter.ctx().clone();
|
||||
@@ -540,9 +544,6 @@ impl Component for Pasteboard<'_> {
|
||||
}
|
||||
for (at, page) in self.pages.iter().enumerate().filter(|(_, page)| shown(page)) {
|
||||
let quad = view.quad(page.rect);
|
||||
if self.border == PageBorder::Line {
|
||||
edge(&quad, style.outline.egui(), style.outline.into(), false);
|
||||
}
|
||||
if let Some(active) = page.active {
|
||||
match self.artboard_edge {
|
||||
ArtboardEdge::Accent => {
|
||||
|
||||
@@ -634,7 +634,18 @@ impl Component for Rulers<'_> {
|
||||
// A label as long along the strip as the room between labelled ticks would run into the next one.
|
||||
let majors: Vec<f32> = ticks.iter().filter(|(tick, _)| tick.rank == TickRank::Major).map(|(_, at)| *at).collect();
|
||||
let room = majors.windows(2).map(|pair| (pair[1] - pair[0]).abs()).fold(f32::INFINITY, f32::min);
|
||||
let origin = if vertical { bar.top() } else { bar.left() };
|
||||
let marks: Vec<Tick> = ticks.iter().map(|(tick, at)| Tick::new(*at - origin, tick.rank)).collect();
|
||||
let fits = |label: Rect| (if vertical { label.height() } else { label.width() }) + style.pad < room;
|
||||
// The edge face keeps every tick, so a stacked vertical number is also left out where a shorter tick runs
|
||||
// into its column (a half-unit tick between the "1" and the "0" of 10), which would cut it in two.
|
||||
let crossed = |column: Rect| {
|
||||
face == RulerFace::Edge
|
||||
&& marks.iter().any(|mark| {
|
||||
let (from, to) = mark.span(bar, edge, face);
|
||||
Rect::from_two_pos(from, to).intersects(column)
|
||||
})
|
||||
};
|
||||
let mut galleys = Vec::new();
|
||||
for (tick, at) in ticks.iter().filter(|(tick, _)| tick.rank == TickRank::Major) {
|
||||
let text = text_of(part).tick_label(&numbers, tick.value, tick.step);
|
||||
@@ -659,7 +670,7 @@ impl Component for Rulers<'_> {
|
||||
})
|
||||
.collect();
|
||||
let column = placed.iter().fold(Rect::NOTHING, |all, (at, layout)| all.union(Rect::from_min_size(*at, layout.size())));
|
||||
if !fits(column) {
|
||||
if !fits(column) || crossed(column) {
|
||||
continue;
|
||||
}
|
||||
if face == RulerFace::Centred && (!shows(strip, column) || bands.iter().any(|band| band.intersects(column))) {
|
||||
@@ -682,8 +693,6 @@ impl Component for Rulers<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
let origin = if vertical { bar.top() } else { bar.left() };
|
||||
let marks: Vec<Tick> = ticks.iter().map(|(tick, at)| Tick::new(*at - origin, tick.rank)).collect();
|
||||
let boxes: Vec<Rect> = galleys.iter().map(|(at, layout)| Rect::from_min_size(*at, layout.size())).collect();
|
||||
let marks = face.beside_numbers(edge, origin, marks, &boxes, style.pad);
|
||||
painter.ticks(bar, edge, face, &marks);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use craft_behavior::geometry::quad::Homography;
|
||||
use craft_behavior::kurbo::{Point, Rect as Rect64};
|
||||
use craft_behavior::{CanvasView, PixelSize};
|
||||
use craft_ui::canvas::{AppPaint, Canvas, Extent, PageFrame, Pasteboard, PixelRect, RasterDisplay, RasterSource};
|
||||
use craft_ui::canvas::{AppPaint, Canvas, Extent, PageBorder, PageFrame, Pasteboard, PixelRect, RasterDisplay, RasterSource};
|
||||
use craft_ui::canvas_controls::PixelGrid;
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::primitives::{Checker, Revision};
|
||||
@@ -590,30 +590,44 @@ fn a_picture_in_the_canvas_slot_shows_its_own_colour_over_the_pasteboard() {
|
||||
let page = Rect64::new(0.0, 0.0, 400.0, 300.0);
|
||||
let view = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), page.center(), 1.0);
|
||||
let at = |x: f64, y: f64| view.to_screen(Point::new(x, y));
|
||||
let plain = slot_canvas(view, vec![PageFrame::new(page).fill(DataColor::new(Color32::WHITE))], Vec::new());
|
||||
let plain = slot_canvas(view, vec![PageFrame::new(page).fill(DataColor::new(Color32::WHITE))], Vec::new(), PageBorder::DropShadow);
|
||||
assert!(shows_picture(&plain, at(200.0, 150.0)), "the plain page's centre shows {:?}", colour_at(&plain, at(200.0, 150.0)));
|
||||
let boards = vec![
|
||||
PageFrame::new(Rect64::new(20.0, 20.0, 180.0, 280.0)).name("One").active(true),
|
||||
PageFrame::new(Rect64::new(220.0, 20.0, 380.0, 280.0)).name("Two").active(false),
|
||||
];
|
||||
let loose = vec![Rect64::new(185.0, 20.0, 215.0, 60.0)];
|
||||
let artboards = slot_canvas(view, boards, loose);
|
||||
let artboards = slot_canvas(view, boards, loose, PageBorder::DropShadow);
|
||||
for (x, y, what) in [(100.0, 150.0, "the first board"), (300.0, 150.0, "the second board"), (200.0, 40.0, "the loose layer")] {
|
||||
assert!(shows_picture(&artboards, at(x, y)), "{what} shows {:?}", colour_at(&artboards, at(x, y)));
|
||||
}
|
||||
assert!(!shows_picture(&artboards, at(200.0, 150.0)), "the pasteboard covers the document between the boards");
|
||||
}
|
||||
|
||||
/// A plain page's line edge lies under the picture, as its fill does: content that hangs off the page (a shape on a
|
||||
/// slide's pasteboard) covers the page's edge instead of being crossed by it.
|
||||
#[trial]
|
||||
fn a_picture_over_a_plain_pages_edge_covers_its_line() {
|
||||
let page = Rect64::new(0.0, 0.0, 400.0, 300.0);
|
||||
let view = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), page.center(), 1.0);
|
||||
let shapes = slot_canvas(view, vec![PageFrame::new(page)], Vec::new(), PageBorder::Line);
|
||||
let picture = shapes.iter().position(|shape| matches!(shape, Shape::Rect(rect) if rect.fill == PICTURE));
|
||||
let edges: Vec<usize> = shapes.iter().enumerate().filter(|(_, shape)| matches!(shape, Shape::LineSegment { .. })).map(|(at, _)| at).collect();
|
||||
let picture = picture.expect("the picture paints");
|
||||
assert!(!edges.is_empty(), "the page's edge paints");
|
||||
assert!(edges.iter().all(|edge| *edge < picture), "the edge {edges:?} paints before the picture at {picture}");
|
||||
}
|
||||
|
||||
/// The picture's own colour.
|
||||
const PICTURE: Color32 = Color32::from_rgb(204, 128, 77);
|
||||
|
||||
/// The shapes of a frame of a canvas whose body shows a pasteboard with `pages` and `uncovered`, then a picture in
|
||||
/// the canvas's slot that fills the canvas with [`PICTURE`].
|
||||
fn slot_canvas(view: CanvasView, pages: Vec<PageFrame>, uncovered: Vec<Rect64>) -> Vec<Shape> {
|
||||
/// The shapes of a frame of a canvas whose body shows a pasteboard with `pages`, `uncovered` and `border`, then a
|
||||
/// picture in the canvas's slot that fills the canvas with [`PICTURE`].
|
||||
fn slot_canvas(view: CanvasView, pages: Vec<PageFrame>, uncovered: Vec<Rect64>, border: PageBorder) -> Vec<Shape> {
|
||||
let size = PixelSize::new(400, 300);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
Canvas::new("Document").view(view).show(ui, |ui, body| {
|
||||
let _ = Pasteboard::new("Pasteboard", &pages).uncovered(&uncovered).show_at(ui, body.rect);
|
||||
let _ = Pasteboard::new("Pasteboard", &pages).uncovered(&uncovered).border(border).show_at(ui, body.rect);
|
||||
let paint = AppPaint::new(|painter, view: CanvasView| {
|
||||
painter.painter.add(Shape::rect_filled(view.rect, 0.0, PICTURE));
|
||||
});
|
||||
|
||||
@@ -208,6 +208,52 @@ fn labels_that_do_not_fit_between_labelled_ticks_are_left_out() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A host table that labels every unit and ticks its halves.
|
||||
fn every_unit_halved(_: f64) -> (f64, u32) {
|
||||
(1.0, 2)
|
||||
}
|
||||
|
||||
/// A two-digit number stacked down the vertical strip reaches the half-unit tick, which would cut it in two. The
|
||||
/// rulers leave out a stacked number a tick runs into; the level two-digit labels across the top stay.
|
||||
#[trial]
|
||||
fn no_tick_cuts_a_stacked_vertical_label() {
|
||||
let room = Vec2::new(800.0, 900.0);
|
||||
let view = CanvasView::new(Rect::from_min_size(Pos2::ZERO, room), Point::new(0.0, 0.0), 1.0);
|
||||
let text = RulerText::new(RulerUnits::new(2.54 / 72.0, Ticks::Custom(every_unit_halved)), UnitKind::Centimetres);
|
||||
let content = Rc::new(Cell::new(Rect::NOTHING));
|
||||
let seen = Rc::clone(&content);
|
||||
let mut zero = Point::ZERO;
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let strips = Rulers::new("Rulers", Bind::bound(&mut zero));
|
||||
let shown = Canvas::new("Document").view(view).with_rulers(Some(strips)).rulers(text, text).show(ui, |_, _| {});
|
||||
if let Some(rulers) = shown.output.rulers {
|
||||
seen.set(rulers.content_rect());
|
||||
}
|
||||
});
|
||||
fixture.room(room);
|
||||
fixture.settle();
|
||||
let content = content.get();
|
||||
let (top, left) = (|rect: &Rect| rect.max.y <= content.min.y + 0.5, |rect: &Rect| rect.max.x <= content.min.x + 0.5);
|
||||
let runs: Vec<(Rect, String)> =
|
||||
fixture.texts().iter().filter(|run| top(&run.rect) || left(&run.rect)).map(|run| (run.rect, run.text.clone())).collect();
|
||||
let ticks: Vec<Rect> = fixture
|
||||
.frame_shapes()
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
Shape::LineSegment { points, .. } => Some(Rect::from_two_pos(points[0], points[1])),
|
||||
_ => None,
|
||||
})
|
||||
// The painter clips the strip's ticks to it, off the corner box.
|
||||
.filter(|tick| left(tick) && tick.height() < 0.5 && tick.min.y >= content.min.y)
|
||||
.collect();
|
||||
assert!(!ticks.is_empty(), "the vertical strip paints ticks");
|
||||
for (run, label) in runs.iter().filter(|(run, _)| left(run) && run.min.y >= content.min.y) {
|
||||
let crossing: Vec<&Rect> = ticks.iter().filter(|tick| tick.intersects(run.shrink(0.5))).collect();
|
||||
assert!(crossing.is_empty(), "the label {label:?} at {run:?} is crossed by {crossing:?}");
|
||||
}
|
||||
assert!(runs.iter().any(|(run, label)| top(run) && label.len() == 2), "two-digit labels stay across the top: {runs:?}");
|
||||
}
|
||||
|
||||
/// How far past the canvas the tool's fill and the marquee reach.
|
||||
const PAST: f32 = 60.0;
|
||||
|
||||
|
||||
@@ -139,6 +139,35 @@ impl Tick {
|
||||
pub const fn new(at: f32, rank: TickRank) -> Self {
|
||||
Tick { at, rank }
|
||||
}
|
||||
|
||||
/// The ends of this tick's line along `edge` of `rect` in `face`, where [`ticks`] paints it: a minor tick
|
||||
/// `TICK_MINOR` long, a mid one `TICK_MID`, a major one across the whole depth of `rect`. The edge face hangs it
|
||||
/// from `edge`; the centred face centres it on `rect`'s middle line.
|
||||
pub fn span(&self, rect: Rect, edge: TickEdge, face: RulerFace) -> (Pos2, Pos2) {
|
||||
let depth = match edge {
|
||||
TickEdge::Bottom | TickEdge::Top => rect.height(),
|
||||
TickEdge::Left | TickEdge::Right => rect.width(),
|
||||
};
|
||||
let length = match self.rank {
|
||||
TickRank::Minor => TICK_MINOR,
|
||||
TickRank::Mid => TICK_MID,
|
||||
TickRank::Major => depth,
|
||||
};
|
||||
match (face, edge) {
|
||||
(RulerFace::Edge, TickEdge::Bottom) => (pos2(rect.left() + self.at, rect.bottom()), pos2(rect.left() + self.at, rect.bottom() - length)),
|
||||
(RulerFace::Edge, TickEdge::Top) => (pos2(rect.left() + self.at, rect.top()), pos2(rect.left() + self.at, rect.top() + length)),
|
||||
(RulerFace::Edge, TickEdge::Left) => (pos2(rect.left(), rect.top() + self.at), pos2(rect.left() + length, rect.top() + self.at)),
|
||||
(RulerFace::Edge, TickEdge::Right) => (pos2(rect.right(), rect.top() + self.at), pos2(rect.right() - length, rect.top() + self.at)),
|
||||
(RulerFace::Centred, TickEdge::Bottom | TickEdge::Top) => {
|
||||
let (x, y) = (rect.left() + self.at, rect.center().y);
|
||||
(pos2(x, y - length / 2.0), pos2(x, y + length / 2.0))
|
||||
}
|
||||
(RulerFace::Centred, TickEdge::Left | TickEdge::Right) => {
|
||||
let (x, y) = (rect.center().x, rect.top() + self.at);
|
||||
(pos2(x - length / 2.0, y), pos2(x + length / 2.0, y))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The cells of the transparency checkerboard: their side and the two colours. A field left unset takes the
|
||||
@@ -714,39 +743,14 @@ pub fn grid_lines_with(look: &GridLook, grid: &GridLines, ink: &GridInk, pixels_
|
||||
shapes
|
||||
}
|
||||
|
||||
/// The tick marks of `ticks` along `edge` of `rect` that `clip` shows, `stroke.thin` lines of `text.faint`: minor ones
|
||||
/// `TICK_MINOR` long, mid ones `TICK_MID`, major ones across the whole depth of `rect`. The edge
|
||||
/// face hangs them from `edge`; the centred face centres them on `rect`'s middle line (`rect` is then the face's bar).
|
||||
/// The tick marks of `ticks` along `edge` of `rect` that `clip` shows, `stroke.thin` lines of `text.faint`, each where
|
||||
/// [`Tick::span`] puts it (`rect` is the centred face's bar).
|
||||
pub fn ticks(tokens: &UiTokens, rect: Rect, edge: TickEdge, face: RulerFace, ticks: &[Tick], clip: Rect, pixels_per_point: f32) -> Vec<Shape> {
|
||||
let look = RuleLook { color: rgba_color(tokens.color.text.faint), width: RuleWidth::Points(tokens.stroke.thin) };
|
||||
let depth = match edge {
|
||||
TickEdge::Bottom | TickEdge::Top => rect.height(),
|
||||
TickEdge::Left | TickEdge::Right => rect.width(),
|
||||
};
|
||||
ticks
|
||||
.iter()
|
||||
.filter_map(|tick| {
|
||||
let length = match tick.rank {
|
||||
TickRank::Minor => TICK_MINOR,
|
||||
TickRank::Mid => TICK_MID,
|
||||
TickRank::Major => depth,
|
||||
};
|
||||
let (from, to) = match (face, edge) {
|
||||
(RulerFace::Edge, TickEdge::Bottom) => {
|
||||
(pos2(rect.left() + tick.at, rect.bottom()), pos2(rect.left() + tick.at, rect.bottom() - length))
|
||||
}
|
||||
(RulerFace::Edge, TickEdge::Top) => (pos2(rect.left() + tick.at, rect.top()), pos2(rect.left() + tick.at, rect.top() + length)),
|
||||
(RulerFace::Edge, TickEdge::Left) => (pos2(rect.left(), rect.top() + tick.at), pos2(rect.left() + length, rect.top() + tick.at)),
|
||||
(RulerFace::Edge, TickEdge::Right) => (pos2(rect.right(), rect.top() + tick.at), pos2(rect.right() - length, rect.top() + tick.at)),
|
||||
(RulerFace::Centred, TickEdge::Bottom | TickEdge::Top) => {
|
||||
let (x, y) = (rect.left() + tick.at, rect.center().y);
|
||||
(pos2(x, y - length / 2.0), pos2(x, y + length / 2.0))
|
||||
}
|
||||
(RulerFace::Centred, TickEdge::Left | TickEdge::Right) => {
|
||||
let (x, y) = (rect.center().x, rect.top() + tick.at);
|
||||
(pos2(x - length / 2.0, y), pos2(x + length / 2.0, y))
|
||||
}
|
||||
};
|
||||
let (from, to) = tick.span(rect, edge, face);
|
||||
clip.intersects(Rect::from_two_pos(from, to)).then(|| Rule::shapes(&look, from, to, pixels_per_point))
|
||||
})
|
||||
.flatten()
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, FocusLook, GlyphRole, StyleCx};
|
||||
use craft_behavior::fit::{FitItem, FitKeep, fit_items};
|
||||
use craft_behavior::{Axis, IconId, Metrics, NavShape, PartKey, PartRef, Proposal, Roving, Sense};
|
||||
use craft_theme::Variant;
|
||||
use craft_theme::{Flags, Variant};
|
||||
use egui::{Rect, Response, Vec2, pos2};
|
||||
|
||||
const ITEM: PartKey = PartKey::new("item");
|
||||
@@ -439,7 +439,11 @@ impl Component for BarItems {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let part = cx.part(ITEM.at(index as u64), cell).sense(sense).focusable();
|
||||
let mut part = cx.part(ITEM.at(index as u64), cell).sense(sense).focusable();
|
||||
// A toggle item's face paints on, and its node reads on, from the part's state.
|
||||
if present[index].resolved.checked == Some(true) {
|
||||
part = part.flags(Flags::CHECKED);
|
||||
}
|
||||
if let Some(tooltip) = tooltip {
|
||||
part.tooltip(tooltip);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,8 @@ impl Component for ListRow<'_> {
|
||||
tone => row_ink_of(cx, cx.tone(tone), form),
|
||||
},
|
||||
),
|
||||
toggle: IconLook::new(sizes.icon, quiet_row_ink(cx, form, text.muted)),
|
||||
// A dimmed row's toggles dim with its name: the children of a hidden group read hidden all along the row.
|
||||
toggle: IconLook::new(sizes.icon, quiet_row_ink(cx, form, muted)),
|
||||
toggle_off: IconLook::new(sizes.icon, quiet_row_ink(cx, form, text.faint)),
|
||||
detail: TextLook::new(TypeRole::Caption, ink(text.faint)),
|
||||
cell: TextLook::new(role, ink(base)),
|
||||
|
||||
@@ -1356,6 +1356,48 @@ fn a_toggle_glyph_rests_muted_and_reads_normal_under_the_pointer() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A dimmed row (a shape inside a hidden group) rests its on toggle in `text.faint` with its name, not in the
|
||||
/// `text.muted` of an ordinary row's toggle.
|
||||
#[trial]
|
||||
fn a_dimmed_rows_toggle_glyph_rests_faint() {
|
||||
use craft_behavior::{ColumnKey, ColumnWidth};
|
||||
use craft_ui::contract::{ColumnSpec, ToggleColumn};
|
||||
use craft_ui::list::{RowInk, ToggleCell};
|
||||
use craft_ui::runtime::env::Env;
|
||||
use egui::Color32;
|
||||
use std::cell::Cell;
|
||||
const EYE: ColumnKey = ColumnKey::new("eye");
|
||||
const NAME: ColumnKey = ColumnKey::new("name");
|
||||
let seen = Rc::new(Cell::new((egui::Rect::NOTHING, Color32::TRANSPARENT)));
|
||||
let held = seen.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let text = Env::of(ui).tokens.tokens().color.text;
|
||||
let [r, g, b, a] = text.faint.0;
|
||||
let columns = vec![ColumnSpec::toggle(EYE, "", ToggleColumn::sweepable()), ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0))];
|
||||
let keys = [0_usize];
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
let _ = List::new("Layers").columns(columns).show_items(ui, &source, &mut |key, icx| {
|
||||
held.set((icx.cell(&EYE).unwrap_or(egui::Rect::NOTHING), Color32::from_rgba_unmultiplied(r, g, b, a)));
|
||||
ListRow::new(NAMES[*key]).cells(icx.cells()).toggle(ToggleCell::eye(EYE, true)).ink(RowInk::Dimmed)
|
||||
});
|
||||
});
|
||||
fixture.room(Vec2::new(300.0, 200.0));
|
||||
fixture.settle();
|
||||
let (cell, faint) = seen.get();
|
||||
let mut tints: Vec<Color32> = fixture
|
||||
.frame_shapes()
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
egui::Shape::Mesh(mesh) if cell.contains(mesh.calc_bounds().center()) => Some(mesh.vertices.iter().map(|vertex| vertex.color)),
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.filter(|color| color.a() > 0)
|
||||
.collect();
|
||||
tints.dedup();
|
||||
assert!(!tints.is_empty() && tints.iter().all(|tint| *tint == faint), "the dimmed row's eye rests in text.faint {faint:?}: {tints:?}");
|
||||
}
|
||||
|
||||
/// Two rows whose eye cell is on and whose lock cell is off; the source does not flip the first row's cells.
|
||||
struct LockedFirst;
|
||||
|
||||
|
||||
Reference in new issue
Block a user