diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-17 09:28:06 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-17 09:28:06 +0200 |
| commit | 9a1d57a11a510b8e6af024b4338ee58d791f3088 (patch) | |
| tree | 5f28224b68b69c3db1365f75613b85798da0b1f7 /src/func.rs | |
| parent | e87a34a4d0bf967427e2443f9f48026d09ccd5db (diff) | |
Implement context-modifying align 🧩
Diffstat (limited to 'src/func.rs')
| -rw-r--r-- | src/func.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/func.rs b/src/func.rs index 1f1b928d..e2391a55 100644 --- a/src/func.rs +++ b/src/func.rs @@ -4,10 +4,9 @@ use std::any::Any; use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; -use toddle::query::FontClass; - -use crate::layout::{Layout, LayoutContext, LayoutResult, MultiLayout}; +use crate::layout::{Layout, LayoutContext, Alignment, LayoutResult, MultiLayout}; use crate::parsing::{ParseContext, ParseResult}; +use crate::style::TextStyle; use crate::syntax::{FuncHeader, SyntaxTree}; /// Typesetting function types. @@ -27,7 +26,7 @@ pub trait Function: FunctionBounds { /// /// Returns optionally the resulting layout and a new context if changes to /// the context should be made. - fn layout(&self, ctx: LayoutContext) -> LayoutResult<FuncCommands>; + fn layout(&self, ctx: LayoutContext) -> LayoutResult<CommandList>; } impl PartialEq for dyn Function { @@ -38,14 +37,14 @@ impl PartialEq for dyn Function { /// A sequence of commands requested for execution by a function. #[derive(Debug)] -pub struct FuncCommands<'a> { +pub struct CommandList<'a> { pub commands: Vec<Command<'a>>, } -impl<'a> FuncCommands<'a> { +impl<'a> CommandList<'a> { /// Create an empty command list. - pub fn new() -> FuncCommands<'a> { - FuncCommands { commands: vec![] } + pub fn new() -> CommandList<'a> { + CommandList { commands: vec![] } } /// Add a command to the sequence. @@ -59,7 +58,7 @@ impl<'a> FuncCommands<'a> { } } -impl<'a> IntoIterator for FuncCommands<'a> { +impl<'a> IntoIterator for CommandList<'a> { type Item = Command<'a>; type IntoIter = std::vec::IntoIter<Command<'a>>; @@ -68,13 +67,23 @@ impl<'a> IntoIterator for FuncCommands<'a> { } } +impl<'a> IntoIterator for &'a CommandList<'a> { + type Item = &'a Command<'a>; + type IntoIter = std::slice::Iter<'a, Command<'a>>; + + fn into_iter(self) -> Self::IntoIter { + self.commands.iter() + } +} + /// Commands requested for execution by functions. #[derive(Debug)] pub enum Command<'a> { Layout(&'a SyntaxTree), Add(Layout), AddMany(MultiLayout), - ToggleStyleClass(FontClass), + SetAlignment(Alignment), + SetStyle(TextStyle), } /// A helper trait that describes requirements for types that can implement |
