Expand description
§Termux GUI Rust Bindings
This library provides Rust bindings for Termux:GUI, allowing you to create native Android GUI applications using Rust in the Termux environment.
§Quick Start
use termux_gui::{Activity, Result};
fn main() -> Result<()> {
// Create an activity (dialog mode)
let mut activity = Activity::new(true)?;
// Create a layout
let layout = activity.create_linear_layout(None)?;
// Add a title
let mut title = activity.create_text_view("Hello Termux!", Some(layout.id()))?;
title.set_text_size(&mut activity, 24)?;
// Add a button
let button = activity.create_button("Click Me", Some(layout.id()))?;
// Event loop
use std::io::Read;
let mut buf = [0u8; 1024];
loop {
let n = activity.event_stream().read(&mut buf)?;
if n > 0 {
let event: serde_json::Value = serde_json::from_slice(&buf[..n])?;
if event["type"] == "UserLeave" {
break;
}
}
}
activity.finish()?;
Ok(())
}§Architecture
- Connection: Low-level socket communication with Termux GUI service
- Activity: Represents a GUI window (dialog or full-screen)
- View: Base view type with common operations
- Components: UI widgets (TextView, Button, EditText, etc.)
§Features
- Object-oriented API design
- Type-safe error handling with
thiserror - Zero-cost abstractions using lifetimes
- All Termux GUI components supported
Re-exports§
pub use connection::Connection;pub use activity::Activity;pub use view::View;pub use view::MATCH_PARENT;pub use view::WRAP_CONTENT;pub use error::GuiError;pub use error::Result;pub use components::TextView;pub use components::Button;pub use components::EditText;pub use components::Checkbox;pub use components::Switch;pub use components::RadioButton;pub use components::RadioGroup;pub use components::Spinner;pub use components::LinearLayout;pub use components::NestedScrollView;pub use components::FrameLayout;pub use components::GridLayout;pub use components::HorizontalScrollView;pub use components::SwipeRefreshLayout;pub use components::TabLayout;pub use components::ImageView;pub use components::ProgressBar;pub use components::ToggleButton;pub use components::Space;pub use components::WebView;
Modules§
- activity
- Activity management
- components
- UI Components
- connection
- Low-level socket connection management
- error
- Error types for Termux GUI
- view
- Base View type and common view operations