mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 22:39:07 +00:00
Merge pull request #9244 from dotCooCoo/fix/ui-port-painter-tokens
Previews: hand-drawn previews take the theme's sizes, colors and stroke widths
This commit is contained in:
@@ -34,7 +34,7 @@ use craft::ui::layout_components::Row;
|
||||
use craft::ui::list::{ThumbAspect, ThumbSize};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::ContentPainterCx;
|
||||
use craft::ui::primitives::{ContentPainterCx, StrokeWidth};
|
||||
use craft::ui::runtime::env::{Label, UnitKind};
|
||||
use craft::ui::text::NumberField;
|
||||
use egui::{Color32, Rect, Stroke, pos2, vec2};
|
||||
@@ -612,14 +612,26 @@ pub(super) fn stroke_preview(cx: &ContentPainterCx, rect: Rect, doc: Option<&Doc
|
||||
crate::panels::brushes::paint_definition(cx, rect, doc, &Value::Object(def));
|
||||
}
|
||||
|
||||
/// The nib preview's paper, white like the brush previews'.
|
||||
const NIB_PAPER: Color32 = Color32::WHITE;
|
||||
/// The nib at the brush's values, black on the paper.
|
||||
const NIB_INK: Color32 = Color32::BLACK;
|
||||
/// The nib preview's center lines, a light gray on its white paper.
|
||||
const NIB_GUIDE: Color32 = Color32::from_gray(220);
|
||||
/// The nib preview's lightest and heaviest nibs, in a gray behind the black nib at the brush's values.
|
||||
const NIB_RANGE: Color32 = Color32::from_gray(200);
|
||||
/// The room the nib preview keeps between its largest nib and each edge, in points.
|
||||
const NIB_MARGIN: f32 = 6.0;
|
||||
|
||||
/// The nib of `c` at its values (black), and — for values that vary — at their lightest and
|
||||
/// heaviest (grey), on white like the brush previews, its largest nib filling the box.
|
||||
fn nib_preview(cx: &ContentPainterCx, r: Rect, c: &Calligraphic) {
|
||||
let p = &cx.painter;
|
||||
p.rect_filled(r, 0.0, Color32::WHITE);
|
||||
let guide = Stroke::new(1.0, Color32::from_gray(220));
|
||||
p.line_segment([pos2(r.left(), r.center().y), pos2(r.right(), r.center().y)], guide);
|
||||
p.line_segment([pos2(r.center().x, r.top()), pos2(r.center().x, r.bottom())], guide);
|
||||
let guide = Stroke::new(cx.stroke_width(StrokeWidth::Thin), NIB_GUIDE);
|
||||
cx.data_shapes([
|
||||
egui::Shape::rect_filled(r, 0.0, NIB_PAPER),
|
||||
egui::Shape::line_segment([pos2(r.left(), r.center().y), pos2(r.right(), r.center().y)], guide),
|
||||
egui::Shape::line_segment([pos2(r.center().x, r.top()), pos2(r.center().x, r.bottom())], guide),
|
||||
]);
|
||||
let values = [c.angle, c.roundness, c.size];
|
||||
let at = |sign: f64| -> [f64; 3] {
|
||||
let mut v = values;
|
||||
@@ -633,9 +645,10 @@ fn nib_preview(cx: &ContentPainterCx, r: Rect, c: &Calligraphic) {
|
||||
};
|
||||
let nibs = [at(-1.0), at(1.0), values];
|
||||
let largest = nibs.iter().map(|n| n[2]).fold(0.0, f64::max).max(1e-6);
|
||||
let scale = (r.height().min(r.width()) - 12.0) / largest as f32;
|
||||
let scale = (r.height().min(r.width()) - 2.0 * NIB_MARGIN) / largest as f32;
|
||||
let mut shapes = Vec::with_capacity(nibs.len());
|
||||
for (k, [angle, round, size]) in nibs.into_iter().enumerate() {
|
||||
let fill = if k < 2 { Color32::from_gray(200) } else { Color32::BLACK };
|
||||
let fill = if k < 2 { NIB_RANGE } else { NIB_INK };
|
||||
let (a, b) = ((size as f32 * scale / 2.0).max(0.5), (size * round.clamp(1.0, 100.0) / 100.0) as f32 * scale / 2.0);
|
||||
let th = (angle as f32).to_radians();
|
||||
let (u, v) = (vec2(th.cos(), -th.sin()), vec2(th.sin(), th.cos()));
|
||||
@@ -645,8 +658,9 @@ fn nib_preview(cx: &ContentPainterCx, r: Rect, c: &Calligraphic) {
|
||||
r.center() + u * (a * s.cos()) + v * (b.max(0.5) * s.sin())
|
||||
})
|
||||
.collect();
|
||||
p.add(egui::Shape::convex_polygon(pts, fill, Stroke::NONE));
|
||||
shapes.push(egui::Shape::convex_polygon(pts, fill, Stroke::NONE));
|
||||
}
|
||||
cx.data_shapes(shapes);
|
||||
}
|
||||
|
||||
/// OK: edit the brush (and rename it). A name another brush has, or a new bristle brush name that
|
||||
|
||||
@@ -21,10 +21,12 @@
|
||||
// of the draw crate is where `TipEllipse` and `TipAngle` live.
|
||||
use craft::draw::ui::brush_settings::{TipAngle, TipEllipse};
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::display::{Picture, PictureSize};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::list::{ThumbAspect, ThumbSize};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind};
|
||||
use craft::ui::runtime::env::{Env, UnitKind};
|
||||
use craft::ui::style::rgba_color;
|
||||
use craft::ui::primitives::{ContentPainterCx, PaintShape};
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use craft::ui::text::NumberField;
|
||||
use craft::ui::value_drag::{Slider, SliderScale};
|
||||
use egui::{Response, Ui};
|
||||
@@ -69,9 +71,6 @@ const KEYS: [&str; 18] = [
|
||||
/// and the field takes up to 100.
|
||||
const FIDELITY_MAX: f64 = 20.0;
|
||||
|
||||
/// Half the length of a tip in its dabs, in points.
|
||||
const DAB_LONG: f32 = 18.0;
|
||||
|
||||
/// Fidelity `v` stepped `n` steps by the slider's and the field's keys: an arrow steps hundredths up to 0.1,
|
||||
/// tenths up to 1 and whole units above, in the tool's unit (a step down from 0.1 or 1 takes the finer step below
|
||||
/// it); ten steps at once (Shift with an arrow, Page Up/Down) multiply or divide by ten, so they go
|
||||
@@ -175,27 +174,34 @@ fn tip_row(ui: &mut Ui, fields: &mut DialogFields, least: f64) -> Response {
|
||||
shown.output
|
||||
}
|
||||
|
||||
/// Three dabs of `tip`, as a stroke of it lays them down.
|
||||
// PLAN: a `Picture::painter` replaces the plain allocation once its `ThumbAspect` is known to this set.
|
||||
/// Three dabs of `tip`, as a stroke of it lays them down: a picture seven tip halves wide and two high, at the
|
||||
/// small sample size, each dab as long as the picture is high.
|
||||
fn dabs(ui: &mut Ui, tip: TipAngle) {
|
||||
let tokens = Env::of(ui).tokens.clone();
|
||||
let (dim, ink) = (rgba_color(tokens.color.text.muted), rgba_color(tokens.color.text.normal));
|
||||
let long = DAB_LONG;
|
||||
let (response, painter) = ui.allocate_painter(egui::vec2(7.0 * long, 2.0 * long), egui::Sense::hover());
|
||||
// Decorative: the Tip control beside it is the row's accessible control.
|
||||
Picture::painter("", ThumbAspect::new(7, 2), move |cx, rect| paint_dabs(cx, rect, tip)).extent(PictureSize::Sample(ThumbSize::Small)).show(ui);
|
||||
}
|
||||
|
||||
/// Paints three dabs of `tip` across `rect`, the middle one in the text color and the outer two in the muted one.
|
||||
fn paint_dabs(cx: &ContentPainterCx<'_>, rect: egui::Rect, tip: TipAngle) {
|
||||
let style = cx.style_cx();
|
||||
let (dim, ink) = (style.color(style.tokens.color.text.muted), style.color(style.tokens.color.text.normal));
|
||||
let long = rect.height() / 2.0;
|
||||
let a = tip.degrees.clamp(-180.0, 180.0).to_radians();
|
||||
let u = egui::vec2(a.cos() as f32, -a.sin() as f32);
|
||||
let v = egui::vec2(-u.y, u.x);
|
||||
let short = long * (tip.roundness.clamp(0.0, 1.0) as f32).max(0.001);
|
||||
for (i, color) in [dim, ink, dim].into_iter().enumerate() {
|
||||
let center = egui::pos2(response.rect.min.x + long + i as f32 * 2.5 * long, response.rect.center().y);
|
||||
let points = (0..32)
|
||||
.map(|k| {
|
||||
let s = std::f32::consts::TAU * k as f32 / 32.0;
|
||||
center + u * (long * s.cos()) + v * (short * s.sin())
|
||||
})
|
||||
.collect();
|
||||
painter.add(egui::Shape::convex_polygon(points, color, egui::Stroke::NONE));
|
||||
}
|
||||
cx.with_draw(|draw| {
|
||||
for (i, color) in [dim, ink, dim].into_iter().enumerate() {
|
||||
let center = egui::pos2(rect.min.x + long + i as f32 * 2.5 * long, rect.center().y);
|
||||
let points = (0..32)
|
||||
.map(|k| {
|
||||
let s = std::f32::consts::TAU * k as f32 / 32.0;
|
||||
center + u * (long * s.cos()) + v * (short * s.sin())
|
||||
})
|
||||
.collect();
|
||||
draw.fill(&PaintShape::Polygon(points), color);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The rows of tool `tool`'s dialog: those of `present` (the option keys the tool reports), in the order the
|
||||
|
||||
@@ -158,6 +158,35 @@ fn map_art_maps_a_symbol_onto_a_surface_of_extrude_and_bevel_classic() {
|
||||
assert!(params.get("__mapArt").is_none() && params.get("__mapSurface").is_none(), "the dialog's own state stays out of the effect");
|
||||
}
|
||||
|
||||
/// The theme's plot size, as a pass of the app's interface resolves it.
|
||||
fn plot_size() -> egui::Vec2 {
|
||||
let mut plot = None;
|
||||
crate::testing::ui_context()
|
||||
.run_ui(Default::default(), |ui| {
|
||||
let size = craft::ui::runtime::env::Env::of(ui).tokens.size.plot;
|
||||
plot = Some(vec2(size.width, size.height));
|
||||
})
|
||||
.textures_delta
|
||||
.clear();
|
||||
plot.expect("the pass ran")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_art_surface_preview_takes_the_themes_plot_size() {
|
||||
let mut h = opened(with_symbol("M50 50L150 50L150 150L50 150Z"), json!({"effect":CLASSIC_EXTRUDE,"item":null}));
|
||||
h.set("__page", json!("mapArt"));
|
||||
let plot = plot_size();
|
||||
let tree = h.fixture.tree();
|
||||
let surface = h
|
||||
.fixture
|
||||
.by_role(craft::ui::contract::Role::CANVAS)
|
||||
.into_iter()
|
||||
.find(|t| tree.name_of(t.node) == Some("Surface"))
|
||||
.expect("Map Art shows the surface canvas");
|
||||
assert_eq!(surface.rect.height(), plot.y, "the preview is as tall as the theme's plot: {:?}", surface.rect);
|
||||
assert!(surface.rect.width() >= plot.x, "the preview is at least as wide as the theme's plot: {:?}", surface.rect);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_art_maps_no_more_surfaces_than_an_object_takes() {
|
||||
let max = vectorcraft_effects::MAX_MAPS;
|
||||
|
||||
@@ -19,9 +19,10 @@ use craft::ui::contract::{
|
||||
Remember as _, Role, Show as _,
|
||||
};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog};
|
||||
use craft::ui::primitives::{ContentPainterCx, TextRun};
|
||||
use craft::ui::runtime::focus::KeyUse;
|
||||
use craft::ui::style::{ComponentStyle, StyleColor, StyleCx};
|
||||
use egui::{Align2, FontId, Painter, Pos2, Rect, Response, Stroke, Ui, Vec2, vec2};
|
||||
use craft::ui::style::{ComponentStyle, StyleColor, StyleCx, TypeRole};
|
||||
use egui::{Pos2, Rect, Response, Stroke, Ui, Vec2, vec2};
|
||||
use serde_json::json;
|
||||
use vectorcraft_effects::{CLASSIC_REVOLVE, REVOLVE};
|
||||
use vectorcraft_geom::Point;
|
||||
@@ -39,6 +40,8 @@ const RING_REACH: f32 = 9.0;
|
||||
const ORBIT_REACH: f32 = 14.0;
|
||||
/// How far from the light's handle a press takes it, in points.
|
||||
const LIGHT_REACH: f32 = 18.0;
|
||||
/// The least radius of the plate under an axis letter, in points; a taller letter gets a plate as tall as its line.
|
||||
const AXIS_PLATE: f32 = 9.0;
|
||||
|
||||
const RING: PartKey = PartKey::new("ring");
|
||||
const CENTRE: PartKey = PartKey::new("centre");
|
||||
@@ -568,7 +571,7 @@ impl Component for RevolveGizmo<'_> {
|
||||
let Some(g) = Geometry::new(&space.view, &self.subject.fields, self.subject.bounds) else { return };
|
||||
let content = ui.content_painter(cx);
|
||||
let paint = Paint {
|
||||
painter: &content.painter,
|
||||
content: &content,
|
||||
style: cx.style,
|
||||
view: &space.view,
|
||||
subject: self.subject,
|
||||
@@ -606,7 +609,8 @@ fn light_position(g: Geometry, options: Revolve) -> Pos2 {
|
||||
|
||||
/// What a pass draws with.
|
||||
struct Paint<'a> {
|
||||
painter: &'a Painter,
|
||||
/// The content painter: its `painter` draws the rings and plates, and its `Draw` lays out and paints the labels.
|
||||
content: &'a ContentPainterCx<'a>,
|
||||
style: &'a RevolveGizmoStyle,
|
||||
view: &'a CanvasView,
|
||||
subject: &'a Subject,
|
||||
@@ -620,10 +624,11 @@ struct Paint<'a> {
|
||||
|
||||
impl Paint<'_> {
|
||||
fn rotation(&self) {
|
||||
let (g, s, painter) = (self.g, self.style, self.painter);
|
||||
let (g, s, painter) = (self.g, self.style, &self.content.painter);
|
||||
for (axis, ring) in g.rings.iter().enumerate() {
|
||||
let hot = self.active == Some(axis);
|
||||
let color = if hot { s.hot.egui() } else { s.axis(axis).egui() };
|
||||
let ink = if hot { s.hot } else { s.axis(axis) };
|
||||
let color = ink.egui();
|
||||
for i in 0..SAMPLES {
|
||||
let angle = i as f32 * std::f32::consts::TAU / SAMPLES as f32;
|
||||
let behind = ring.depth[0] * angle.cos() + ring.depth[1] * angle.sin() < -0.05;
|
||||
@@ -641,8 +646,10 @@ impl Paint<'_> {
|
||||
_ => 4.7,
|
||||
};
|
||||
let p = g.center + ring.point(phase);
|
||||
painter.circle_filled(p, 9.0, s.plate.egui());
|
||||
painter.text(p, Align2::CENTER_CENTER, ["X", "Y", "Z"][axis], FontId::proportional(11.0), color);
|
||||
self.text(["X", "Y", "Z"][axis], ink, |size| {
|
||||
painter.circle_filled(p, (size.max_elem() * 0.5).max(AXIS_PLATE), s.plate.egui());
|
||||
p - size * 0.5
|
||||
});
|
||||
}
|
||||
painter.circle(g.center, 8.0, s.plate.egui().gamma_multiply(0.8), Stroke::new(1.5, s.muted.egui()));
|
||||
painter.line_segment([g.center - vec2(4.0, 0.0), g.center + vec2(4.0, 0.0)], Stroke::new(1.0, s.muted.egui()));
|
||||
@@ -654,12 +661,12 @@ impl Paint<'_> {
|
||||
if let Some(Mode::Ring { axis, .. }) = self.dragging {
|
||||
let degrees = self.values.rotation.get(axis).copied().unwrap_or(0.0);
|
||||
let text = format!("{} {degrees:.1}°", ["X", "Y", "Z"].get(axis).unwrap_or(&""));
|
||||
self.readout(text, g.center + vec2(0.0, g.radius * 1.12 + 18.0), 12.0);
|
||||
self.readout(&text, g.center + vec2(0.0, g.radius * 1.12 + 18.0));
|
||||
}
|
||||
}
|
||||
|
||||
fn light(&self) {
|
||||
let (g, s, painter) = (self.g, self.style, self.painter);
|
||||
let (g, s, painter) = (self.g, self.style, &self.content.painter);
|
||||
let options = light_options(&self.subject.fields);
|
||||
let radius = g.radius * 1.4;
|
||||
painter.circle_stroke(g.center, radius, Stroke::new(1.0, s.muted.egui().gamma_multiply(0.3)));
|
||||
@@ -682,7 +689,7 @@ impl Paint<'_> {
|
||||
let label = labels[axis];
|
||||
painter.rect_filled(label, 4.0, if self.active == Some(axis) { s.plate_hover.egui() } else { s.plate.egui() });
|
||||
let text = if axis == 0 { tl!("Rotation") } else { tl!("Height") };
|
||||
painter.text(label.center(), Align2::CENTER_CENTER, text, FontId::proportional(11.0), s.hot.egui());
|
||||
self.text(text, s.hot, |size| label.center() - size * 0.5);
|
||||
}
|
||||
let p = light_position(g, options);
|
||||
let delta = g.center - p;
|
||||
@@ -710,22 +717,34 @@ impl Paint<'_> {
|
||||
painter.line_segment([p + direction * 13.0, p + direction * 17.0], Stroke::new(1.5, s.hot.egui()));
|
||||
}
|
||||
let name = crate::i18n::tr_ctx(crate::i18n::current(), "lighting", "Light");
|
||||
let galley = painter.layout_no_wrap(name.to_string(), FontId::proportional(11.0), s.hot.egui());
|
||||
let name_pos = p - vec2(galley.size().x * 0.5, 25.0 + galley.size().y);
|
||||
painter.rect_filled(Rect::from_min_size(name_pos - vec2(4.0, 2.0), galley.size() + vec2(8.0, 4.0)), 3.0, s.plate.egui());
|
||||
painter.galley(name_pos, galley, s.hot.egui());
|
||||
self.text(name, s.hot, |size| {
|
||||
let name_pos = p - vec2(size.x * 0.5, 25.0 + size.y);
|
||||
painter.rect_filled(Rect::from_min_size(name_pos - vec2(4.0, 2.0), size + vec2(8.0, 4.0)), 3.0, s.plate.egui());
|
||||
name_pos
|
||||
});
|
||||
if self.dragging.is_some() {
|
||||
let text = format!("{} {:.1}° {} {:.1}°", tl!("Rotation"), self.values.light_rotation, tl!("Height"), self.values.light_height);
|
||||
self.readout(text, g.center + vec2(0.0, radius + 56.0), 11.5);
|
||||
self.readout(&text, g.center + vec2(0.0, radius + 56.0));
|
||||
}
|
||||
}
|
||||
|
||||
/// `text` on a plate centred at `at`.
|
||||
fn readout(&self, text: String, at: Pos2, size: f32) {
|
||||
let (s, painter) = (self.style, self.painter);
|
||||
let galley = painter.layout_no_wrap(text, FontId::proportional(size), s.ink.egui());
|
||||
painter.rect_filled(Rect::from_center_size(at, galley.size() + vec2(14.0, 8.0)), 4.0, s.plate.egui());
|
||||
painter.galley(at - galley.size() * 0.5, galley, s.ink.egui());
|
||||
fn readout(&self, text: &str, at: Pos2) {
|
||||
let (s, painter) = (self.style, &self.content.painter);
|
||||
self.text(text, s.ink, |size| {
|
||||
painter.rect_filled(Rect::from_center_size(at, size + vec2(14.0, 8.0)), 4.0, s.plate.egui());
|
||||
at - size * 0.5
|
||||
});
|
||||
}
|
||||
|
||||
/// Paints `text` in the label type role and `color` at the top left `place` gives for its size; `place` may paint
|
||||
/// what goes under the text.
|
||||
fn text(&self, text: &str, color: StyleColor, place: impl FnOnce(Vec2) -> Pos2) {
|
||||
self.content.with_draw(|draw| {
|
||||
let layout = draw.layout(&TextRun::new(text).role(TypeRole::Label).color(color), f32::INFINITY);
|
||||
let at = place(layout.size());
|
||||
draw.galley(at, &layout);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::patterns::form_dialogs::{CustomContext, DialogFields, FieldValue, HostedParamDialog, Param, ParamKind};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::ContentPainterCx;
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use craft::ui::runtime::env::{Env, UnitKind};
|
||||
use craft::ui::sections::{DialogRole, FooterButton};
|
||||
use craft::ui::style::DataColor;
|
||||
use craft::ui::text::NumberField;
|
||||
@@ -32,6 +32,7 @@ use vectorcraft_effects::{
|
||||
|
||||
use super::revolve::{Place, bevel_row, c3, light_editor};
|
||||
use super::three_d::{Data, with_fields};
|
||||
use super::track_cube::{SHADE_DARK, SHADE_LIGHT};
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// The field that holds the number of the surface Map Art shows.
|
||||
@@ -379,10 +380,11 @@ pub(crate) fn map_done(dialog: &mut HostedParamDialog, effect: &str) {
|
||||
fn flat_view(ui: &mut Ui, fields: &mut DialogFields, flat: &Flat) -> Response {
|
||||
let surface = surface_number(fields);
|
||||
let map = maps_of(fields).into_iter().find(|m| m.surface == surface);
|
||||
let size = vec2(ui.available_width().max(ui.spacing().slider_width), ui.spacing().slider_width); // PLAN: tokens.size.plot
|
||||
let tokens = Env::of(ui).tokens.clone();
|
||||
let size = vec2(ui.available_width().max(tokens.size.plot.width), tokens.size.plot.height);
|
||||
let (room, response) = ui.allocate_exact_size(size, Sense::hover());
|
||||
let (width, height) = (flat.width.max(1e-6), flat.height.max(1e-6));
|
||||
let margin = f64::from(ui.spacing().item_spacing.x) * 2.0;
|
||||
let margin = f64::from(tokens.space.gap.item) * 2.0;
|
||||
let zoom = ((f64::from(room.width()) - margin) / width).min((f64::from(room.height()) - margin) / height).max(1e-6);
|
||||
let view = CanvasView::new(room, Point::ZERO, zoom);
|
||||
let rect = flat.art.map(art_rect);
|
||||
@@ -390,7 +392,7 @@ fn flat_view(ui: &mut Ui, fields: &mut DialogFields, flat: &Flat) -> Response {
|
||||
Canvas::new(tl!("Surface")).view(view).show_at(ui, room, |ui, body| {
|
||||
let corner = |x: f64, y: f64| view.to_screen(Point::new(x, y));
|
||||
let page = egui::Rect::from_two_pos(corner(-width / 2.0, -height / 2.0), corner(width / 2.0, height / 2.0));
|
||||
let fill = if flat.visible { Color32::from_gray(205) } else { Color32::from_gray(90) };
|
||||
let fill = if flat.visible { SHADE_LIGHT } else { SHADE_DARK };
|
||||
if let Some(space) = canvas_space(&body.env) {
|
||||
space.paint_picture(ui.ctx(), vec![egui::Shape::rect_filled(page, 0.0, fill)]);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,12 @@ const CUBE_BOX: f32 = 124.0;
|
||||
const CUBE_HALF: f32 = 25.0;
|
||||
const RING_IN: f32 = 47.0;
|
||||
const RING_OUT: f32 = 60.0;
|
||||
/// The grays the 3D dialogs shade a surface with, the same in every theme: light for the cube's top and bottom faces
|
||||
/// and a Map Art surface the viewer sees, mid for the cube's left and right faces, and dark for its back face and a
|
||||
/// hidden Map Art surface.
|
||||
pub(super) const SHADE_LIGHT: Color32 = Color32::from_gray(205);
|
||||
pub(super) const SHADE_MID: Color32 = Color32::from_gray(155);
|
||||
pub(super) const SHADE_DARK: Color32 = Color32::from_gray(90);
|
||||
/// How far an edge reaches for the pointer (points).
|
||||
const EDGE_REACH: f32 = 5.0;
|
||||
/// Degrees one point of pointer movement turns the cube.
|
||||
@@ -425,12 +431,11 @@ fn paint_cube(painter: &egui::Painter, s: &RowStyle, rect: Rect, m: M3, active:
|
||||
if !face_visible(m, axis, side) {
|
||||
continue;
|
||||
}
|
||||
// PLAN: the gray steps are literals; the data tokens of area plan §2 w3 were not visible to this writer.
|
||||
let fill = match (axis, side) {
|
||||
(2, true) => colors[2],
|
||||
(2, false) => Color32::from_gray(90),
|
||||
(1, _) => Color32::from_gray(205),
|
||||
_ => Color32::from_gray(155),
|
||||
(2, false) => SHADE_DARK,
|
||||
(1, _) => SHADE_LIGHT,
|
||||
_ => SHADE_MID,
|
||||
};
|
||||
let points: Vec<Pos2> = face_corners(axis, side).iter().map(|&i| corner(m, center, i)).collect();
|
||||
painter.add(egui::Shape::convex_polygon(points, fill, Stroke::NONE));
|
||||
|
||||
@@ -20,17 +20,20 @@ use craft::behavior::{EditEvent, GesturePhase, IconId, Selection};
|
||||
use craft::ui::contract::{
|
||||
Bind, DropAt, DropPayload, DropPlace, Entry, ListDrag, MemoProps, PopupKind, ReorderMove, SelectMode, Show as _, ShowContainer as _, Trigger,
|
||||
};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::display::{Divider, Picture, PictureSize};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::{Menu, MenuItem, PanelRow};
|
||||
use craft::ui::patterns::presets::{
|
||||
PickerField, PresetBrowser, PresetDrop, PresetEvent, PresetFns, PresetPicker, PresetReorder, PresetRow, PresetSource, PresetState, PresetView,
|
||||
};
|
||||
use craft::ui::primitives::{
|
||||
ContentPainterCx, IconSpec, Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails,
|
||||
ContentPainterCx, IconSpec, PaintShape, Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails,
|
||||
};
|
||||
use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates};
|
||||
use craft::ui::runtime::env::Env;
|
||||
use craft::ui::sections::{FooterAction, FooterBar, FooterOutput, Panel};
|
||||
use egui::{Color32, Rect, Sense, TextureHandle, Ui, pos2, vec2};
|
||||
use craft::ui::style::DataColor;
|
||||
use egui::{Color32, Rect, TextureHandle, Ui, pos2};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{BlendMode, Color, Paint};
|
||||
use vectorcraft_doc::style_libs::STYLE_LIBRARIES;
|
||||
@@ -130,9 +133,6 @@ fn thumbnails(ctx: &egui::Context, salt: &'static str) -> Thumbnails<StyleKey> {
|
||||
Thumbnails::in_context(ctx, salt, ThumbnailOptions::new())
|
||||
}
|
||||
|
||||
/// Side of the large preview shown while the pointer rests on a style.
|
||||
const LARGE: f32 = 132.0;
|
||||
|
||||
thread_local! {
|
||||
// PLAN: the sheet drops RENDERER, but `render` and `render_object` need one renderer that outlives a call.
|
||||
static RENDERER: RefCell<vectorcraft_render::Renderer> = RefCell::new(vectorcraft_render::Renderer::new());
|
||||
@@ -337,7 +337,7 @@ fn paint_thumb(cx: &ContentPainterCx<'_>, rect: Rect, thumbs: &Thumbnails<StyleK
|
||||
let request = ThumbRequest::for_cell(rect.width().max(rect.height()), ctx.pixels_per_point());
|
||||
let state = thumbs.state(&ctx, source, key, &request, Priority::VISIBLE);
|
||||
if !thumbs.paint(cx, rect, &state, &ThumbPaint::default().checker(false)) {
|
||||
cx.painter.rect_filled(rect, 0.0, Color32::WHITE);
|
||||
cx.with_draw(|draw| draw.data_fill(&PaintShape::Rect(rect, egui::CornerRadius::ZERO), DataColor::new(Color32::WHITE)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,14 +385,23 @@ fn render_object(app: &VectorcraftApp, doc: &Document, n: &Node, g: &GraphicStyl
|
||||
/// The tip over a style: it large, on the selected object when there is one, with its name.
|
||||
fn large_tip(app: &VectorcraftApp, thumbs: &StyleThumbs, ui: &mut Ui, key: &StyleKey) {
|
||||
let Some(i) = thumbs.d.graphic_style_index(key) else { return };
|
||||
let px = (LARGE * ui.ctx().pixels_per_point()).round() as u32;
|
||||
// The preview is a card thumbnail (`size.thumb.card`) wide, and as tall: the tip is that wide, and the square
|
||||
// picture fills it.
|
||||
let side = Env::of(ui).tokens.size.thumb.card;
|
||||
let px = (side * ui.ctx().pixels_per_point()).round() as u32;
|
||||
let look = thumbs.looks.get(i).copied().unwrap_or_default();
|
||||
let tex = object_preview(app, ui.ctx(), &thumbs.d.graphic_styles[i], look, thumbs.look.preview, px);
|
||||
let (r, _) = ui.allocate_exact_size(vec2(LARGE, LARGE), Sense::hover());
|
||||
match &tex {
|
||||
Some(tex) => ui.painter().image(tex.id(), r, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE),
|
||||
None => ui.painter().rect_filled(r, 0.0, Color32::WHITE),
|
||||
};
|
||||
ui.set_max_width(side);
|
||||
let texture = tex.as_ref().map(TextureHandle::id);
|
||||
// Decorative: the style's name below it says what it shows.
|
||||
Picture::painter("", ThumbAspect::SQUARE, move |cx, rect| {
|
||||
cx.with_draw(|draw| match texture {
|
||||
Some(id) => draw.texture(rect, id, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0))),
|
||||
None => draw.data_fill(&PaintShape::Rect(rect, egui::CornerRadius::ZERO), DataColor::new(Color32::WHITE)),
|
||||
})
|
||||
})
|
||||
.extent(PictureSize::Fill)
|
||||
.show(ui);
|
||||
ui.label(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ use craft::ui::contract::{Bind, DropAt, DropPlace, ListDrag, MemoProps, SelectMo
|
||||
use craft::ui::contract::{Entry, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::patterns::presets::{PresetEvent, PresetView, ThumbInfo};
|
||||
use craft::ui::primitives::{ContentPainterCx, Glyph, IconSpec, StrokeWidth};
|
||||
use craft::ui::primitives::{ContentPainterCx, Glyph, IconSpec, PaintShape, StrokeWidth};
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::sections::{FooterAction, FooterBar};
|
||||
use craft::ui::style::UiTokens;
|
||||
use craft::ui::style::{DataColor, UiTokens};
|
||||
use egui::{Color32, Painter, Rect, Response, Shape, Stroke, StrokeKind, Ui, pos2, vec2};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::swatch::REGISTRATION;
|
||||
@@ -543,10 +543,7 @@ pub(super) fn paint_swatch(cx: &ContentPainterCx<'_>, rect: Rect, paint: &Paint,
|
||||
match paint {
|
||||
_ if paint.is_registration() => registration_mark(cx, inner),
|
||||
Paint::Solid { .. } => {}
|
||||
Paint::None => {
|
||||
let slash = Stroke::new(cx.stroke_width(StrokeWidth::Medium), Color32::from_rgb(0xe0, 0x20, 0x20));
|
||||
cx.data_shapes([Shape::line_segment([inner.left_bottom(), inner.right_top()], slash)]);
|
||||
}
|
||||
Paint::None => none_slash(cx, inner),
|
||||
Paint::Pattern { .. } if pattern.is_some_and(|doc| pattern_thumb_in(doc, cx, inner, paint)) => {}
|
||||
_ => crate::paint_preview::paint_rect(cx, inner, paint),
|
||||
}
|
||||
@@ -593,6 +590,15 @@ fn pattern_thumb_in(doc: &Document, cx: &ContentPainterCx<'_>, r: Rect, paint: &
|
||||
true
|
||||
}
|
||||
|
||||
/// The red of None's slash on a swatch tile and of a disabled opacity mask's cross, drawn on the document's white or
|
||||
/// black paper. It is the same in every theme.
|
||||
pub(super) const OFF_MARK: Color32 = Color32::from_rgb(0xe0, 0x20, 0x20);
|
||||
|
||||
/// None's slash across `r`, from its lower left to its upper right, in [`OFF_MARK`] at the medium stroke width.
|
||||
fn none_slash(cx: &ContentPainterCx<'_>, r: Rect) {
|
||||
cx.with_draw(|draw| draw.stroke(&PaintShape::Path(vec![r.left_bottom(), r.right_top()]), StrokeWidth::Medium, DataColor::new(OFF_MARK)));
|
||||
}
|
||||
|
||||
/// Registration's mark: a black target on white.
|
||||
fn registration_mark(cx: &ContentPainterCx<'_>, r: Rect) {
|
||||
let c = r.center();
|
||||
|
||||
@@ -19,13 +19,15 @@ use craft::ui::list::{List, ListRow, RowEvent, ThumbSize, ThumbTarget};
|
||||
use craft::ui::menu::PanelRow;
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::{
|
||||
ContentPainterCx, IconSpec, LoadFailure, LoadedPicture, Priority, ThumbJob, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails,
|
||||
ContentPainterCx, IconSpec, LoadFailure, LoadedPicture, PaintShape, Priority, StrokeWidth, ThumbJob, ThumbRender, ThumbRequest, ThumbSource,
|
||||
ThumbnailOptions, Thumbnails,
|
||||
};
|
||||
use craft::ui::primitives::{Revision, ThumbPaint};
|
||||
use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates};
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use craft::ui::style::DataColor;
|
||||
use craft::ui::text::NumberField;
|
||||
use egui::{Color32, Stroke, Ui};
|
||||
use egui::{Color32, Ui};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{Document, Knockout, Node, NodeId, OpacityMask};
|
||||
use vectorcraft_engine::cmd::TransparencyInfo;
|
||||
@@ -183,8 +185,7 @@ fn mask_row(
|
||||
if !object_state.as_ref().is_some_and(|s| store.paint(cx, rect, s, plain))
|
||||
&& let Some(c) = fill
|
||||
{
|
||||
// PLAN: a colour from data should go through the content painter's data path, not the raw painter.
|
||||
cx.painter.rect_filled(rect.shrink(rect.width() * 0.2), 0.0, c);
|
||||
cx.data_shapes([egui::Shape::rect_filled(rect.shrink(rect.width() * 0.2), 0.0, c)]);
|
||||
}
|
||||
};
|
||||
let paint_mask = move |cx: &ContentPainterCx, rect: egui::Rect| {
|
||||
@@ -193,9 +194,12 @@ fn mask_row(
|
||||
store.paint(cx, rect, s, paper);
|
||||
}
|
||||
if disabled {
|
||||
let red = Stroke::new(2.0, Color32::from_rgb(220, 40, 40));
|
||||
cx.painter.line_segment([rect.left_top(), rect.right_bottom()], red);
|
||||
cx.painter.line_segment([rect.right_top(), rect.left_bottom()], red);
|
||||
let red = DataColor::new(super::swatches::OFF_MARK);
|
||||
cx.with_draw(|draw| {
|
||||
for line in [[rect.left_top(), rect.right_bottom()], [rect.right_top(), rect.left_bottom()]] {
|
||||
draw.stroke(&PaintShape::Path(line.to_vec()), StrokeWidth::Thick, red);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
cx.icon(rect, &IconSpec::svg(IconId::new("dc-mask-none")));
|
||||
|
||||
Reference in New Issue
Block a user