summaryrefslogtreecommitdiff
path: root/library/src/visualize
diff options
context:
space:
mode:
authorBirk Tjelmeland <git@birktj.no>2023-04-13 16:05:56 +0200
committerGitHub <noreply@github.com>2023-04-13 16:05:56 +0200
commitd1cd814ef8149cbac6e59c81e074aa59c930eed3 (patch)
tree02b9a8afed4d121b34d89669452f91cda19df8e2 /library/src/visualize
parent46ce9c94e3f615751989d3cba5aa1599e0ba5913 (diff)
Add support for more complex strokes (#505)
Diffstat (limited to 'library/src/visualize')
-rw-r--r--library/src/visualize/line.rs25
-rw-r--r--library/src/visualize/shape.rs18
2 files changed, 40 insertions, 3 deletions
diff --git a/library/src/visualize/line.rs b/library/src/visualize/line.rs
index 0932a9f1..362f1a89 100644
--- a/library/src/visualize/line.rs
+++ b/library/src/visualize/line.rs
@@ -40,9 +40,32 @@ pub struct LineElem {
/// to `{1pt}`.
/// - A stroke combined from color and thickness using the `+` operator as
/// in `{2pt + red}`.
+ /// - A stroke described by a dictionary with any of the following keys:
+ /// - `color`: the color to use for the stroke
+ /// - `thickness`: the stroke's thickness
+ /// - `cap`: one of `"butt"`, `"round"` or `"square"`, the line cap of the stroke
+ /// - `join`: one of `"miter"`, `"round"` or `"bevel"`, the line join of the stroke
+ /// - `miter-limit`: the miter limit to use if `join` is `"miter"`, defaults to 4.0
+ /// - `dash`: the dash pattern to use. Can be any of the following:
+ /// - One of the strings `"solid"`, `"dotted"`, `"densely-dotted"`, `"loosely-dotted"`,
+ /// `"dashed"`, `"densely-dashed"`, `"loosely-dashed"`, `"dashdotted"`,
+ /// `"densely-dashdotted"` or `"loosely-dashdotted"`
+ /// - An array with elements that specify the lengths of dashes and gaps, alternating.
+ /// Elements can also be the string `"dot"` for a length equal to the line thickness.
+ /// - A dict with the keys `array`, same as the array above, and `phase`, the offset to
+ /// the start of the first dash.
+ ///
///
/// ```example
- /// #line(length: 100%, stroke: 2pt + red)
+ /// #stack(
+ /// line(length: 100%, stroke: 2pt + red),
+ /// v(1em),
+ /// line(length: 100%, stroke: (color: blue, thickness: 4pt, cap: "round")),
+ /// v(1em),
+ /// line(length: 100%, stroke: (color: blue, thickness: 1pt, dash: "dashed")),
+ /// v(1em),
+ /// line(length: 100%, stroke: (color: blue, thickness: 1pt, dash: ("dot", 2pt, 4pt, 2pt))),
+ /// )
/// ```
#[resolve]
#[fold]
diff --git a/library/src/visualize/shape.rs b/library/src/visualize/shape.rs
index 51dbabd8..e0214f03 100644
--- a/library/src/visualize/shape.rs
+++ b/library/src/visualize/shape.rs
@@ -47,8 +47,22 @@ pub struct RectElem {
/// to `{1pt}`.
/// - A stroke combined from color and thickness using the `+` operator as
/// in `{2pt + red}`.
- /// - A dictionary: With a dictionary, the stroke for each side can be set
- /// individually. The dictionary can contain the following keys in order
+ /// - A stroke described by a dictionary with any of the following keys:
+ /// - `color`: the color to use for the stroke
+ /// - `thickness`: the stroke's thickness
+ /// - `cap`: one of `"butt"`, `"round"` or `"square"`, the line cap of the stroke
+ /// - `join`: one of `"miter"`, `"round"` or `"bevel"`, the line join of the stroke
+ /// - `miter-limit`: the miter limit to use if `join` is `"miter"`, defaults to 4.0
+ /// - `dash`: the dash pattern to use. Can be any of the following:
+ /// - One of the strings `"solid"`, `"dotted"`, `"densely-dotted"`, `"loosely-dotted"`,
+ /// `"dashed"`, `"densely-dashed"`, `"loosely-dashed"`, `"dashdotted"`,
+ /// `"densely-dashdotted"` or `"loosely-dashdotted"`
+ /// - An array with elements that specify the lengths of dashes and gaps, alternating.
+ /// Elements can also be the string `"dot"` for a length equal to the line thickness.
+ /// - A dict with the keys `array`, same as the array above, and `phase`, the offset to
+ /// the start of the first dash.
+ /// - Another dictionary describing the stroke for each side inidvidually.
+ /// The dictionary can contain the following keys in order
/// of precedence:
/// - `top`: The top stroke.
/// - `right`: The right stroke.