Merge remote-tracking branch 'origin/main' into HEAD

This commit is contained in:
bflatastic committed 2026-11-27 18:05:08 +07:00
commit 77de2d7bb7
14 files changed
+318 -27

No files matched your search

+2
View File
@@ -466,6 +466,7 @@ fn board_commands_survive_junk() {
json!({"id": 99_999, "end": 7, "target": [1], "style": "wavy"}),
json!({"id": 99_999, "relation": 7, "children": "x", "text": [1], "x": "NaN", "y": 1e308}),
json!({"id": 99_999, "language": 7, "text": [1], "width": "wide", "x": "NaN", "y": 1e308, "side": 3}),
json!({"tool": "sticky", "color": "auto", "weight": -1e308}),
];
let ids: Vec<&str> = crate::cmd::all_commands()
.iter()
@@ -479,6 +480,7 @@ fn board_commands_survive_junk() {
"tool.marker",
"tool.highlighter",
"tool.eraser",
"tool.ink",
"tool.stamp",
"tool.mindMap",
"file.newBoard",
+52
View File
@@ -311,3 +311,55 @@ fn a_connector_joined_to_a_moving_layer_or_its_section_is_no_snap_target() {
assert_eq!(pull(&s, &[b], start), 0.0, "not for the layer it arrives at");
assert_eq!((pull(&s, &[sec], start), pull(&s, &[sec], lx)), (0.0, 0.0), "not for the section the connector leaves from");
}
/// The ink chosen for a drawing tool before drawing is the one its new strokes get, each tool
/// keeping its own (#2395); `tool.ink` reads it back and refuses what no tool draws with.
#[test]
fn new_strokes_take_the_ink_chosen_before_drawing() {
use figcraft_color::Color;
use figcraft_doc::{Node, NodeKind};
// A stroke across at height `y` with `tool`; the newest vector afterwards.
let draw = |s: &mut Session, tool: &str, y: f64| -> Node {
s.execute("tool.set", &json!({"tool": tool})).unwrap();
for (k, x) in [(PointerKind::Down, 0.0), (PointerKind::Move, 50.0), (PointerKind::Move, 100.0), (PointerKind::Up, 150.0)] {
s.pointer(&PointerEvent::at(k, x, y, 1.0)).unwrap();
}
s.doc().unwrap().nodes().filter(|n| matches!(n.kind, NodeKind::Vector { .. })).max_by_key(|n| n.id).cloned().unwrap()
};
let color = |n: &Node| n.strokes.first().and_then(|p| p.solid_color());
// The Pencil, in a design file: chosen while it is the tool, so no `tool` is named.
let mut s = Session::new();
let plain = draw(&mut s, "pencil", 0.0);
let r = s.execute("tool.ink", &json!({"color": "blue", "weight": 6})).unwrap();
assert_eq!(r["tool"], "pencil");
let blue = draw(&mut s, "pencil", 100.0);
assert_ne!(color(&blue), color(&plain));
assert_eq!(color(&blue).map(|c| c.to_hex()), r["color"].as_str().map(|h| h.trim_start_matches('#').to_uppercase()));
assert!(blue.stroke.weight > plain.stroke.weight, "{} vs {}", blue.stroke.weight, plain.stroke.weight);
// A chosen colour holds on a dark page; auto goes back to white there.
s.execute("page.setBackground", &json!({"color": "#1E1E1E"})).unwrap();
assert_eq!(color(&draw(&mut s, "pencil", 200.0)), color(&blue));
s.execute("tool.ink", &json!({"tool": "pencil", "color": "auto"})).unwrap();
assert_eq!(color(&draw(&mut s, "pencil", 300.0)), Some(Color::WHITE));
// The Marker and Highlighter on a board, each with its own ink.
let mut s = board();
let marker = draw(&mut s, "marker", 0.0);
s.execute("tool.ink", &json!({"tool": "highlighter", "color": "#336699", "weight": 40})).unwrap();
let high = draw(&mut s, "highlighter", 100.0);
assert_eq!(color(&high).map(|c| c.to_hex()).as_deref(), Some("336699"));
assert!(high.stroke.weight > 20.0);
let marker2 = draw(&mut s, "marker", 200.0);
assert_eq!((color(&marker2), marker2.stroke.weight), (color(&marker), marker.stroke.weight), "the marker keeps its own ink");
assert_eq!(s.execute("tool.ink", &json!({"tool": "highlighter"})).unwrap()["weight"], 40.0, "read back");
// A stroke made headless takes the tool's ink too.
let r = s.execute("board.ink", &json!({"points": [[0, 400], [100, 400]], "highlighter": true})).unwrap();
assert_eq!(node(&s, id(&r, "id")).stroke.weight, 40.0);
// Refusals: a tool that draws no ink, a weight out of range, auto for a board tool.
for bad in [json!({"tool": "sticky", "color": "red"}), json!({"tool": "marker", "weight": 0}), json!({"tool": "marker", "color": "auto"})] {
assert!(s.execute("tool.ink", &bad).is_err(), "{bad}");
}
s.execute("tool.set", &json!({"tool": "move"})).unwrap();
assert!(s.execute("tool.ink", &json!({"color": "red"})).is_err(), "the Move tool draws no ink");
}
+73 -2
View File
@@ -99,6 +99,19 @@ const LINE_WEIGHT: f64 = 2.0;
/// Marker and highlighter strokes: (weight, opacity).
const MARKER: (f64, f32) = (4.0, 1.0);
const HIGHLIGHTER: (f64, f32) = (20.0, 0.45);
/// The ink colours the drawing tools offer (`tool.ink`): name and colour.
pub const INK_COLORS: [(&str, Color); 8] = [
("black", INK),
("gray", Color::from_rgb8_const(0x8A, 0x88, 0x83)),
("red", Color::from_rgb8_const(0xE0, 0x3E, 0x3E)),
("orange", Color::from_rgb8_const(0xF2, 0x86, 0x1F)),
("yellow", Color::from_rgb8_const(0xFF, 0xD2, 0x1F)),
("green", Color::from_rgb8_const(0x2F, 0xA8, 0x4F)),
("blue", Color::from_rgb8_const(0x2D, 0x7F, 0xF9)),
("violet", Color::from_rgb8_const(0x8B, 0x5C, 0xF6)),
];
/// The stroke weights `tool.ink` takes.
pub const INK_WEIGHTS: std::ops::RangeInclusive<f64> = 0.1..=100.0;
/// How far the eraser reaches around the pointer (screen pixels).
const ERASER_PX: f64 = 8.0;
/// The text sizes the contextual bar offers.
@@ -107,7 +120,7 @@ pub const TEXT_SIZES: [(&str, f64); 4] = [("S", 12.0), ("M", 16.0), ("L", 24.0),
pub const STICKY_SIZES: [(&str, f64); 5] = [("Small", 16.0), ("Medium", 24.0), ("Large", 40.0), ("Extra large", 64.0), ("Huge", 96.0)];
/// The board tools' choices: the colour new stickies get, the shape and stamp the tools place,
/// how new connectors run and the marker's and highlighter's colours.
/// how new connectors run and the marker's and highlighter's colours and weights.
#[derive(Clone, Debug)]
pub struct BoardTool {
pub sticky: Color,
@@ -118,6 +131,8 @@ pub struct BoardTool {
pub routing: Routing,
pub marker: Color,
pub highlighter: Color,
pub marker_weight: f64,
pub highlighter_weight: f64,
}
impl Default for BoardTool {
@@ -131,6 +146,8 @@ impl Default for BoardTool {
routing: Routing::Elbow,
marker: INK,
highlighter: Color::from_rgb8_const(0xFF, 0xD2, 0x1F),
marker_weight: MARKER.0,
highlighter_weight: HIGHLIGHTER.0,
}
}
}
@@ -225,7 +242,7 @@ pub fn specs() -> Vec<CommandSpec> {
spec!(
"board.ink",
"Marker stroke",
"{path (SVG path data on the page) | points [[x,y],..], highlighter? (wide and see-through), color?, select? (default true)} → {id}",
"{path (SVG path data on the page) | points [[x,y],..], highlighter? (wide and see-through), color?, weight? (default the tool's, as tool.ink sets them), select? (default true)} → {id}",
true,
ink_cmd
),
@@ -280,6 +297,13 @@ pub fn specs() -> Vec<CommandSpec> {
}
board_tool(s, ToolId::Highlighter)
}),
spec!(
"tool.ink",
"Ink",
"{tool? (pencil|marker|highlighter; default the current one), color? (black|gray|red|orange|yellow|green|blue|violet or any colour; the Pencil also takes auto: black, or white on a dark page or frame), weight? (0.1 to 100)} → {tool, color, weight} the ink that tool's new strokes get (omit color and weight to read it)",
false,
tool_ink
),
spec!("tool.eraser", "Eraser", "{} (drag over marker and highlighter strokes to remove them)", false, |s, _| board_tool(s, ToolId::Eraser)),
spec!("tool.stamp", "Stamp", "{stamp?} (a click places the stamp)", false, |s, p| {
if let Some(v) = string(p, "stamp") {
@@ -314,6 +338,53 @@ fn board_tool(s: &mut Session, t: ToolId) -> Result<Value> {
crate::cmd::view::tool(s, t)
}
/// `weight`: an ink stroke's weight, in [`INK_WEIGHTS`].
fn weight_param(cmd: &str, p: &Value) -> Result<Option<f64>> {
match num(p, "weight") {
Some(w) if !INK_WEIGHTS.contains(&w) => Err(bad(cmd, "`weight` is 0.1 to 100")),
w => Ok(w),
}
}
/// `tool.ink`: set or read a drawing tool's ink.
fn tool_ink(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "tool.ink";
let tool = match string(p, "tool") {
Some(t) => ToolId::from_id(&t)
.filter(|t| s.tool.ink(*t).is_some())
.ok_or_else(|| bad(cmd, format!("`tool` is pencil, marker or highlighter, not `{t}`")))?,
None if s.tool.ink(s.tool.tool).is_some() => s.tool.tool,
None => return Err(bad(cmd, "name a `tool` (pencil, marker or highlighter): the current tool draws no ink")),
};
let color = match get(p, "color") {
None | Some(Value::Null) => None,
Some(Value::String(v)) if tool == ToolId::Pencil && v.eq_ignore_ascii_case("auto") => Some(None),
Some(v) => {
let named = v.as_str().and_then(|v| INK_COLORS.iter().find(|(n, _)| n.eq_ignore_ascii_case(v))).map(|c| c.1);
Some(Some(named.or_else(|| color_of(v)).ok_or_else(|| bad(cmd, "`color` is an ink colour (black, blue…) or a colour such as #2D7FF9"))?))
}
};
let weight = weight_param(cmd, p)?;
let b = &mut s.tool.board;
match tool {
ToolId::Marker => {
b.marker = color.flatten().unwrap_or(b.marker);
b.marker_weight = weight.unwrap_or(b.marker_weight);
}
ToolId::Highlighter => {
b.highlighter = color.flatten().unwrap_or(b.highlighter);
b.highlighter_weight = weight.unwrap_or(b.highlighter_weight);
}
_ => {
let ink = &mut s.tool.pencil_ink;
ink.color = color.unwrap_or(ink.color);
ink.weight = weight.unwrap_or(ink.weight);
}
}
let ink = s.tool.ink(tool).unwrap_or_default();
Ok(json!({"tool": tool.id(), "color": ink.color.map_or_else(|| "auto".to_string(), |c| c.to_css_hex()), "weight": ink.weight}))
}
fn shape_of(cmd: &str, v: &str) -> Result<BoardShape> {
BoardShape::from_id(v).ok_or_else(|| {
let known: Vec<&str> = BoardShape::ALL.iter().map(|b| b.id()).collect();
+3 -1
View File
@@ -381,7 +381,9 @@ pub(super) fn ink_cmd(s: &mut Session, p: &Value) -> Result<Value> {
require(s, cmd)?;
let high = boolean(p, "highlighter").unwrap_or(false);
let color = color_param(cmd, p)?.unwrap_or(if high { s.tool.board.highlighter } else { s.tool.board.marker });
let (weight, opacity) = if high { HIGHLIGHTER } else { MARKER };
let opacity = if high { HIGHLIGHTER.1 } else { MARKER.1 };
let b = &s.tool.board;
let weight = super::weight_param(cmd, p)?.unwrap_or(if high { b.highlighter_weight } else { b.marker_weight });
if get(p, "path").is_none() && get(p, "points").is_none() {
return Err(bad(cmd, "`path` or `points` is required"));
}
+27
View File
@@ -633,6 +633,8 @@ pub struct ToolState {
pub labels: Vec<(NodeId, [Point; 4])>,
/// The brush the Pencil draws with (`tool.pencilBrush`; `None`: a plain stroke).
pub pencil_brush: Option<figcraft_doc::Brush>,
/// The ink new Pencil strokes get (`tool.ink`).
pub pencil_ink: Ink,
/// The board tools' colours and choices.
pub board: crate::board::BoardTool,
/// The eyedropper samples for a colour picker (`edit.pickColor` with `apply: false`): the
@@ -655,7 +657,32 @@ pub struct ToolState {
pub(crate) selections_before_last_two_presses: [Option<(Point, Vec<NodeId>)>; 2],
}
/// A drawing tool's ink (`tool.ink`): the colour and stroke weight its new strokes get. A colour
/// of `None` is the Pencil's own: black, or white on a dark page or frame (#1741).
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
pub struct Ink {
pub color: Option<figcraft_color::Color>,
pub weight: f64,
}
impl Default for Ink {
fn default() -> Self {
Ink { color: None, weight: PENCIL_STROKE.1 }
}
}
impl ToolState {
/// The ink `tool` draws with now; `None` for a tool that draws no ink.
pub fn ink(&self, tool: ToolId) -> Option<Ink> {
let b = &self.board;
match tool {
ToolId::Pencil => Some(self.pencil_ink),
ToolId::Marker => Some(Ink { color: Some(b.marker), weight: b.marker_weight }),
ToolId::Highlighter => Some(Ink { color: Some(b.highlighter), weight: b.highlighter_weight }),
_ => None,
}
}
pub fn busy(&self) -> bool {
!matches!(self.gesture, Gesture::None)
}
+9 -6
View File
@@ -1,4 +1,4 @@
use super::handles::{PENCIL_STROKE, selected_end_at};
use super::handles::selected_end_at;
use super::{
Affine, Document, Gesture, Guide, Node, NodeId, NodeKind, PenPath, Point, PointerEvent, Result, Session, StrokeAlign, ToolId, Vec2,
VectorNetwork, at_45_degrees, frame_at, json, pen_handles,
@@ -334,9 +334,9 @@ impl Session {
let mut local = fitted.clone();
local.apply_affine(pw.inverse());
let _ = d;
// Black, or white on a dark page or frame (#1741).
let (_, weight) = PENCIL_STROKE;
let color = super::handles::pencil_color(self.doc()?, parent);
// The ink chosen for the Pencil; by default black, or white on a dark page or frame (#1741).
let ink = self.tool.pencil_ink;
let (color, weight) = (ink.color.unwrap_or(super::handles::pencil_color(self.doc()?, parent)), ink.weight);
let mut props = json!({"fills": [], "strokes": [color.to_css_hex()], "strokeWeight": weight, "strokeCap": "round", "strokeJoin": "round", "strokeAlign": "center"});
// Pen pressure becomes the stroke's width profile (brushes follow it too).
if let Some(points) = pressure_profile(points, pressure) {
@@ -352,9 +352,12 @@ impl Session {
Ok(())
}
/// The colour a Pencil stroke starting at `p` will have: it goes into the frame under `p`
/// (else the page), and is white when that is dark (`pencil_color`).
/// The colour a Pencil stroke starting at `p` will have: the one chosen for it, else (it goes
/// into the frame under `p`, else the page) white when that is dark (`pencil_color`).
pub(super) fn pencil_color_at(&self, p: figcraft_geom::Point) -> Result<figcraft_color::Color> {
if let Some(c) = self.tool.pencil_ink.color {
return Ok(c);
}
let page = self.page()?;
let doc = self.doc()?;
let parent = frame_at(doc, page, p, &[]).unwrap_or(page);
+2
View File
@@ -161,6 +161,7 @@ name = "English"
"Auto (space between)" = "Auto (space between)"
"Auto (space evenly)" = "Auto (space evenly)"
"Auto ({mode})" = "Auto ({mode})"
"Auto: black, or white on a dark background" = "Auto: black, or white on a dark background"
"Auto columns" = "Auto columns"
"Auto gap" = "Auto gap"
"Auto height" = "Auto height"
@@ -188,6 +189,7 @@ name = "English"
"Bevel" = "Bevel"
"Binary assets added" = "Binary assets added"
"Binary assets removed" = "Binary assets removed"
"Black" = "Black"
"Black & white" = "Black & white"
"Bleed" = "Bleed"
"Bleed marks" = "Bleed marks"
+1
View File
@@ -43,6 +43,7 @@ pub mod frame_labels;
pub mod frame_stats;
pub mod guides;
pub mod handles;
pub(crate) mod ink_bar;
pub mod live_text;
pub mod measure_overlay;
pub mod proto_canvas;
+18 -11
View File
@@ -66,9 +66,10 @@ pub(crate) fn choices(options: Options, board: &BoardTool, current: ToolId) -> V
}
}
/// A board colour's name as the UI says it.
fn color_label(name: &str) -> &'static str {
/// A board or ink colour's name as the UI says it.
pub(crate) fn color_label(name: &str) -> &'static str {
match name {
"black" => tr_noop("Black"),
"yellow" => tr_noop("Yellow"),
"orange" => tr_noop("Orange"),
"red" => tr_noop("Red"),
@@ -188,8 +189,8 @@ fn has(app: &FigApp) -> Option<Has> {
}
const CELL: f32 = 28.0;
const SWATCH: f32 = 20.0;
const GAP: f32 = 4.0;
pub(crate) const SWATCH: f32 = 20.0;
pub(crate) const GAP: f32 = 4.0;
/// The room each part takes after its controls (the divider and the gap around it).
const PART_END: f32 = 8.0;
/// The sticky size menu's width: its name ("Extra large") and the chevron.
@@ -252,12 +253,7 @@ pub fn show(app: &mut FigApp, ctx: &egui::Context) {
let at = place(sel, size, app.canvas.rect);
let t = Tokens::get(ctx);
egui::Area::new(egui::Id::unique("board_bar")).fixed_pos(at).order(egui::Order::Middle).show(ctx, |ui| {
let (rect, _) = ui.allocate_exact_size(size, Sense::click());
a11y::container_bounds(ui, rect);
let p = ui.painter();
p.rect_filled(rect.expand(2.0).translate(vec2(0.0, 1.0)), CornerRadius::same(12), Color32::from_black_alpha(18));
p.rect_filled(rect, CornerRadius::same(10), t.panel);
p.rect_stroke(rect, CornerRadius::same(10), Stroke::new(1.0, t.border), StrokeKind::Inside);
let rect = bar(ui, size, &t);
let cy = rect.center().y;
let mut x = rect.min.x + 8.0;
if h.color {
@@ -281,6 +277,17 @@ pub fn show(app: &mut FigApp, ctx: &egui::Context) {
});
}
/// A floating bar `size` big where `ui` starts (its shadow, panel and border); its rect.
pub(crate) fn bar(ui: &mut Ui, size: egui::Vec2, t: &Tokens) -> Rect {
let (rect, _) = ui.allocate_exact_size(size, Sense::click());
a11y::container_bounds(ui, rect);
let p = ui.painter();
p.rect_filled(rect.expand(2.0).translate(vec2(0.0, 1.0)), CornerRadius::same(12), Color32::from_black_alpha(18));
p.rect_filled(rect, CornerRadius::same(10), t.panel);
p.rect_stroke(rect, CornerRadius::same(10), Stroke::new(1.0, t.border), StrokeKind::Inside);
rect
}
/// The board colours from `x` (`board.setColor`), and for connectors `lines` any colour in the
/// colour picker; where the next part starts.
fn color_part(app: &mut FigApp, ui: &mut Ui, mut x: f32, cy: f32, t: &Tokens, lines: Option<&[NodeId]>) -> f32 {
@@ -312,7 +319,7 @@ fn color_part(app: &mut FigApp, ui: &mut Ui, mut x: f32, cy: f32, t: &Tokens, li
}
/// A small colour wheel: the button for any colour.
fn paint_wheel(p: &egui::Painter, c: Pos2, r: f32) {
pub(crate) fn paint_wheel(p: &egui::Painter, c: Pos2, r: f32) {
const STEPS: usize = 12;
let at = |i: usize| {
let a = i as f32 / STEPS as f32 * std::f32::consts::TAU;
+101
View File
@@ -0,0 +1,101 @@
//! The ink bar: while the Pencil, Marker or Highlighter is the tool, its colour and stroke weight
//! float above the bottom toolbar, so they are chosen before drawing (#2395; `tool.ink`). Each
//! tool keeps its own for the session.
use egui::{CornerRadius, Id, Rect, Sense, Stroke, StrokeKind, Ui, UiBuilder, pos2, vec2};
use figcraft_engine::ToolId;
use figcraft_engine::board::{INK_COLORS, INK_WEIGHTS};
use serde_json::json;
use crate::FigApp;
use crate::a11y::{self, Region};
use crate::board_bar::{GAP, Mark, SWATCH, bar, color_label, divider, paint_choice, paint_wheel};
use crate::colorpicker::PickerTarget;
use crate::i18n::tr;
use crate::icons::Icon;
use crate::theme::Tokens;
use crate::widgets::{self, Lead};
/// The stroke weight field's width.
const FIELD_W: f32 = 72.0;
const HEIGHT: f32 = 40.0;
/// The ink bar above the toolbar pill at `pill`, while the tool draws ink and no flyout (which
/// opens where the bar sits) is open.
pub(crate) fn show(app: &mut FigApp, ui: &Ui, pill: Rect) {
let tool = app.session.tool.tool;
let Some(ink) = app.session.tool.ink(tool) else { return };
if app.ui.tool_flyout.is_some() {
return;
}
let t = Tokens::get(ui.ctx());
// The Pencil's own colour (black, or white on a dark page or frame) comes first.
let auto = tool == ToolId::Pencil;
let chips = INK_COLORS.len() + 1 + usize::from(auto);
let size = vec2(8.0 + chips as f32 * (SWATCH + GAP) - GAP + 8.0 + FIELD_W + 8.0, HEIGHT);
let at = pos2(pill.center().x - size.x / 2.0, pill.min.y - 8.0 - HEIGHT);
egui::Area::new(Id::unique("ink_bar")).fixed_pos(at).order(egui::Order::Middle).show(ui.ctx(), |ui| {
let rect = bar(ui, size, &t);
a11y::area(&mut app.ui.nav, Region::Toolbar, rect);
let cy = rect.center().y;
let mut x = rect.min.x + 8.0;
// One swatch from `x`: hovered it lifts, the ink's own is ringed.
let mut chip = |ui: &mut Ui, key: usize, label: &str, on: bool| {
let r = Rect::from_center_size(pos2(x + SWATCH / 2.0, cy), vec2(SWATCH, SWATCH));
let resp = ui.interact(r, ui.scope_id().with(("ink", key)), Sense::click()).on_hover_text(label);
a11y::toggle(&resp, label, on);
if on {
ui.painter().rect_stroke(r.expand(3.0), CornerRadius::same(7), Stroke::new(2.0, t.accent), StrokeKind::Inside);
} else if resp.hovered() {
ui.painter().rect_filled(r.expand(2.0), CornerRadius::same(6), t.hover);
}
x += SWATCH + GAP;
(resp, r)
};
let mut chosen = None;
if auto {
let (resp, r) = chip(ui, 0, tr("Auto: black, or white on a dark background"), ink.color.is_none());
let (black, white) = (crate::theme::c32(figcraft_engine::tools::PENCIL_STROKE.0), egui::Color32::WHITE);
let p = ui.painter();
p.rect_filled(r, CornerRadius::same(4), white);
p.rect_filled(Rect::from_min_max(r.min, pos2(r.center().x, r.max.y)), CornerRadius { nw: 4, sw: 4, ne: 0, se: 0 }, black);
p.rect_stroke(r, CornerRadius::same(4), Stroke::new(1.0, t.border), StrokeKind::Inside);
if resp.clicked() {
chosen = Some("auto");
}
}
for (i, (name, c)) in INK_COLORS.iter().enumerate() {
let (resp, r) = chip(ui, i + 1, tr(color_label(name)), ink.color == Some(*c));
paint_choice(ui.painter(), r, &Mark::Color(*c), t.icon);
// Outlined so a dark ink still reads against the dark bar.
ui.painter().rect_stroke(r, CornerRadius::same(4), Stroke::new(1.0, t.border), StrokeKind::Inside);
if resp.clicked() {
chosen = Some(*name);
}
}
let custom = ink.color.is_some_and(|c| !INK_COLORS.iter().any(|(_, k)| *k == c));
let (resp, r) = chip(ui, INK_COLORS.len() + 1, tr("Edit colour"), custom);
paint_wheel(ui.painter(), r.center(), SWATCH / 2.0 - 1.0);
app.picker_control(PickerTarget::Ink { tool }, &resp);
if let Some(color) = chosen {
app.run("tool.ink", json!({"tool": tool.id(), "color": color}));
}
let x = divider(ui, &t, x - GAP, cy);
let field = Rect::from_min_size(pos2(x, cy - 12.0), vec2(FIELD_W, 24.0));
let edit = ui
.scope_builder(UiBuilder::new().max_rect(field), |ui| {
widgets::number_field(
ui,
Id::unique(("ink_weight", tool.id())),
Lead::Icon(Icon::Menu, tr("Stroke weight")),
Some(ink.weight),
"",
FIELD_W,
1.0,
)
})
.inner;
let (lo, hi) = (*INK_WEIGHTS.start(), *INK_WEIGHTS.end());
app.field_run(edit, "tool.ink", |v| json!({"tool": tool.id(), "weight": v.clamp(lo, hi)}));
});
}
+3 -3
View File
@@ -504,9 +504,9 @@ fn pen_overlay(app: &FigApp, painter: &egui::Painter, zoom: f64) {
let pts: Vec<Pos2> = ov.pen.iter().map(|[x, y]| app.to_screen(*x, *y)).collect();
if app.session.tool.tool == ToolId::Pencil {
// The stroke it will make, in its colour and weight (at least a point when zoomed out):
// white over a dark page or frame, as the stroke will be (#1741).
let (default, weight) = figcraft_engine::tools::PENCIL_STROKE;
let color = ov.pen_color.unwrap_or(default);
// white over a dark page or frame, as the stroke will be (#1741), or the ink chosen (#2395).
let weight = app.session.tool.pencil_ink.weight;
let color = ov.pen_color.unwrap_or(figcraft_engine::tools::PENCIL_STROKE.0);
painter.add(Shape::line(pts, stroke(doc_c32(painter.ctx(), color), ((weight * zoom) as f32).max(1.0))));
} else {
for [x0, y0, x1, y1] in &ov.pen_handles {
+1
View File
@@ -186,6 +186,7 @@ fn main_toolbar(app: &mut FigApp, ui: &mut Ui, canvas: Rect, t: &Tokens, board:
mode_switcher(app, ui, x, cy, t);
}
ui.set_clip_rect(outer_clip);
crate::canvas::ink_bar::show(app, ui, rect);
help_button(app, ui, canvas, rect, t);
}
+23 -2
View File
@@ -52,6 +52,10 @@ pub enum PickerTarget {
id: String,
index: usize,
},
/// The ink a drawing tool's new strokes get (`tool.ink`).
Ink {
tool: figcraft_engine::ToolId,
},
/// A colour field of a plugin's panel or parameters form. A drag only shows `pending`; the
/// plugin hears of the colour when the drag ends.
PluginField {
@@ -114,6 +118,10 @@ fn current_paint(app: &FigApp, target: &PickerTarget) -> Option<Paint> {
_ => None,
},
PickerTarget::Style { id, index } => style_paints(doc, id)?.get(*index).cloned(),
PickerTarget::Ink { tool } => {
let ink = app.session.tool.ink(*tool)?;
Some(Paint::solid(ink.color.unwrap_or(figcraft_engine::tools::PENCIL_STROKE.0)))
}
PickerTarget::PluginField { plugin, control, pending } => {
let hex = match pending {
Some(hex) => hex.clone(),
@@ -158,6 +166,10 @@ fn paint_command(app: &FigApp, target: &PickerTarget, paint: &Paint) -> Option<(
}
("style.update", json!({"style": id, "value": paints}))
}
PickerTarget::Ink { tool } => {
let c = paint.solid_color().unwrap_or(Color::BLACK);
("tool.ink", json!({"tool": tool.id(), "color": c.to_css_hex()}))
}
})
}
@@ -977,6 +989,7 @@ pub fn show(app: &mut FigApp, ctx: &egui::Context) {
let stale = match &target {
PickerTarget::Paint { ids, .. } | PickerTarget::Effect { ids, .. } => *ids != app.session.selection(),
PickerTarget::TextRange { id, .. } => !app.session.selection().contains(id),
PickerTarget::Ink { tool } => *tool != app.session.tool.tool,
_ => false,
};
let current = if stale { None } else { current_paint(app, &target) };
@@ -1034,14 +1047,22 @@ pub fn show(app: &mut FigApp, ctx: &egui::Context) {
// Paint type.
if !matches!(
target,
PickerTarget::Effect { .. } | PickerTarget::PageBackground | PickerTarget::Variable { .. } | PickerTarget::PluginField { .. }
PickerTarget::Effect { .. }
| PickerTarget::PageBackground
| PickerTarget::Variable { .. }
| PickerTarget::PluginField { .. }
| PickerTarget::Ink { .. }
) {
paint_type_row(ui, app, &target, &mut paint);
}
// The paint's own blend mode, with the paints and layers under it.
if !matches!(
target,
PickerTarget::Effect { .. } | PickerTarget::PageBackground | PickerTarget::Variable { .. } | PickerTarget::PluginField { .. }
PickerTarget::Effect { .. }
| PickerTarget::PageBackground
| PickerTarget::Variable { .. }
| PickerTarget::PluginField { .. }
| PickerTarget::Ink { .. }
) {
blend_row(ui, app, &target, &mut paint);
}
+3 -2
View File
@@ -1,6 +1,6 @@
# Boards parity
> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-11-12 · **Change:** minor (mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre)
> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-11-27 · **Change:** minor (the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre)
**Breadth ~48%, ready ~30% (estimated, erring low).** A board is a FigCraft file of its own kind
(`file.newBoard`) with a dot grid on the page, sticky notes, shapes with text, connectors that
@@ -45,7 +45,7 @@ all end with the same geometry.
| Quick-create handles | done | a "+" beside each side of the one selected sticky or shape makes the next one there, joined by a connector (`board.addConnected`, also Shift+Cmd/Ctrl+Enter); dragged, it places the next one where it is let go, or joins the sticky or shape it is let go on (#1919) |
| Marker and highlighter | done | the Pencil's stroke fitting with board presets: marker opaque, highlighter wide, see-through and multiplying |
| Eraser | done | drag over marker and highlighter strokes to remove them, one undo step |
| Pen colours and widths in the toolbar | partial | `tool.marker {color}`, `tool.highlighter {color}`; colour changes on a selected stroke from the contextual bar |
| Pen colours and widths in the toolbar | done | while the Marker or Highlighter is the tool, a bar above the toolbar offers eight ink colours, any colour in the colour picker and the stroke weight; each tool keeps its own for the session and new strokes take it (`tool.ink {tool?, color?, weight?}`, #2395). A selected stroke's colour still changes from the contextual bar |
| Stamps | done | thumbs up, heart, plus one, star, question, check: round badges drawn as vectors, the placer's name on hover |
| Stamps sticking to the object they land on, the stamp wheel, emotes, stickers | partial | a stamp sticks to the object it lands on (`on`) and moves with it; dragged onto another object it sticks to that one, dragged off it to nothing, and it stays where it is when its object is deleted. the object it will stick to is outlined while the stamp tool is over it or a stamp is dragged over it. No stamp wheel, emotes or stickers |
| Text and sections | done | the existing Text tool and sections |
@@ -69,6 +69,7 @@ all end with the same geometry.
| Date | Change | Summary |
|---|---|---|
| 2026-11-27 | minor | M12, #2395: the Marker, Highlighter and Pencil had no way to choose the ink before drawing; only a stroke already drawn could be recoloured. While one of them is the tool, a bar above the bottom toolbar shows its ink: eight colours (the Pencil also its automatic black, or white on a dark page or frame), any colour through the colour picker, and the stroke weight. Each tool keeps its own for the session and new strokes, and their preview, take it. The engine command `tool.ink {tool?, color?, weight?}` sets and reads it, and `board.ink` takes a `weight`. Tests: `new_strokes_take_the_ink_chosen_before_drawing`. |
| 2026-11-11 | minor | M12, #2237 (step 1 of 4): code blocks in the document and engine. A code block is a board object of its own (`BoardItem::CodeBlock { language }`): a hugging frame holding one monospace text, 576 wide, 32 + 24 a visual line tall and never under four lines; only its width is kept from a resize. `board.codeBlock` places one, `board.setLanguage` picks one of 16 languages, and `board.nextSticky` makes the next block beside it. The normalize pass keeps a block's text plain code (`board::settle_code`) and the text editor types literally in it (two spaces for Tab, the line's indent after Enter, no list from `- `). The colours are FigCraft's own (the board's ink and tints); the sizes are from a FigJam measurement. Tests: `board_code_tests` in doc (four) and engine (thirteen). Numbers unchanged (no toolbar entry yet). |
| 2026-11-10 | minor | M12, #2226 (step 2 of 4): mind maps in the UI. The Shapes flyout ends in a mind map tool (`tool.mindMap`): a click places a map with the first node's text starting there and types in it. Cmd/Ctrl+Enter adds a child of the selected or edited node (`board.mindMapAdd`), Shift+Cmd/Ctrl+Enter its next sibling (`board.nextSticky` on a node), both typing on; Tab and Shift+Tab walk a node's siblings in the map's order (`select.next`, `select.previous`). The bar over the selection colours a node's text (`board.setColor`) and shows a branch the connector's controls without the line types. Tests: `board_mindmap_tests` (four more), `board_ui_tests` (five more). Breadth ~47% → ~48%, ready ~29% → ~30%. |
| 2026-11-13 | patch | Rows that recent merges had duplicated or garbled are merged back into one row each (no behaviour change): Shapes with text, Connectors, Create the next shape already connected. |