summaryrefslogtreecommitdiff
path: root/src/func.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/func.rs')
-rw-r--r--src/func.rs50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/func.rs b/src/func.rs
index 776f0e98..a7044b6e 100644
--- a/src/func.rs
+++ b/src/func.rs
@@ -4,9 +4,10 @@ use std::any::Any;
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter};
-use crate::layout::{Layout, LayoutContext, LayoutResult};
+use toddle::query::FontClass;
+use crate::layout::{Layout, MultiLayout , LayoutContext, LayoutResult};
use crate::parsing::{ParseContext, ParseResult};
-use crate::syntax::FuncHeader;
+use crate::syntax::{SyntaxTree, FuncHeader};
/// Typesetting function types.
@@ -25,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<Option<Layout>>;
+ fn layout(&self, ctx: LayoutContext) -> LayoutResult<FuncCommands>;
}
impl PartialEq for dyn Function {
@@ -34,6 +35,49 @@ impl PartialEq for dyn Function {
}
}
+/// A sequence of commands requested for execution by a function.
+#[derive(Debug)]
+pub struct FuncCommands {
+ pub commands: Vec<Command>
+}
+
+impl FuncCommands {
+ /// Create an empty command list.
+ pub fn new() -> FuncCommands {
+ FuncCommands {
+ commands: vec![],
+ }
+ }
+
+ /// Add a command to the sequence.
+ pub fn add_command(&mut self, command: Command) {
+ self.commands.push(command);
+ }
+
+ /// Whether there are any commands in this sequence.
+ pub fn is_empty(&self) -> bool {
+ self.commands.is_empty()
+ }
+}
+
+impl IntoIterator for FuncCommands {
+ type Item = Command;
+ type IntoIter = std::vec::IntoIter<Command>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.commands.into_iter()
+ }
+}
+
+/// Commands requested for execution by functions.
+#[derive(Debug)]
+pub enum Command {
+ Layout(SyntaxTree),
+ Add(Layout),
+ AddMany(MultiLayout),
+ ToggleStyleClass(FontClass),
+}
+
/// A helper trait that describes requirements for types that can implement [`Function`].
///
/// Automatically implemented for all types which fulfill to the bounds `Debug + PartialEq +