summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-06-11 11:30:18 +0200
committerLaurenz <laurmaedje@gmail.com>2021-06-11 11:30:18 +0200
commit3330767c20e14a05176902a93dcefb08cb509173 (patch)
treeeb40b262d267df0e9f73bbbc4ec602183fd39dff /src/library
parentc28708aa196eaca247cdab6b5e8af9751b4f1dad (diff)
Remove props in favor of using state for everything
Diffstat (limited to 'src/library')
-rw-r--r--src/library/decorations.rs16
-rw-r--r--src/library/font.rs28
-rw-r--r--src/library/mod.rs1
-rw-r--r--src/library/spacing.rs3
4 files changed, 24 insertions, 24 deletions
diff --git a/src/library/decorations.rs b/src/library/decorations.rs
index ef9afd37..423041c1 100644
--- a/src/library/decorations.rs
+++ b/src/library/decorations.rs
@@ -55,7 +55,7 @@ fn line_impl(
name: &str,
ctx: &mut EvalContext,
args: &mut FuncArgs,
- substate: impl Fn(&mut FontState) -> &mut Option<LineState> + 'static,
+ substate: fn(&mut FontState) -> &mut Option<Rc<LineState>>,
) -> Value {
let color = args.eat_named(ctx, "color");
let position = args.eat_named(ctx, "position");
@@ -64,17 +64,19 @@ fn line_impl(
let body = args.eat::<TemplateValue>(ctx);
// Suppress any existing strikethrough if strength is explicitly zero.
- let state = strength.map_or(true, |s| !s.is_zero()).then(|| LineState {
- fill: color.map(Fill::Color),
- strength,
- position,
- extent,
+ let state = strength.map_or(true, |s| !s.is_zero()).then(|| {
+ Rc::new(LineState {
+ strength,
+ position,
+ extent,
+ fill: color.map(Fill::Color),
+ })
});
Value::template(name, move |ctx| {
let snapshot = ctx.state.clone();
- *substate(&mut ctx.state.font) = state;
+ *substate(ctx.state.font_mut()) = state.clone();
if let Some(body) = &body {
body.exec(ctx);
diff --git a/src/library/font.rs b/src/library/font.rs
index a3fe6c13..c1ed1c98 100644
--- a/src/library/font.rs
+++ b/src/library/font.rs
@@ -64,54 +64,50 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
Value::template("font", move |ctx| {
let snapshot = ctx.state.clone();
+ let font = ctx.state.font_mut();
if let Some(linear) = size {
- if linear.rel.is_zero() {
- ctx.state.font.size = linear.abs;
- ctx.state.font.scale = Linear::one();
- } else {
- ctx.state.font.scale = linear;
- }
+ font.size = linear.resolve(font.size);
}
if !list.is_empty() {
- ctx.state.font.families_mut().list = list.clone();
+ font.families_mut().list = list.clone();
}
if let Some(style) = style {
- ctx.state.font.variant.style = style;
+ font.variant.style = style;
}
if let Some(weight) = weight {
- ctx.state.font.variant.weight = weight;
+ font.variant.weight = weight;
}
if let Some(stretch) = stretch {
- ctx.state.font.variant.stretch = stretch;
+ font.variant.stretch = stretch;
}
if let Some(top_edge) = top_edge {
- ctx.state.font.top_edge = top_edge;
+ font.top_edge = top_edge;
}
if let Some(bottom_edge) = bottom_edge {
- ctx.state.font.bottom_edge = bottom_edge;
+ font.bottom_edge = bottom_edge;
}
if let Some(color) = color {
- ctx.state.font.fill = Fill::Color(color);
+ font.fill = Fill::Color(color);
}
if let Some(FontFamilies(serif)) = &serif {
- ctx.state.font.families_mut().serif = serif.clone();
+ font.families_mut().serif = serif.clone();
}
if let Some(FontFamilies(sans_serif)) = &sans_serif {
- ctx.state.font.families_mut().sans_serif = sans_serif.clone();
+ font.families_mut().sans_serif = sans_serif.clone();
}
if let Some(FontFamilies(monospace)) = &monospace {
- ctx.state.font.families_mut().monospace = monospace.clone();
+ font.families_mut().monospace = monospace.clone();
}
if let Some(body) = &body {
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 553b39e6..0536eaa1 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -34,6 +34,7 @@ pub use spacing::*;
pub use stack::*;
use std::fmt::{self, Display, Formatter};
+use std::rc::Rc;
use crate::color::RgbaColor;
use crate::eval::{EvalContext, FuncArgs, Scope, TemplateValue, Value};
diff --git a/src/library/spacing.rs b/src/library/spacing.rs
index ff6aaa69..654a18c4 100644
--- a/src/library/spacing.rs
+++ b/src/library/spacing.rs
@@ -31,7 +31,8 @@ fn spacing_impl(
let spacing: Option<Linear> = args.eat_expect(ctx, "spacing");
Value::template(name, move |ctx| {
if let Some(linear) = spacing {
- let amount = linear.resolve(ctx.state.font.resolve_size());
+ // TODO: Should this really always be font-size relative?
+ let amount = linear.resolve(ctx.state.font.size);
ctx.push_spacing(axis, amount);
}
})