Rename geometric eval and apply to resolve ✏

This commit is contained in:
Laurenz 2020-10-13 13:24:33 +02:00
parent 22697f0c0c
commit 8680fcd490
11 changed files with 27 additions and 28 deletions

View File

@ -173,7 +173,7 @@ impl EvalContext {
self.start_group(ParGroup {
dirs: self.state.dirs,
aligns: self.state.aligns,
line_spacing: self.state.par.line_spacing.eval(em),
line_spacing: self.state.par.line_spacing.resolve(em),
});
}
@ -299,7 +299,7 @@ impl Eval for SynNode {
SynNode::Space => {
let em = ctx.state.font.font_size();
ctx.push(Spacing {
amount: ctx.state.par.word_spacing.eval(em),
amount: ctx.state.par.word_spacing.resolve(em),
softness: Softness::Soft,
});
}
@ -318,7 +318,7 @@ impl Eval for SynNode {
ctx.end_par_group();
let em = ctx.state.font.font_size();
ctx.push(Spacing {
amount: ctx.state.par.par_spacing.eval(em),
amount: ctx.state.par.par_spacing.resolve(em),
softness: Softness::Soft,
});
ctx.start_par_group();
@ -358,7 +358,7 @@ impl Eval for NodeRaw {
families.flatten();
let em = ctx.state.font.font_size();
let line_spacing = ctx.state.par.line_spacing.eval(em);
let line_spacing = ctx.state.par.line_spacing.resolve(em);
let mut children = vec![];
for line in &self.lines {

View File

@ -121,7 +121,7 @@ pub struct FontState {
impl FontState {
/// The absolute font size.
pub fn font_size(&self) -> Length {
self.scale.eval(self.size)
self.scale.resolve(self.size)
}
}

View File

@ -13,7 +13,7 @@ pub enum Align {
impl Align {
/// Returns the position of this alignment in the given range.
pub fn apply(self, range: Range<Length>) -> Length {
pub fn resolve(self, range: Range<Length>) -> Length {
match self {
Self::Start => range.start,
Self::Center => (range.start + range.end) / 2.0,

View File

@ -21,10 +21,9 @@ impl Linear {
Self { rel, abs }
}
/// Evaluate the linear length with `one` being `100%` for the relative
/// part.
pub fn eval(self, one: Length) -> Length {
self.rel.eval(one) + self.abs
/// Resolve this relative to the given `length`.
pub fn resolve(self, length: Length) -> Length {
self.rel.resolve(length) + self.abs
}
/// Whether this linear's relative part is zero.

View File

@ -26,9 +26,9 @@ impl Relative {
self.0
}
/// Evaluate the relative length with `one` being `100%`.
pub fn eval(self, one: Length) -> Length {
self.get() * one
/// Resolve this relative to the given `length`.
pub fn resolve(self, length: Length) -> Length {
self.get() * length
}
}

View File

@ -34,13 +34,13 @@ impl<T> Sides<T> {
}
impl Sides<Linear> {
/// Evaluate the linear values in this container.
pub fn eval(self, size: Size) -> Sides<Length> {
/// Resolve the linear margins relative to the given `size`.
pub fn resolve(self, size: Size) -> Sides<Length> {
Sides {
left: self.left.eval(size.width),
top: self.top.eval(size.height),
right: self.right.eval(size.width),
bottom: self.bottom.eval(size.height),
left: self.left.resolve(size.width),
top: self.top.resolve(size.height),
right: self.right.resolve(size.width),
bottom: self.bottom.resolve(size.height),
}
}
}

View File

@ -16,8 +16,8 @@ impl Layout for Fixed {
fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted {
let Area { rem, full } = areas.current;
let size = Size::new(
self.width.map(|w| w.eval(full.width)).unwrap_or(rem.width),
self.height.map(|h| h.eval(full.height)).unwrap_or(rem.height),
self.width.map(|w| w.resolve(full.width)).unwrap_or(rem.width),
self.height.map(|h| h.resolve(full.height)).unwrap_or(rem.height),
);
let areas = Areas::once(size);

View File

@ -31,7 +31,7 @@ impl Layout for Pad {
/// Shrink all areas by the padding.
fn shrink_areas(areas: &Areas, padding: Sides<Linear>) -> Areas {
let shrink = |size| size - padding.eval(size).size();
let shrink = |size| size - padding.resolve(size).size();
Areas {
current: Area {
rem: shrink(areas.current.rem),
@ -44,7 +44,7 @@ fn shrink_areas(areas: &Areas, padding: Sides<Linear>) -> Areas {
/// Enlarge the box and move all elements inwards.
fn pad_layout(layout: &mut BoxLayout, padding: Sides<Linear>) {
let padding = padding.eval(layout.size);
let padding = padding.resolve(layout.size);
let origin = Point::new(padding.left, padding.top);
layout.size += padding.size();

View File

@ -125,7 +125,7 @@ impl<'a> ParLayouter<'a> {
let child_cross_size = layout.size.get(self.cross);
// Position along the cross axis.
let cross = align.apply(if self.dirs.cross.is_positive() {
let cross = align.resolve(if self.dirs.cross.is_positive() {
let after_with_self = self.run_size.cross - before;
before .. full_size.cross - after_with_self
} else {
@ -164,7 +164,7 @@ impl<'a> ParLayouter<'a> {
};
// Align along the cross axis.
let cross = cross_align.apply(if self.dirs.cross.is_positive() {
let cross = cross_align.resolve(if self.dirs.cross.is_positive() {
Length::ZERO .. size.cross - child_size.cross
} else {
size.cross - child_size.cross .. Length::ZERO

View File

@ -117,7 +117,7 @@ impl<'a> StackLayouter<'a> {
let child_size = layout.size.switch(self.dirs);
// Align along the main axis.
let main = aligns.main.apply(if self.dirs.main.is_positive() {
let main = aligns.main.resolve(if self.dirs.main.is_positive() {
let after_with_self = self.used.main - before;
before .. full_size.main - after_with_self
} else {
@ -127,7 +127,7 @@ impl<'a> StackLayouter<'a> {
});
// Align along the cross axis.
let cross = aligns.cross.apply(if self.dirs.cross.is_positive() {
let cross = aligns.cross.resolve(if self.dirs.cross.is_positive() {
Length::ZERO .. full_size.cross - child_size.cross
} else {
full_size.cross - child_size.cross .. Length::ZERO

View File

@ -24,7 +24,7 @@ fn spacing(mut args: Args, ctx: &mut EvalContext, axis: SpecAxis) -> Value {
args.done(ctx);
if let Some(linear) = spacing {
let amount = linear.eval(ctx.state.font.font_size());
let amount = linear.resolve(ctx.state.font.font_size());
let spacing = Spacing { amount, softness: Softness::Hard };
if ctx.state.dirs.main.axis() == axis {
ctx.end_par_group();