mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
This commit is contained in:
parent
90f5699fff
commit
f08593f0f8
5 changed files with 64 additions and 89 deletions
|
|
@ -85,7 +85,7 @@ impl<E: Output> Measure<E> {
|
|||
pub fn format (&self) -> Arc<str> {
|
||||
format!("{}x{}", self.w(), self.h()).into()
|
||||
}
|
||||
pub fn of <T: Content<E>> (&self, item: T) -> Bsp<Fill<&Self>, T> {
|
||||
pub fn of <T: Render<E>> (&self, item: T) -> Bsp<Fill<&Self>, T> {
|
||||
Bsp::b(Fill::xy(self), item)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,12 @@
|
|||
use crate::*;
|
||||
|
||||
#[macro_export] macro_rules! view {
|
||||
($Output:ty: |$self:ident: $State:ty| $expr:expr; {
|
||||
$($sym:literal => $body:expr),* $(,)?
|
||||
}) => {
|
||||
impl Content<$Output> for $State {
|
||||
fn content (&$self) -> impl Render<$Output> { $expr }
|
||||
}
|
||||
impl<'a> ViewContext<'a, $Output> for $State {
|
||||
fn get_content_sym (&'a $self, iter: &Value<'a>) -> Perhaps<RenderBox<'a, $Output>> {
|
||||
Ok(if let Value::Sym(s) = value {
|
||||
match *s {
|
||||
$($sym => Some($body.boxed()),)*
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
return Err(format!("expected content, got: {iter:?}").into())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An ephemeral wrapper around view state and view description,
|
||||
// that is meant to be constructed and returned from [Content::content].
|
||||
#[cfg(feature = "dsl")]
|
||||
pub struct View<'a, T>(
|
||||
pub &'a T,
|
||||
pub TokenIter<'a>
|
||||
);
|
||||
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<'a, O: Output + 'a, T: ViewContext<'a, O>> Content<O> for View<'a, T> {
|
||||
fn content (&self) -> impl Render<O> {
|
||||
let mut iter = self.1.clone();
|
||||
while let Some(Token { value, .. }) = iter.peek() {
|
||||
if let Ok(Some(content)) = self.0.get_content(&mut iter) {
|
||||
return Some(content)
|
||||
// TODO handle errors here, how?
|
||||
// error receiver trait in viewcontext?
|
||||
}
|
||||
#[macro_export] macro_rules! try_delegate {
|
||||
($s:ident, $dsl:expr, $T:ty) => {
|
||||
let value: Option<$T> = FromDsl::take_from($s, $dsl)?;
|
||||
if let Some(value) = value {
|
||||
return Ok(Some(value.boxed()))
|
||||
}
|
||||
return None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,13 +61,3 @@ pub trait ViewContext<'state, E: Output + 'state>: Send + Sync
|
|||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "dsl")]
|
||||
#[macro_export] macro_rules! try_delegate {
|
||||
($s:ident, $dsl:expr, $T:ty) => {
|
||||
let value: Option<$T> = FromDsl::take_from($s, $dsl)?;
|
||||
if let Some(value) = value {
|
||||
return Ok(Some(value.boxed()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue