termux_gui/lib.rs
1//! # Termux GUI Rust Bindings
2//!
3//! This library provides Rust bindings for Termux:GUI, allowing you to create
4//! native Android GUI applications using Rust in the Termux environment.
5//!
6//! ## Quick Start
7//!
8//! ```rust,no_run
9//! use termux_gui::{Activity, Result};
10//!
11//! fn main() -> Result<()> {
12//! // Create an activity (dialog mode)
13//! let mut activity = Activity::new(true)?;
14//!
15//! // Create a layout
16//! let layout = activity.create_linear_layout(None)?;
17//!
18//! // Add a title
19//! let mut title = activity.create_text_view("Hello Termux!", Some(layout.id()))?;
20//! title.set_text_size(&mut activity, 24)?;
21//!
22//! // Add a button
23//! let button = activity.create_button("Click Me", Some(layout.id()))?;
24//!
25//! // Event loop
26//! use std::io::Read;
27//! let mut buf = [0u8; 1024];
28//! loop {
29//! let n = activity.event_stream().read(&mut buf)?;
30//! if n > 0 {
31//! let event: serde_json::Value = serde_json::from_slice(&buf[..n])?;
32//! if event["type"] == "UserLeave" {
33//! break;
34//! }
35//! }
36//! }
37//!
38//! activity.finish()?;
39//! Ok(())
40//! }
41//! ```
42//!
43//! ## Architecture
44//!
45//! - **Connection**: Low-level socket communication with Termux GUI service
46//! - **Activity**: Represents a GUI window (dialog or full-screen)
47//! - **View**: Base view type with common operations
48//! - **Components**: UI widgets (TextView, Button, EditText, etc.)
49//!
50//! ## Features
51//!
52//! - Object-oriented API design
53//! - Type-safe error handling with `thiserror`
54//! - Zero-cost abstractions using lifetimes
55//! - All Termux GUI components supported
56
57pub mod connection;
58pub mod activity;
59pub mod view;
60pub mod components;
61pub mod error;
62
63// Re-exports for convenience
64pub use connection::Connection;
65pub use activity::Activity;
66pub use view::{View, MATCH_PARENT, WRAP_CONTENT};
67pub use error::{GuiError, Result};
68
69// Re-export all components
70pub use components::{
71 TextView, Button, EditText, Checkbox, Switch,
72 RadioButton, RadioGroup, Spinner,
73 LinearLayout, NestedScrollView, FrameLayout, GridLayout,
74 HorizontalScrollView, SwipeRefreshLayout, TabLayout,
75 ImageView, ProgressBar, ToggleButton, Space, WebView,
76};