Update example to show props deriving, text macro, etc
This commit is contained in:
parent
290b57d336
commit
241cae3c93
7 changed files with 50 additions and 24 deletions
|
|
@ -23,7 +23,7 @@ pub struct FragmentProps;
|
|||
pub struct Fragment;
|
||||
|
||||
impl Fragment {
|
||||
fn default_props() -> FragmentProps {
|
||||
pub fn default_props() -> FragmentProps {
|
||||
FragmentProps {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use std::sync::Mutex;
|
||||
|
||||
use alchemy_styles::{Appearance, Layout, StylesList};
|
||||
use alchemy_styles::{Appearance, Layout};
|
||||
|
||||
use alchemy_lifecycle::ComponentKey;
|
||||
use alchemy_lifecycle::error::Error;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ use std::sync::Arc;
|
|||
pub use lazy_static::lazy_static;
|
||||
use proc_macro_hack::proc_macro_hack;
|
||||
|
||||
pub use alchemy_lifecycle::ComponentKey;
|
||||
pub use alchemy_lifecycle::{ComponentKey, text};
|
||||
pub use alchemy_lifecycle::traits::{
|
||||
AppDelegate, Component, Props, WindowDelegate
|
||||
AppDelegate, Component, Props as ComponentProps, WindowDelegate
|
||||
};
|
||||
|
||||
pub use alchemy_lifecycle::error::Error;
|
||||
|
|
@ -24,6 +24,7 @@ pub use alchemy_macros::rsx;
|
|||
|
||||
#[proc_macro_hack]
|
||||
pub use alchemy_macros::styles;
|
||||
pub use alchemy_macros::Props;
|
||||
|
||||
pub use alchemy_styles::{Color, styles as style_attributes, SpacedSet, StyleSheet, StylesList};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/// @created March 26th, 2019
|
||||
|
||||
use alchemy::{
|
||||
AppDelegate, Component, ComponentKey, Fragment, Props, Error, rsx, RSX, styles,
|
||||
AppDelegate, Component, ComponentKey, Fragment, Error, Props, rsx, RSX, styles, text,
|
||||
Text, View, Window, WindowDelegate
|
||||
};
|
||||
|
||||
|
|
@ -24,26 +24,26 @@ impl AppDelegate for AppState {
|
|||
}
|
||||
}
|
||||
|
||||
/*#[derive(Default)]
|
||||
pub struct Banner;
|
||||
#[derive(Default)]
|
||||
struct BannerProps {}
|
||||
|
||||
#[derive(Props)]
|
||||
struct Banner;
|
||||
|
||||
impl Component for Banner {
|
||||
type Props = Box<()>;
|
||||
type State = Box<()>;
|
||||
|
||||
fn constructor(_key: ComponentKey) -> Banner {
|
||||
fn new(_key: ComponentKey) -> Banner {
|
||||
Banner {}
|
||||
}
|
||||
|
||||
fn render(&self, props: &Self::Props) -> Result<RSX, Error> {
|
||||
fn render(&self, children: Vec<RSX>) -> Result<RSX, Error> {
|
||||
Ok(rsx! {
|
||||
<Fragment>
|
||||
<View styles=["wut1"]></View>
|
||||
//{props.children.clone()}
|
||||
{children}
|
||||
</Fragment>
|
||||
})
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
pub struct WindowState;
|
||||
|
||||
|
|
@ -55,17 +55,16 @@ impl WindowDelegate for WindowState {
|
|||
fn render(&self) -> Result<RSX, Error> {
|
||||
let messages = vec!["LOL"]; //, "wut", "BERT"];
|
||||
Ok(rsx! {
|
||||
<View styles={messages}>
|
||||
<View styles={&messages}>
|
||||
<Text styles=["message"]>"Hello there, my name is Bert"</Text>
|
||||
<View styles=["boxxx"] />
|
||||
/*{messages.iter().map(|message| rsx! {
|
||||
<View>{text!("{}", message)}</View>
|
||||
})}*/
|
||||
{messages.iter().map(|message| rsx! {
|
||||
<Text styles=["text"]>{text!("{}", message)}</Text>
|
||||
})}
|
||||
<View styles=["box1"]>
|
||||
//<View styles=["box1"]></View>
|
||||
//<Banner>
|
||||
//<View styles=["innermostBox"] />
|
||||
//</Banner>
|
||||
<Banner>
|
||||
<View styles=["innermostBox"] />
|
||||
</Banner>
|
||||
</View>
|
||||
</View>
|
||||
})
|
||||
|
|
@ -88,6 +87,7 @@ fn main() {
|
|||
}
|
||||
|
||||
message { width: 500; height: 100; background-color: yellow; color: black; }
|
||||
text { width: 500; height: 100; background-color: blue; color: white; }
|
||||
|
||||
boxxx {
|
||||
background-color: rgba(245, 217, 28, .8);
|
||||
|
|
|
|||
|
|
@ -26,3 +26,13 @@ pub use reconciler::key::ComponentKey;
|
|||
lazy_static! {
|
||||
pub static ref RENDER_ENGINE: RenderEngine = RenderEngine::new();
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! text {
|
||||
($t:expr) => {
|
||||
alchemy::RSX::text($t)
|
||||
};
|
||||
($format:tt, $($tail:expr),*) => {
|
||||
alchemy::RSX::text(format!($format, $($tail),*))
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,13 +90,13 @@ pub fn writable_props_derive(input: TokenStream) -> TokenStream {
|
|||
|
||||
TokenStream::from(quote! {
|
||||
impl #impl_generics #name #ty_generics #where_clause {
|
||||
fn default_props() -> #name_props {
|
||||
pub fn default_props() -> #name_props {
|
||||
#name_props::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl #impl_generics alchemy::ComponentProps for #name #ty_generics #where_clause {
|
||||
fn set_props(&mut self, new_props: &mut Any) {
|
||||
fn set_props(&mut self, new_props: &mut std::any::Any) {
|
||||
match new_props.downcast_ref::<#name_props>() {
|
||||
Some(props) => { },
|
||||
None => { panic!("Woah there, somehow the wrong props were being passed!"); }
|
||||
|
|
|
|||
|
|
@ -121,6 +121,21 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, A: Ord + FromStr> From<&Vec<&'a str>> for SpacedSet<A>
|
||||
where
|
||||
<A as FromStr>::Err: Debug,
|
||||
{
|
||||
fn from(s: &Vec<&'a str>) -> Self {
|
||||
let mut list = Self::new();
|
||||
|
||||
for key in s {
|
||||
list.insert(FromStr::from_str(key).unwrap());
|
||||
}
|
||||
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, A: Ord + FromStr> From<(&'a str, &'b str)> for SpacedSet<A>
|
||||
where
|
||||
<A as FromStr>::Err: Debug,
|
||||
|
|
|
|||
Reference in a new issue