//! The README's hello world: a component with state, Tailwind utilities as //! attributes, and a hover style. `cargo run --release --example hello` //! (`--screenshot out.png` renders it headless instead). use blenderui::prelude::*; #[component] fn counter(label: &str) { let (count, set_count) = use_state(0); rsx! {
{label.to_string()} ": " {count().to_string()}
"Add one"
} } struct Hello; impl Render for Hello { fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { rsx! {

"Hello, BUI"

// a real Blender slider } } } fn main() { let shot = std::env::args().skip_while(|a| a != "--screenshot").nth(1); let app = if shot.is_some() { Application::headless() } else { Application::new() }; app.run(move |cx| { let opts = WindowOptions { window_bounds: Some(WindowBounds::Windowed(Bounds { origin: point(px(0.0), px(0.0)), size: size(px(420.0), px(260.0)), })), ..Default::default() }; let win = cx.open_window(opts, |_, cx| cx.new(|_| Hello)).unwrap(); if let Some(path) = &shot { let (w, h, px) = cx.draw(win.id); let rgba: Vec = px.iter().flat_map(|p| [(p >> 16) as u8, (p >> 8) as u8, *p as u8, 255]).collect(); let file = std::fs::File::create(path).expect("create png"); let mut enc = png::Encoder::new(std::io::BufWriter::new(file), w as u32, h as u32); enc.set_color(png::ColorType::Rgba); enc.set_depth(png::BitDepth::Eight); enc.write_header().expect("png").write_image_data(&rgba).expect("png"); } }); }