Compo Window - Cross-Platform Window Component for Compo
Compo Window is a cross-platform window component library built on top of the Compo declarative and reactive component framework. It provides native window creation and management capabilities for Windows, macOS, iOS, and Android platforms, enabling you to build native GUI applications with Compo's reactive programming model.
Features
- Cross-Platform Support: Native window implementation for Windows, macOS, iOS, and Android
- Reactive Window Management: Declarative window properties with automatic updates
- Native Performance: Uses platform-specific APIs for optimal performance
- Compo Integration: Seamlessly integrates with Compo's component system
- Zero Dependencies: Minimal external dependencies, leveraging platform-native APIs
- Type Safety: Full Rust type safety with compile-time guarantees
Platform Support
| Platform | Status | Implementation |
|---|---|---|
| Windows | ✅ | Win32 API |
| macOS | ✅ | Cocoa/AppKit |
| iOS | ✅ | UIKit |
| Android | ✅ | JNI + Android SDK |
Quick Start
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use *;
async
Running the Example
# Desktop (Windows/macOS/Linux)
# Android
# iOS
# Open CompoWindow.xcodeproj in Xcode and run
API Reference
window Component
The main window component with the following parameters:
pub async
Parameters
title: The window title text (default: "Window")width: Window width in pixels (default: 800 on desktop, 360 on Android, 375 on iOS)height: Window height in pixels (default: 600 on desktop, 640 on Android, 667 on iOS)left: Window X position (default: system default)top: Window Y position (default: system default)visible: Whether the window is visible (default: true)enabled: Whether the window accepts user input (default: true)
Reactive Updates
All window properties are reactive - when you change a variable that's passed to the window component, the window will automatically update:
async
Examples
Basic Window
use *;
async
Dynamic Window Updates
use *;
async
Multiple Windows
use *;
async
Platform-Specific Details
Default Window Sizes
The window component uses platform-appropriate default sizes:
- Desktop (Windows/macOS): 800×600 pixels - suitable for desktop applications
- Android: 360×640 pixels - optimized for typical Android phone screens in portrait mode
- iOS: 375×667 pixels - optimized for iPhone screens in portrait mode (iPhone 6/7/8 size)
These defaults ensure that windows appear with appropriate sizes for each platform's typical use cases and screen orientations.
Windows
- Uses Win32 API for native window creation
- Supports all standard Windows window features
- Integrates with Windows message loop
macOS
- Uses Cocoa/AppKit for native window management
- Supports macOS-specific window behaviors
- Integrates with NSApplication lifecycle
iOS
- Uses UIKit for iOS-native window creation
- Supports iOS app lifecycle integration
- Optimized for touch interfaces
Android
- Uses JNI bridge to Android SDK
- Integrates with Android Activity lifecycle
- Supports Android-specific window features
Building for Different Platforms
Desktop
Android
Requires Android NDK and cargo-apk2:
iOS
Requires Xcode and iOS toolchain:
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Development Setup
- Clone the repository
- Install Rust and platform-specific toolchains
- Run tests:
cargo test - Run examples:
cargo run --example desktop
License
Apache-2.0
Related Projects
- Compo - The core declarative and reactive component framework
- Compo Platform Loop - Cross-platform event loop implementation
- cargo-apk2 - Tool for building Android applications with Cargo