Rename box to rect and color to fill ✏

This commit is contained in:
Laurenz 2021-03-17 22:08:44 +01:00
parent 271b0f953b
commit 8cdfc7faaf
14 changed files with 47 additions and 45 deletions

View File

@ -44,13 +44,13 @@ pub fn new() -> Scope {
// Functions. // Functions.
set!(func: "align", align); set!(func: "align", align);
set!(func: "box", box_);
set!(func: "font", font); set!(func: "font", font);
set!(func: "h", h); set!(func: "h", h);
set!(func: "image", image); set!(func: "image", image);
set!(func: "pad", pad); set!(func: "pad", pad);
set!(func: "page", page); set!(func: "page", page);
set!(func: "pagebreak", pagebreak); set!(func: "pagebreak", pagebreak);
set!(func: "rect", rect);
set!(func: "repr", repr); set!(func: "repr", repr);
set!(func: "rgb", rgb); set!(func: "rgb", rgb);
set!(func: "type", type_); set!(func: "type", type_);

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
/// `box`: Create a rectangular box. /// `rect`: Create a rectangular box.
/// ///
/// # Positional arguments /// # Positional arguments
/// - Body: optional, of type `template`. /// - Body: optional, of type `template`.
@ -10,7 +10,7 @@ use super::*;
/// - Height of the box: `height`, of type `linear` relative to parent height. /// - Height of the box: `height`, of type `linear` relative to parent height.
/// - Main layouting direction: `main-dir`, of type `direction`. /// - Main layouting direction: `main-dir`, of type `direction`.
/// - Cross layouting direction: `cross-dir`, of type `direction`. /// - Cross layouting direction: `cross-dir`, of type `direction`.
/// - Background color of the box: `color`, of type `color`. /// - Fill color of the box: `fill`, of type `color`.
/// ///
/// # Relevant types and constants /// # Relevant types and constants
/// - Type `direction` /// - Type `direction`
@ -18,12 +18,12 @@ use super::*;
/// - `rtl` (right to left) /// - `rtl` (right to left)
/// - `ttb` (top to bottom) /// - `ttb` (top to bottom)
/// - `btt` (bottom to top) /// - `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 width = args.get(ctx, "width");
let height = args.get(ctx, "height"); let height = args.get(ctx, "height");
let main = args.get(ctx, "main-dir"); let main = args.get(ctx, "main-dir");
let cross = args.get(ctx, "cross-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(); let body = args.find::<ValueTemplate>(ctx).unwrap_or_default();
Value::template("box", move |ctx| { 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 child = ctx.exec(&body).into();
let fixed = NodeFixed { width, height, child }; let fixed = NodeFixed { width, height, child };
if let Some(color) = color { if let Some(color) = fill {
ctx.push(NodeBackground { ctx.push(NodeBackground {
fill: Fill::Color(color), fill: Fill::Color(color),
child: fixed.into(), child: fixed.into(),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -18,8 +18,8 @@
--- ---
// Syntax sugar for function definitions. // Syntax sugar for function definitions.
#let background = #239dad #let background = #239dad
#let box(body) = box(width: 2cm, height: 1cm, color: background, body) #let rect(body) = rect(width: 2cm, height: 1cm, fill: background, body)
#box[Hi!] #rect[Hi!]
// Error: 13 expected body // Error: 13 expected body
#let func(x) #let func(x)

View File

@ -6,9 +6,9 @@
// Top-level paragraph fills page, boxed paragraph only when width is fixed. // Top-level paragraph fills page, boxed paragraph only when width is fixed.
L #right[R] \ L #right[R] \
#box(width: 50pt)[L #right[R]] \ #rect(width: 50pt)[L #right[R]] \
#box[L #right[R]] \ #rect[L #right[R]] \
// Pad inherits expansion behaviour. // Pad inherits expansion behaviour.
#pad[PL #right[PR]] \ #pad[PL #right[PR]] \
#box(pad[PL #right[PR]]) #rect(pad[PL #right[PR]])

View File

@ -50,10 +50,10 @@
// Error: 3-4 unknown variable // Error: 3-4 unknown variable
{ z = 1 } { z = 1 }
// Error: 3-6 cannot assign to a constant // Error: 3-7 cannot assign to a constant
{ box = "hi" } { 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). // (since then it doesn't resolve to the standard library version anymore).
#let box = "" #let rect = ""
{ box = "hi" } { rect = "hi" }

View File

@ -10,10 +10,10 @@
#let university = [*Technische Universität {city}*] #let university = [*Technische Universität {city}*]
#let faculty = [*Fakultät II, Institut for Mathematik*] #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 // the only argument to a function is a template, the parentheses can be omitted
// (i.e. `f[a]` is the same as `f([a])`). // (i.e. `f[a]` is the same as `f([a])`).
#box[ #rect[
// Backslash adds a forced line break. // Backslash adds a forced line break.
#university \ #university \
#faculty \ #faculty \
@ -21,7 +21,7 @@
Dr. Max Mustermann \ Dr. Max Mustermann \
Ola Nordmann, John Doe Ola Nordmann, John Doe
] ]
#align(right, box[*WiSe 2019/2020* \ Woche 3]) #align(right, rect[*WiSe 2019/2020* \ Woche 3])
// Adds vertical spacing. // Adds vertical spacing.
#v(6mm) #v(6mm)

View File

@ -3,7 +3,7 @@
--- ---
#test(type("hi"), "string") #test(type("hi"), "string")
#test(repr([Hi #box[there]]), "[Hi [<node box>]]") #test(repr([Hi #rect[there]]), "[Hi [<node box>]]")
--- ---
// Check the output. // Check the output.

View File

@ -5,9 +5,9 @@
#pad(left: 10pt, [Indented!]) #pad(left: 10pt, [Indented!])
// All sides together. // All sides together.
#box(color: #9feb52, #rect(fill: #9feb52,
pad(10pt, right: 20pt, pad(10pt, right: 20pt,
box(color: #eb5278, width: 20pt, height: 20pt))) rect(width: 20pt, height: 20pt, fill: #eb5278)))
// Error: 13-23 missing argument: body // Error: 14-24 missing argument: body
Hi #box(pad(left: 10pt)) there Hi #rect(pad(left: 10pt)) there

View File

@ -1,31 +1,33 @@
// Test shapes. // Test shapes.
--- ---
// Test `rect` function.
#page("a8", flip: true) #page("a8", flip: true)
// Box with fixed width, should have text height. // Fixed width, should have text height.
#box(width: 2cm, color: #9650D6)[Legal] #rect(width: 2cm, fill: #9650D6)[Legal]
Sometimes there is no box. Sometimes there is no box.
// Box with fixed height, should span line. // Fixed height, should span line.
#box(height: 1cm, width: 100%, color: #734CED)[B] #rect(height: 1cm, width: 100%, fill: #734CED)[B]
// Empty box with fixed width and height. // Empty with fixed width and height.
#box(width: 6cm, height: 12pt, color: #CB4CED) #rect(width: 6cm, height: 12pt, fill: #CB4CED)
// Not visible, but creates a gap between the boxes above and below. // 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! // These are in a row!
#box(width: 0.5in, height: 10pt, color: #D6CD67) #rect(width: 0.5in, height: 10pt, fill: #D6CD67)
#box(width: 0.5in, height: 10pt, color: #EDD466) #rect(width: 0.5in, height: 10pt, fill: #EDD466)
#box(width: 0.5in, height: 10pt, color: #E3BE62) #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 A
#box[ #rect[
B B
// Error: 16 cannot modify page from here // Error: 16 cannot modify page from here
#pagebreak() #pagebreak()

View File

@ -8,7 +8,7 @@ _Emphasized!_
Partly em_phas_ized. Partly em_phas_ized.
// Scoped to body. // Scoped to body.
#box[_Scoped] to body. #rect[_Scoped] to body.
// Unterminated is fine. // Unterminated is fine.
_The End _The End

View File

@ -21,7 +21,7 @@
} }
// Function call continues heading. // Function call continues heading.
= #box[ = #rect[
A A
] B ] B
@ -35,7 +35,7 @@ B
// Parsed as headings if at start of the context. // Parsed as headings if at start of the context.
/**/ = Ok /**/ = Ok
{[== Ok]} {[== Ok]}
#box[=== Ok] #rect[=== Ok]
// Not at the start of the context. // Not at the start of the context.
No = heading No = heading

View File

@ -8,7 +8,7 @@
Partly str*ength*ened. Partly str*ength*ened.
// Scoped to body. // Scoped to body.
#box[*Scoped] to body. #rect[*Scoped] to body.
// Unterminated is fine. // Unterminated is fine.
*The End *The End

View File

@ -52,6 +52,6 @@
// Functions // Functions
#let f(x) = x #let f(x) = x
{box} \ {rect} \
{f} \ {f} \
{() => none} \ {() => none} \