Skip to content

Instantly share code, notes, and snippets.

@ndugger
Last active March 11, 2019 16:07
Show Gist options
  • Save ndugger/3ecbfcf397f4e9ca3000db0a9ac74220 to your computer and use it in GitHub Desktop.
Save ndugger/3ecbfcf397f4e9ca3000db0a9ac74220 to your computer and use it in GitHub Desktop.
mod wjet;
use wjet::core::Event;
use wjet::core::Tree;
use wjet::core::Widget;
use wjet::shape::Rectangle;
use wjet::shape::Typography;
pub struct Button {
width: u32,
height: u32,
emit: Option<str>,
variant: Option<str>
}
impl Button {
fn handle_click(&self, event: Event<Button>) {
println!("button was clicked");
}
}
impl Widget for Button {
fn render(&self, children: Tree) -> Tree {
let width = self.width;
let height = self.height;
wml! {
<Rectangle { width, height, on_click: |e| { self.handle_click(e) } }>
<Typography { width, height }>
<{ children };>
<;Typography>
<;Rectangle>
}
}
}
mod wjet;
use wjet::core::Event;
use wjet::core::Tree;
use wjet::core::Widget;
use crate::button::Button;
use crate::layout::FlexBox;
pub struct Form;
impl Form {
fn handle_submit(&self, event: Event<Form>) {
println!("form was submitted");
}
}
impl Widget for Form {
fn render(&self, children: Tree) -> Tree {
let enable_message = true;
wml! {
<FlexBox { direction: "vertical" }>
#[if(enable_message)] {
<Typography { variant: "message" }>
<{ "This Is A Message" };>
<;Typography>
}
<Button { emit: "submit", height: 32, width: 256 }>
<{ "Submit Form" };>
<;Button>
<;FlexBox>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment