suzy/
lib.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5#![warn(missing_docs)]
6#![warn(clippy::clone_on_ref_ptr)]
7#![warn(clippy::todo)]
8#![warn(clippy::print_stdout)]
9#![allow(clippy::needless_doctest_main)]
10
11//! ## Create an application with Suzy
12//!
13//! Suzy allows you to create a GUI comprised of widgets.
14//!
15//! The most basic app template will look something like this:
16//!
17//! ```rust,no_run
18//! # use suzy::widget::*;
19//! #[derive(Default)]
20//! struct Data { }
21//!
22//! impl WidgetContent for Data {
23//!     fn init(_init: impl WidgetInit<Self>) {}
24//!     fn children(&mut self, _receiver: impl WidgetChildReceiver) {}
25//!     fn graphics(&mut self, _receiver: impl WidgetGraphicReceiver) {}
26//! }
27//!
28//! fn main() {
29//!     Data::run_as_app();
30//! }
31//! ```
32//!
33//! ## Watch System
34//!
35//! Suzy's watch system provides the main way to define functionality within
36//! the framework.  It enables you to describe the relationships between
37//! widgets in a declarative way.
38//!
39//! For example, if you wanted to make a widget half the width of its
40//! parent:
41//!
42//! ```rust
43//! # use suzy::widget::*;
44//! # use suzy::dims::Rect;
45//! # struct Data { child: Widget<()> }
46//! # impl WidgetContent for Data {
47//! #     fn init(mut init: impl WidgetInit<Self>) {
48//! init.watch(|this, rect| {
49//!     this.child.set_width(rect.width() / 2.0);
50//! });
51//! #     }
52//! #     fn children(&mut self, _receiver: impl WidgetChildReceiver) {}
53//! #     fn graphics(&mut self, _receiver: impl WidgetGraphicReceiver) {}
54//! # }
55//! ```
56//!
57//! When the parent changes size, the closure will be re-run and update the
58//! size of the child.
59//!
60//! See the [`watch`](watch/index.html) module documentation for more
61//! information about the watch system.
62
63pub mod adapter;
64pub mod animation;
65pub mod app;
66pub mod dims;
67pub mod graphics;
68pub mod platform;
69pub mod pointer;
70pub mod selectable;
71pub mod units;
72pub mod watch;
73pub mod widget;
74pub mod widgets;
75pub mod window;
76
77/// A version of the tweak! macro from the crate
78/// [`inline_tweak`](https://crates.io/crates/inline_tweak), but designed to
79/// work within Suzy's watch system.
80///
81/// Using this macro in a watch closure will cause the closure to be re-run
82/// periodically, so that a tweaked value in the parsed source code can
83/// be observed.
84///
85/// This macro is available if the `inline_tweak` feature is enabled for Suzy.
86#[cfg(feature = "inline_tweak")]
87#[cfg(debug_assertions)]
88#[macro_export]
89macro_rules! tweak {
90    // this macro adapted from crate `inline_tweak`, version 1.0.8
91    ($default:expr) => {{
92        $crate::app::App::<$crate::platform::DefaultPlatform>::coarse_time();
93        $crate::watch::inline_tweak(None, file!(), line!(), column!())
94            .unwrap_or_else(|| $default)
95    }};
96    ($value:literal; $default:expr) => {{
97        $crate::app::App::<$crate::platform::DefaultPlatform>::coarse_time();
98        $crate::watch::inline_tweak(Some($value), file!(), line!(), column!())
99            .unwrap_or_else(|| $default)
100    }};
101}
102
103#[cfg(feature = "inline_tweak")]
104#[cfg(not(debug_assertions))]
105#[macro_export]
106macro_rules! tweak {
107    // this macro adapted from crate `inline_tweak`, version 1.0.8
108    ($default:expr) => {
109        $default
110    };
111    ($value:literal; $default:expr) => {
112        $default
113    };
114}