openkit/
lib.rs

1//! # OpenKit
2//!
3//! A cross-platform CSS-styled UI framework for Rust.
4//!
5//! OpenKit provides a consistent, beautiful UI experience across Windows, macOS, Linux,
6//! and FreeBSD with CSS-powered styling and a Tailwind-inspired design system.
7//!
8//! ## Supported Platforms
9//!
10//! - **Windows**: Windows 10 and later
11//! - **macOS**: macOS 10.15 (Catalina) and later
12//! - **Linux**: X11 and Wayland (GNOME, KDE, Sway, Hyprland, etc.)
13//! - **FreeBSD**: X11 with common desktop environments
14//!
15//! ## Quick Start
16//!
17//! ```rust,ignore
18//! use openkit::prelude::*;
19//!
20//! App::new()
21//!     .title("My App")
22//!     .theme(Theme::Auto)
23//!     .run(|| {
24//!         col![16;
25//!             label!("Hello, OpenKit!"),
26//!             button!("Click me", { println!("Clicked!"); }),
27//!         ]
28//!     });
29//! ```
30//!
31//! ## Declarative Macros
32//!
33//! OpenKit provides ergonomic macros for building UIs:
34//!
35//! ```rust
36//! use openkit::prelude::*;
37//!
38//! // Layout macros
39//! let ui = col![16;                          // Column with 16px gap
40//!     label!("Welcome!"),
41//!     row![8;                                // Row with 8px gap
42//!         button!("OK", { /* handler */ }),
43//!         button!("Cancel", Secondary),
44//!     ],
45//! ];
46//!
47//! // Widget macros
48//! let btn = button!("Save", { println!("Saved!"); });
49//! let cb = checkbox!("Enable", |checked| println!("{}", checked));
50//! let tf = textfield!("Enter name...", |val| println!("{}", val));
51//!
52//! // Utility macros
53//! let classes = class!["btn", "primary", "large"];
54//! let styles = style! { padding: 16, color: "blue" };
55//! ```
56
57pub mod app;
58#[macro_use]
59pub mod component;
60pub mod css;
61pub mod event;
62pub mod geometry;
63pub mod layout;
64#[macro_use]
65pub mod macros;
66pub mod platform;
67pub mod render;
68pub mod theme;
69pub mod widget;
70
71// Re-export proc macros when the feature is enabled
72#[cfg(feature = "macros")]
73pub use openkit_macros::{Widget, Component, Styleable, component, prop, state, event};
74
75pub mod prelude {
76    //! Convenient re-exports for common types.
77
78    // Core types
79    pub use crate::app::App;
80    pub use crate::css::{StyleManager, StyleBuilder, CssLoadError};
81    pub use crate::event::{Event, MouseButton, MouseEvent, KeyEvent, Key, Modifiers};
82    pub use crate::geometry::{Point, Size, Rect, Color, BorderRadius, EdgeInsets};
83    pub use crate::layout::{Layout, Alignment, Padding};
84    pub use crate::theme::Theme;
85
86    // Widget types
87    pub use crate::widget::{Widget, WidgetId};
88    pub use crate::widget::avatar::{Avatar, AvatarSize, AvatarShape};
89    pub use crate::widget::bar::{Bar, BarPosition, BarVariant};
90    pub use crate::widget::button::{Button, ButtonVariant};
91    pub use crate::widget::card::{Card, CardVariant};
92    pub use crate::widget::checkbox::Checkbox;
93    pub use crate::widget::clock::{Clock, ClockFormat, DateFormat};
94    pub use crate::widget::container::{Column, Row};
95    pub use crate::widget::context_menu::{ContextMenu, MenuItem};
96    pub use crate::widget::desktop::{Desktop, DesktopIcon, Wallpaper, WallpaperMode, GradientDirection};
97    pub use crate::widget::dropdown::{Dropdown, DropdownOption};
98    pub use crate::widget::icon_button::{IconButton, IconButtonSize, IconButtonVariant};
99    pub use crate::widget::label::Label;
100    pub use crate::widget::list_view::{ListView, ListItem, SelectionMode};
101    pub use crate::widget::notification::{Notification, NotificationUrgency};
102    pub use crate::widget::password_field::PasswordField;
103    pub use crate::widget::progress::{Progress, ProgressVariant, ProgressSize};
104    pub use crate::widget::scroll_view::{ScrollView, ScrollBarVisibility};
105    pub use crate::widget::separator::{Separator, SeparatorOrientation};
106    pub use crate::widget::slider::{Slider, SliderOrientation};
107    pub use crate::widget::spacer::Spacer;
108    pub use crate::widget::spinner::{Spinner, SpinnerSize};
109    pub use crate::widget::switch::{ToggleSwitch, ToggleSwitchSize};
110    pub use crate::widget::system_tray::{SystemTray, TrayIcon};
111    pub use crate::widget::tabs::{Tabs, Tab, TabPosition, TabVariant};
112    pub use crate::widget::textfield::TextField;
113    pub use crate::widget::tooltip::{Tooltip, TooltipPosition};
114    pub use crate::widget::window::{Window, WindowVariant, WindowControlsStyle};
115    pub use crate::widget::workspace::{WorkspaceSwitcher, WorkspaceItem};
116
117    // Component system (Angular-like)
118    pub use crate::component::{
119        // Core types
120        State, EventEmitter, Model, Binding,
121        ComponentBuilder, BuiltComponent, ComponentContext,
122        component,
123        // Lifecycle
124        Lifecycle, Changes,
125        // Directives
126        If, For, Switch,
127        // Pipes
128        Pipe, UppercasePipe, LowercasePipe, CurrencyPipe,
129    };
130
131    // Re-export all declarative macros
132    pub use crate::{
133        // Widget macros
134        view, col, row, class, style,
135        button, checkbox, textfield, label,
136        when, match_widget, for_each, spacer, dbg_widget,
137        // Angular-like macros
138        define_component, ng_if, ng_for, ng_switch,
139        bind, on, model,
140    };
141
142    // Re-export proc macros when enabled
143    #[cfg(feature = "macros")]
144    pub use openkit_macros::{Widget, Component, Styleable, component, prop, state, event};
145
146    // Platform utilities
147    pub use crate::platform::{init as platform_init, platform_name, is_desktop};
148}
149
150/// Re-export of the error types
151pub use crate::app::AppError;