gooey/
lib.rs

1//! # gooey <IMG STYLE="vertical-align: middle" SRC="https://gitlab.com/spearman/gooey/-/raw/master/splatl.png">
2//!
3//! > UI library
4//!
5//! A gooey [`Interface`] is defined as a layer between an [`Application`] and a
6//! [`Presentation`] backend.
7//!
8//! An `Application` implementation can handle
9//! [`Callbacks`](application::Callback) on [`model`](interface::model) data
10//! bound to the `Interface`, and a `Presentation` backend can receive
11//! [`Input`](interface::view::Input) from the user or OS and display a
12//! [`view`](interface::view) of the interface.
13//!
14//! ```
15//! use gooey::{application, presentation, widget, Presentation};
16//! use gooey::interface::{self, Interface, view};
17//! // create a default interface with a headless presentation layer that reads
18//! // from stdin and ignores all display values
19//! let mut interface =
20//!   presentation::Headless::make_interface::<application::Default>();
21//! // attach a widget to the root node
22//! let root_id = interface.root_id().clone();
23//! let action  = interface::Action::create_singleton (
24//!   widget::playback::new (None), interface::CreateOrder::Append);
25//! for event in interface.action (&root_id, action) {
26//!   // ... model events
27//! }
28//! // get stdin and update the interface
29//! for event in interface.update() {
30//!   // ... model events
31//! }
32//! interface.display();  // no-op
33//! ```
34//!
35//! See `./examples/` for complete examples.
36
37#![warn(unused_extern_crates)]
38#![feature(associated_type_defaults)]
39#![feature(decl_macro)]
40#![cfg_attr(docsrs, feature(doc_cfg))]
41
42#[doc(hidden)] pub use serde;
43#[doc(hidden)] pub use strum;
44
45pub use id_tree as tree;
46pub use tree::Tree;
47pub use nsys::{geometry, math};
48
49pub mod application;
50pub mod interface;
51pub mod presentation;
52pub mod utils;
53pub mod widget;
54
55pub mod prelude;
56
57pub use self::application::Application;
58pub use self::interface::Interface;
59pub use self::presentation::Presentation;
60pub use self::utils::TreeHelper;
61pub use self::widget::Widget;
62
63#[doc(hidden)]
64#[allow(unused_macros)]
65pub (crate) macro debug {
66  ($e:expr) => {
67    log::debug!("{}: {:?}", stringify!($e), $e);
68  }
69}
70
71#[doc(hidden)]
72#[allow(unused_macros)]
73pub (crate) macro pretty {
74  ($e:expr) => {
75    log::debug!("{}: {:#?}", stringify!($e), $e);
76  }
77}
78
79#[doc(hidden)]
80macro_rules! show {
81  ($e:expr) => { println!("{}: {:?}", stringify!($e), $e); }
82}
83
84/// Diagnostic print sizes of various types
85pub fn report_sizes() {
86  use std::mem::size_of;
87  println!("gooey: report sizes...");
88
89  show!(size_of::<Interface>());
90  show!(size_of::<interface::Element>());
91  show!(size_of::<interface::Model>());
92  show!(size_of::<interface::Controller>());
93  show!(size_of::<interface::controller::Appearances>());
94  show!(size_of::<interface::controller::component::Layout>());
95  show!(size_of::<interface::View>());
96  show!(size_of::<interface::view::component::Canvas>());
97  show!(size_of::<interface::Action>());
98  show!(size_of::<interface::model::Event>());
99  show!(size_of::<interface::view::Input>());
100
101  #[cfg(feature="curses")]
102  show!(size_of::<Interface <application::Default, presentation::Curses>>());
103  #[cfg(feature="fmod")]
104  show!(size_of::<Interface <application::Default, presentation::Fmod>>());
105
106  println!("gooey: ...report sizes");
107}