#![recursion_limit = "1024"] use vgtk::ext::*; use vgtk::lib::gdk_pixbuf::Pixbuf; use vgtk::lib::gio::{ActionExt, ApplicationFlags, Cancellable, MemoryInputStream, SimpleAction}; use vgtk::lib::glib::Bytes; use vgtk::lib::gtk::*; use vgtk::{gtk, gtk_if, run, Callback, Component, UpdateAction, VNode}; static DOG: &[u8] = include_bytes!("dog.png"); pub struct AboutDialog { dog: Pixbuf, } impl Default for AboutDialog { fn default() -> Self { let data_stream = MemoryInputStream::new_from_bytes(&Bytes::from_static(DOG)); let dog = Pixbuf::new_from_stream(&data_stream, None as Option<&Cancellable>).unwrap(); AboutDialog { dog } } } impl Component for AboutDialog { type Message = (); type Properties = (); fn view(&self) -> VNode { gtk! { , DialogFlags::MODAL, &[("Ok", ResponseType::Ok)] )> } } } impl AboutDialog { #[allow(unused_must_use)] fn run() { vgtk::run_dialog::(vgtk::current_window().as_ref()); } } #[derive(Clone, Debug, Default)] pub struct Radio { pub labels: &'static [&'static str], pub active: usize, pub on_changed: Callback, } #[derive(Clone, Debug)] pub enum RadioMessage { Changed(usize), } #[derive(Clone, Debug)] struct Task { text: String, done: bool, } impl Component for Radio { type Message = RadioMessage; type Properties = Self; fn update(&mut self, msg: Self::Message) -> UpdateAction { match msg { RadioMessage::Changed(index) => { self.on_changed.send(index); UpdateAction::Render } } } fn create(props: Self) -> Self { props } fn change(&mut self, props: Self) -> UpdateAction { *self = props; UpdateAction::Render } fn view(&self) -> VNode { gtk! { { self.labels.iter().enumerate().map(|(index, label)| gtk! { }) } } } } impl Task { fn new(text: S, done: bool) -> Self { Self { text: text.to_string(), done, } } fn label(&self) -> String { if self.done { format!( r#"{}"#, self.text ) } else { self.text.clone() } } fn render(&self, index: usize) -> VNode { gtk! {