diff options
Diffstat (limited to 'src/library/direction.rs')
| -rw-r--r-- | src/library/direction.rs | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/src/library/direction.rs b/src/library/direction.rs index 59c0d1fd..7bb11c99 100644 --- a/src/library/direction.rs +++ b/src/library/direction.rs @@ -1,59 +1,41 @@ use crate::func::prelude::*; -use super::maps::ConsistentMap; -use super::keys::AxisKey; +use super::maps::PosAxisMap; function! { /// `direction`: Sets the directions of the layouting axes. #[derive(Debug, PartialEq)] pub struct DirectionChange { body: Option<SyntaxTree>, - map: ConsistentMap<AxisKey, Direction>, + map: PosAxisMap<Direction>, } parse(args, body, ctx) { - let mut map = ConsistentMap::new(); - - map.add_opt(AxisKey::Primary, args.get_pos_opt::<Direction>()?)?; - map.add_opt(AxisKey::Secondary, args.get_pos_opt::<Direction>()?)?; - - for arg in args.keys() { - let axis = AxisKey::from_ident(&arg.v.key)?; - let value = Direction::from_expr(arg.v.value)?; - - map.add(axis, value)?; - } - DirectionChange { body: parse!(optional: body, ctx), - map, + map: PosAxisMap::new(&mut args)?, } } layout(self, mut ctx) { - let axes = ctx.axes; + ctx.base = ctx.spaces[0].dimensions; - let map = self.map.dedup(|key, &direction| { - Ok((match key { - AxisKey::Primary => Primary, - AxisKey::Secondary => Secondary, - AxisKey::Horizontal => Horizontal.to_generic(axes), - AxisKey::Vertical => Vertical.to_generic(axes), - }, direction)) + let map = self.map.dedup(ctx.axes, |direction| { + Some(direction.axis().to_generic(ctx.axes)) })?; - map.with(Primary, |&val| ctx.axes.primary = val); - map.with(Secondary, |&val| ctx.axes.secondary = val); + map.with(Primary, |&dir| ctx.axes.primary = dir); + map.with(Secondary, |&dir| ctx.axes.secondary = dir); if ctx.axes.primary.axis() == ctx.axes.secondary.axis() { error!( - "aligned primary and secondary axes: `{}`, `{}`", + "invalid aligned primary and secondary axes: `{}`, `{}`", format!("{:?}", ctx.axes.primary).to_lowercase(), format!("{:?}", ctx.axes.secondary).to_lowercase(), ); } match &self.body { - Some(body) => vec![AddMultiple(layout_tree(&body, ctx)?)], + Some(body) => vec![AddMultiple(layout(&body, ctx)?)], None => vec![Command::SetAxes(ctx.axes)], } } |
