haussmann/
lib.rs

1// This file is part of "haussmann"
2// Under the MIT License
3// Copyright (c) 2023 Antonin Hérault
4
5//! Integrate highly customizable widgets and themes for any Rust application
6//! or GUI library.
7//!
8//! ## Introduction
9//! More than explaining how to use this crate, this documentation want to help
10//! understand how the project is organized, and how the functions actually
11//! work. Tutorials, examples and more can be found on the
12//! [repository (GitHub)](https://github.com/antoninhrlt/haussmann).
13//!
14//! However, some examples can be found in this documentation when they are
15//! useful to understand how the item works. Sometimes, a good example is better
16//! than lines of documentation.
17//!
18//! This documentation is for people who want to contribute to the project but
19//! also for people who just want to understand some concepts.
20//!
21//! ## Purpose
22//! This project is not a GUI library itself, but it gives highly customizable
23//! widgets and themes to be integrated in a GUI library or directly in an
24//! application using a system API
25//! ([windows-rs](https://github.com/microsoft/windows-rs),
26//! [x11rb](https://github.com/psychon/x11rb), ...). Furthermore, the crate
27//! contains tools to transform widgets into shapes and to place and align
28//! widgets on a drawable surface. The [`Drawer`](graphics::Drawer) trait can be
29//! implemented on a drawable surface to easily draw widgets on it.
30//!
31//! ## Organization
32//! The crate is organized in different parts:
33//! - Widgets (located in [`mod@widgets`])
34//! - Controllers (located in [`controllers`]), they are also widgets but not
35//! designed to be drawn but to wrap a widget and control stuff like events on
36//! it.
37//! - Utilities: simple structures, parameters for widgets... (located in
38//! [`crate`])
39//! - Graphics: drawer, aligner, shapes... (located in [`graphics`])
40//!
41//! ## Note
42//! This project want to have the simplest usage possible. Indeed, imports are
43//! simplified the most possible (well, it does not mean all elements can be
44//! imported from the crate, but repetition is avoided and imports like
45//! `crate::widgets::Widget` are replaced by `crate::Widget` for example) and
46//! widgets have different constructors to avoid filling all the fields when
47//! they are not all defined (check the widgets documentation).
48
49#![warn(missing_docs)]
50
51#[path = "../controllers/mod.rs"]
52pub mod controllers;
53
54#[path = "../widgets/mod.rs"]
55pub mod widgets;
56
57pub mod graphics;
58
59mod align;
60mod border;
61mod direction;
62mod font;
63mod overflow;
64mod radius;
65mod theme;
66
67pub use align::{Align, TextAlign};
68pub use border::Border;
69pub use direction::Direction;
70pub use font::*;
71pub use overflow::Overflow;
72pub use radius::Radius;
73pub use theme::{TextTheme, Theme};
74
75pub use widgets::{DebugWidget, Widget};
76
77/// Trait to implement on *any* object in order to be able to convert it as a
78/// [`std::any::Any`] value.
79pub trait ToAny {
80    /// Converts the `self` value into a [`std::any::Any`] value.
81    ///
82    /// Generally implemented as following:
83    /// ```
84    /// impl ToAny for Foo {
85    ///     fn as_any(&self) -> &dyn std::any::Any {
86    ///         self
87    ///     }    
88    /// }
89    /// ```
90    fn as_any(&self) -> &dyn std::any::Any;
91}