mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
Rename box to rect and color to fill ✏
This commit is contained in:
parent
271b0f953b
commit
8cdfc7faaf
@ -44,13 +44,13 @@ pub fn new() -> Scope {
|
||||
|
||||
// Functions.
|
||||
set!(func: "align", align);
|
||||
set!(func: "box", box_);
|
||||
set!(func: "font", font);
|
||||
set!(func: "h", h);
|
||||
set!(func: "image", image);
|
||||
set!(func: "pad", pad);
|
||||
set!(func: "page", page);
|
||||
set!(func: "pagebreak", pagebreak);
|
||||
set!(func: "rect", rect);
|
||||
set!(func: "repr", repr);
|
||||
set!(func: "rgb", rgb);
|
||||
set!(func: "type", type_);
|
||||
|
@ -1,16 +1,16 @@
|
||||
use super::*;
|
||||
|
||||
/// `box`: Create a rectangular box.
|
||||
/// `rect`: Create a rectangular box.
|
||||
///
|
||||
/// # Positional arguments
|
||||
/// - Body: optional, of type `template`.
|
||||
///
|
||||
/// # Named arguments
|
||||
/// - Width of the box: `width`, of type `linear` relative to parent width.
|
||||
/// - Height of the box: `height`, of type `linear` relative to parent height.
|
||||
/// - Main layouting direction: `main-dir`, of type `direction`.
|
||||
/// - Cross layouting direction: `cross-dir`, of type `direction`.
|
||||
/// - Background color of the box: `color`, of type `color`.
|
||||
/// - Width of the box: `width`, of type `linear` relative to parent width.
|
||||
/// - Height of the box: `height`, of type `linear` relative to parent height.
|
||||
/// - Main layouting direction: `main-dir`, of type `direction`.
|
||||
/// - Cross layouting direction: `cross-dir`, of type `direction`.
|
||||
/// - Fill color of the box: `fill`, of type `color`.
|
||||
///
|
||||
/// # Relevant types and constants
|
||||
/// - Type `direction`
|
||||
@ -18,12 +18,12 @@ use super::*;
|
||||
/// - `rtl` (right to left)
|
||||
/// - `ttb` (top to bottom)
|
||||
/// - `btt` (bottom to top)
|
||||
pub fn box_(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||
pub fn rect(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||
let width = args.get(ctx, "width");
|
||||
let height = args.get(ctx, "height");
|
||||
let main = args.get(ctx, "main-dir");
|
||||
let cross = args.get(ctx, "cross-dir");
|
||||
let color = args.get(ctx, "color");
|
||||
let fill = args.get(ctx, "fill");
|
||||
let body = args.find::<ValueTemplate>(ctx).unwrap_or_default();
|
||||
|
||||
Value::template("box", move |ctx| {
|
||||
@ -33,7 +33,7 @@ pub fn box_(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||
|
||||
let child = ctx.exec(&body).into();
|
||||
let fixed = NodeFixed { width, height, child };
|
||||
if let Some(color) = color {
|
||||
if let Some(color) = fill {
|
||||
ctx.push(NodeBackground {
|
||||
fill: Fill::Color(color),
|
||||
child: fixed.into(),
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@ -18,8 +18,8 @@
|
||||
---
|
||||
// Syntax sugar for function definitions.
|
||||
#let background = #239dad
|
||||
#let box(body) = box(width: 2cm, height: 1cm, color: background, body)
|
||||
#box[Hi!]
|
||||
#let rect(body) = rect(width: 2cm, height: 1cm, fill: background, body)
|
||||
#rect[Hi!]
|
||||
|
||||
// Error: 13 expected body
|
||||
#let func(x)
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
// Top-level paragraph fills page, boxed paragraph only when width is fixed.
|
||||
L #right[R] \
|
||||
#box(width: 50pt)[L #right[R]] \
|
||||
#box[L #right[R]] \
|
||||
#rect(width: 50pt)[L #right[R]] \
|
||||
#rect[L #right[R]] \
|
||||
|
||||
// Pad inherits expansion behaviour.
|
||||
#pad[PL #right[PR]] \
|
||||
#box(pad[PL #right[PR]])
|
||||
#rect(pad[PL #right[PR]])
|
||||
|
@ -50,10 +50,10 @@
|
||||
// Error: 3-4 unknown variable
|
||||
{ z = 1 }
|
||||
|
||||
// Error: 3-6 cannot assign to a constant
|
||||
{ box = "hi" }
|
||||
// Error: 3-7 cannot assign to a constant
|
||||
{ rect = "hi" }
|
||||
|
||||
// Works if we define box beforehand
|
||||
// Works if we define rect beforehand
|
||||
// (since then it doesn't resolve to the standard library version anymore).
|
||||
#let box = ""
|
||||
{ box = "hi" }
|
||||
#let rect = ""
|
||||
{ rect = "hi" }
|
||||
|
@ -10,10 +10,10 @@
|
||||
#let university = [*Technische Universität {city}*]
|
||||
#let faculty = [*Fakultät II, Institut for Mathematik*]
|
||||
|
||||
// The `box` function just places content into a rectangular container. When
|
||||
// The `rect` function just places content into a rectangular container. When
|
||||
// the only argument to a function is a template, the parentheses can be omitted
|
||||
// (i.e. `f[a]` is the same as `f([a])`).
|
||||
#box[
|
||||
#rect[
|
||||
// Backslash adds a forced line break.
|
||||
#university \
|
||||
#faculty \
|
||||
@ -21,7 +21,7 @@
|
||||
Dr. Max Mustermann \
|
||||
Ola Nordmann, John Doe
|
||||
]
|
||||
#align(right, box[*WiSe 2019/2020* \ Woche 3])
|
||||
#align(right, rect[*WiSe 2019/2020* \ Woche 3])
|
||||
|
||||
// Adds vertical spacing.
|
||||
#v(6mm)
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
---
|
||||
#test(type("hi"), "string")
|
||||
#test(repr([Hi #box[there]]), "[Hi [<node box>]]")
|
||||
#test(repr([Hi #rect[there]]), "[Hi [<node box>]]")
|
||||
|
||||
---
|
||||
// Check the output.
|
||||
|
@ -5,9 +5,9 @@
|
||||
#pad(left: 10pt, [Indented!])
|
||||
|
||||
// All sides together.
|
||||
#box(color: #9feb52,
|
||||
#rect(fill: #9feb52,
|
||||
pad(10pt, right: 20pt,
|
||||
box(color: #eb5278, width: 20pt, height: 20pt)))
|
||||
rect(width: 20pt, height: 20pt, fill: #eb5278)))
|
||||
|
||||
// Error: 13-23 missing argument: body
|
||||
Hi #box(pad(left: 10pt)) there
|
||||
// Error: 14-24 missing argument: body
|
||||
Hi #rect(pad(left: 10pt)) there
|
||||
|
@ -1,31 +1,33 @@
|
||||
// Test shapes.
|
||||
|
||||
---
|
||||
// Test `rect` function.
|
||||
|
||||
#page("a8", flip: true)
|
||||
|
||||
// Box with fixed width, should have text height.
|
||||
#box(width: 2cm, color: #9650D6)[Legal]
|
||||
// Fixed width, should have text height.
|
||||
#rect(width: 2cm, fill: #9650D6)[Legal]
|
||||
|
||||
Sometimes there is no box.
|
||||
|
||||
// Box with fixed height, should span line.
|
||||
#box(height: 1cm, width: 100%, color: #734CED)[B]
|
||||
// Fixed height, should span line.
|
||||
#rect(height: 1cm, width: 100%, fill: #734CED)[B]
|
||||
|
||||
// Empty box with fixed width and height.
|
||||
#box(width: 6cm, height: 12pt, color: #CB4CED)
|
||||
// Empty with fixed width and height.
|
||||
#rect(width: 6cm, height: 12pt, fill: #CB4CED)
|
||||
|
||||
// Not visible, but creates a gap between the boxes above and below.
|
||||
#box(width: 2in, color: #ff0000)
|
||||
#rect(width: 2in, fill: #ff0000)
|
||||
|
||||
// These are in a row!
|
||||
#box(width: 0.5in, height: 10pt, color: #D6CD67)
|
||||
#box(width: 0.5in, height: 10pt, color: #EDD466)
|
||||
#box(width: 0.5in, height: 10pt, color: #E3BE62)
|
||||
#rect(width: 0.5in, height: 10pt, fill: #D6CD67)
|
||||
#rect(width: 0.5in, height: 10pt, fill: #EDD466)
|
||||
#rect(width: 0.5in, height: 10pt, fill: #E3BE62)
|
||||
|
||||
---
|
||||
// Make sure that you can't do page related stuff in a box.
|
||||
// Make sure that you can't do page related stuff in a shape.
|
||||
A
|
||||
#box[
|
||||
#rect[
|
||||
B
|
||||
// Error: 16 cannot modify page from here
|
||||
#pagebreak()
|
||||
|
@ -8,7 +8,7 @@ _Emphasized!_
|
||||
Partly em_phas_ized.
|
||||
|
||||
// Scoped to body.
|
||||
#box[_Scoped] to body.
|
||||
#rect[_Scoped] to body.
|
||||
|
||||
// Unterminated is fine.
|
||||
_The End
|
||||
|
@ -21,7 +21,7 @@
|
||||
}
|
||||
|
||||
// Function call continues heading.
|
||||
= #box[
|
||||
= #rect[
|
||||
A
|
||||
] B
|
||||
|
||||
@ -35,7 +35,7 @@ B
|
||||
// Parsed as headings if at start of the context.
|
||||
/**/ = Ok
|
||||
{[== Ok]}
|
||||
#box[=== Ok]
|
||||
#rect[=== Ok]
|
||||
|
||||
// Not at the start of the context.
|
||||
No = heading
|
||||
|
@ -8,7 +8,7 @@
|
||||
Partly str*ength*ened.
|
||||
|
||||
// Scoped to body.
|
||||
#box[*Scoped] to body.
|
||||
#rect[*Scoped] to body.
|
||||
|
||||
// Unterminated is fine.
|
||||
*The End
|
||||
|
@ -52,6 +52,6 @@
|
||||
// Functions
|
||||
#let f(x) = x
|
||||
|
||||
{box} \
|
||||
{rect} \
|
||||
{f} \
|
||||
{() => none} \
|
||||
|
Loading…
x
Reference in New Issue
Block a user