A macro for constructing views that is non framework specific.
rust
let images = vec!["coffee.png","cream.png","sugar.png"];
let v = view!{
VStack(direction:TOP_TO_BOTTOM) {
Image("company.png")
Button(text:"order".to_owned(),style:BOLD)
.on_click(|x|{ do_order() }) {
Image("order_icon.png")
}
( Image::from_names(images) )
Footer
}
};
will translate to
rust
let images = vec!["coffee.png","cream.png","sugar.png"];
let v = {
let o = VStack { direction: TOP_TO_BOTTOM, ..Default::default() }
o.construct({
let mut children = AnyVec::new();
children.push({
let o = Image::new("company.png");
o.construct(None)
o
});
children.push({
let o = Button { text: "a".to_owned(), style: BOLD, ..Default::default() };
o.on_click(|x|{ do_order() });
o.construct(Some({
let o = Image::new("order_icon.png");
o.construct(None)
o
}));
o
});
for i in Image::from_names(images).into_iter() {
children.push(i)
}
children.push({
let o = Footer{ ..Default::default() };
o.construct(None)
o
});
Some(children)
});
o
};
This project really isn't framework specific, but it does have certain rules:
fn construct(&mut self, children:Option<AnyVec>)
implemented ( a View trait is included to help with this )Here's a simple example to follow:
```rust
struct VStack { direction: u8, children: AnyVec }
impl VStack { fn new(direction:u8){ ... }
fn construct(&mut self, children:Option
An optional helper trait exists for defining view behavior.
rust
trait View {
fn construct(&mut self, children:Option<AnyVec>)
}
A derive macro can be used if your component does nothing with children
```rust
struct Button(text:String) ```