input, output: formatting, warnings
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-08-10 21:50:17 +03:00
parent ab0dc3fae0
commit ab1afa219f
2 changed files with 24 additions and 47 deletions

View file

@ -62,7 +62,7 @@ impl<E: Clone + Ord, C> EventMap<E, C> {
/// Create event map from path to text file. /// Create event map from path to text file.
pub fn load_from_path <'s> ( pub fn load_from_path <'s> (
&'s mut self, path: impl AsRef<Path> &'s mut self, path: impl AsRef<Path>
) -> Usually<&mut Self> where Self: DslInto<C> + DslInto<E> { ) -> Usually<&'s mut Self> where Self: DslInto<C> + DslInto<E> {
if exists(path.as_ref())? { if exists(path.as_ref())? {
let source = read_to_string(&path)?; let source = read_to_string(&path)?;
let path: Arc<PathBuf> = Arc::new(path.as_ref().into()); let path: Arc<PathBuf> = Arc::new(path.as_ref().into());
@ -81,7 +81,7 @@ impl<E: Clone + Ord, C> EventMap<E, C> {
/// Load one event binding into the event map. /// Load one event binding into the event map.
pub fn load_from_source_one <'s> ( pub fn load_from_source_one <'s> (
&'s mut self, dsl: impl Dsl, path: &Option<&Arc<PathBuf>> &'s mut self, dsl: impl Dsl, path: &Option<&Arc<PathBuf>>
) -> Usually<&mut Self> where Self: DslInto<C> + DslInto<E> { ) -> Usually<&'s mut Self> where Self: DslInto<C> + DslInto<E> {
if let Some(exp) = dsl.head()?.exp()? if let Some(exp) = dsl.head()?.exp()?
&& let Some(sym) = exp.head()?.sym()? && let Some(sym) = exp.head()?.sym()?
&& let Some(tail) = exp.tail()? && let Some(tail) = exp.tail()?
@ -117,10 +117,10 @@ impl<E: Clone + Ord, C> EventMap<E, C> {
} }
impl<C> Binding<C> { impl<C> Binding<C> {
pub fn from_dsl (dsl: impl Dsl) -> Usually<Self> { pub fn from_dsl (dsl: impl Dsl) -> Usually<Self> {
let mut command: Option<C> = None; let command: Option<C> = None;
let mut condition: Option<Condition> = None; let condition: Option<Condition> = None;
let mut description: Option<Arc<str>> = None; let description: Option<Arc<str>> = None;
let mut source: Option<Arc<PathBuf>> = None; let source: Option<Arc<PathBuf>> = None;
if let Some(command) = command { if let Some(command) = command {
Ok(Self { command, condition, description, source }) Ok(Self { command, condition, description, source })
} else { } else {

View file

@ -777,27 +777,15 @@ pub struct Stack<E, F> {
callback: F callback: F
} }
impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Stack<E, F> { impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Stack<E, F> {
pub fn north (callback: F) -> Self { Self::new(North, callback) }
pub fn south (callback: F) -> Self { Self::new(South, callback) }
pub fn east (callback: F) -> Self { Self::new(East, callback) }
pub fn west (callback: F) -> Self { Self::new(West, callback) }
pub fn above (callback: F) -> Self { Self::new(Above, callback) }
pub fn below (callback: F) -> Self { Self::new(Below, callback) }
pub fn new (direction: Direction, callback: F) -> Self { pub fn new (direction: Direction, callback: F) -> Self {
Self { direction, callback, __: Default::default(), } Self { direction, callback, __: Default::default(), }
} }
pub fn north (callback: F) -> Self {
Self::new(North, callback)
}
pub fn south (callback: F) -> Self {
Self::new(South, callback)
}
pub fn east (callback: F) -> Self {
Self::new(East, callback)
}
pub fn west (callback: F) -> Self {
Self::new(West, callback)
}
pub fn above (callback: F) -> Self {
Self::new(Above, callback)
}
pub fn below (callback: F) -> Self {
Self::new(Below, callback)
}
} }
impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for Stack<E, F> { impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for Stack<E, F> {
fn layout (&self, to: E::Area) -> E::Area { fn layout (&self, to: E::Area) -> E::Area {
@ -808,6 +796,8 @@ impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for St
(self.callback)(&mut move |component: &dyn Render<E>|{ (self.callback)(&mut move |component: &dyn Render<E>|{
let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh(); let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh();
match self.direction { match self.direction {
North | West => { todo!() },
Above | Below => {},
South => { y = y.plus(h); South => { y = y.plus(h);
h_used = h_used.plus(h); h_used = h_used.plus(h);
h_remaining = h_remaining.minus(h); h_remaining = h_remaining.minus(h);
@ -816,16 +806,12 @@ impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for St
w_used = w_used.plus(w); w_used = w_used.plus(w);
w_remaining = w_remaining.minus(w); w_remaining = w_remaining.minus(w);
h_used = h_used.max(h); }, h_used = h_used.max(h); },
North | West => { todo!() },
Above | Below => {},
_ => unreachable!(),
} }
}); });
match self.direction { match self.direction {
North | West => { todo!() }, North | West => { todo!() },
South | East => { [to.x(), to.y(), w_used.into(), h_used.into()].into() }, South | East => { [to.x(), to.y(), w_used.into(), h_used.into()].into() },
Above | Below => { [to.x(), to.y(), to.w(), to.h()].into() }, Above | Below => { [to.x(), to.y(), to.w(), to.h()].into() },
_ => unreachable!(),
} }
} }
fn render (&self, to: &mut E) { fn render (&self, to: &mut E) {
@ -836,25 +822,16 @@ impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for St
(self.callback)(&mut move |component: &dyn Render<E>|{ (self.callback)(&mut move |component: &dyn Render<E>|{
let layout = component.layout([x, y, w_remaining, h_remaining].into()); let layout = component.layout([x, y, w_remaining, h_remaining].into());
match self.direction { match self.direction {
South => { Above | Below => { to.place(layout, component); }
y = y.plus(layout.h()); North | West => { todo!() },
h_remaining = h_remaining.minus(layout.h()); South => { y = y.plus(layout.h());
h_used = h_used.plus(layout.h()); h_remaining = h_remaining.minus(layout.h());
to.place(layout, component); h_used = h_used.plus(layout.h());
}, to.place(layout, component); },
East => { East => { x = x.plus(layout.w());
x = x.plus(layout.w()); w_remaining = w_remaining.minus(layout.w());
w_remaining = w_remaining.minus(layout.w()); w_used = w_used.plus(layout.h());
w_used = w_used.plus(layout.h()); to.place(layout, component); },
to.place(layout, component);
},
Above | Below => {
to.place(layout, component);
}
North | West => {
todo!()
},
_ => unreachable!()
} }
}); });
} }