e_window_api
A high-level Rust API for controlling e_window instances programmatically, including comprehensive message box functionality.
Overview
e_window_api provides a convenient Rust interface for launching and controlling e_window processes. Instead of manually spawning processes and writing to stdin, this crate offers a structured API for window management, content updates, real-time control, and modern message box functionality.
Features
- Message Box API: Full-featured message box system with all standard button types
- Notification System: Auto-closing notifications with visual countdown timers
- Easy Window Management: Launch e_window instances with simple configuration
- Real-time Control: Send control commands to running windows
- Animated Positioning: Move and resize windows with easing animations
- Structured Content API: Build cards using structured fields instead of raw content strings
- Document Protocol: Full support for e_window's document format protocol
- Async/Await Support: Full async support with tokio
- Type Safety: Strongly typed API with comprehensive error handling
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["macros", "rt-multi-thread"] }
Quick Start
Message Box Usage
use *;
Async Message Box Usage
use *;
async
Basic Usage
use ;
async
Simple Show Method
For quick demos, use the convenience show() method:
use Card;
Message Box API
The e_window_api includes a comprehensive message box system that provides both blocking and async variants, supporting all standard message box types with emoji icons and automatic sizing.
Quick Message Box Examples
use *;
Message Box Types
The API supports all standard Windows message box types:
use *;
// Single button types
message_box?;
// Two button types
let result = message_box?;
let result = message_box?;
// Three button types
let result = message_box?;
// Default button variants
let result = message_box?;
let result = message_box?;
// Special input types
let text = input_text?;
let file = select_file?;
Message Box Results
Message boxes return typed results that match the button configuration:
use MessageBoxResult;
let result = message_box?;
match result
// Text input returns the entered text
if let Text = input_text?
// File selection returns the selected file path
if let File = select_file?
Auto-closing Notifications
Notifications automatically close after a specified duration and show a visual countdown:
use *;
// Built-in notification types with standard durations
info; // 3 seconds
warn; // 5 seconds
error; // 7 seconds
// Custom notification with specific duration
notify?;
// Persistent notification (no auto-close)
notify?;
Async Message Box API
Full async support for non-blocking operations:
use *;
async
Message Box Icons
Visual icons are automatically added based on the message type:
- Information: ℹ️ (info, notify with Information icon)
- Warning: ⚠️ (warn, warning messages)
- Error: ❌ (error, critical messages)
- Question: ❓ (yes/no, ok/cancel questions)
// Icons are automatically selected based on function used
info; // Uses ℹ️ Information icon
warn; // Uses ⚠️ Warning icon
error; // Uses ❌ Error icon
ask_yes_no; // Uses ❓ Question icon
// Or specify explicitly
message_box?;
Advanced Features
Timeouts and Auto-close
// Message box with 10-second timeout
let result = message_box_ex?;
if result == Timeout
Input Validation
// Text input with validation
loop
Convenience Functions
// Quick yes/no question
if ask_yes_no?
// Quick confirmation
if confirm?
// Quick info with custom duration
notify_timed?;
Structured Card API
The e_window application uses a specific document format protocol for displaying content. This crate provides a structured API that automatically generates the correct format.
Document Structure
A valid e_window document follows this structure:
--title "Window Title" --width 800 --height 600 --x 100 --y 100
field1 | value1 | type1
field2 | value2 | type2
Card Title
Header Text
Caption Text
Body line 1
Body line 2
...
Format Breakdown
-
CLI Arguments Line (optional): Window configuration parameters
--title "text"- Window title--width N- Window width in pixels--height N- Window height in pixels--x N- Window X position--y N- Window Y position--follow-hwnd 0xHEX- Follow parent window
-
Fields Section (optional): Key-value pairs in
key | value | typeformat- Displayed as a structured table in the UI
- Common types:
string,number,boolean,date
-
Blank Line Separator (crucial!): Required between configuration/fields and content
-
Content Section: Structured content after the blank line
- Line 1: Card title (can be empty)
- Line 2: Header text (can be empty)
- Line 3: Caption text (can be empty)
- Lines 4+: Body content (multiple lines supported)
Raw Document Example
--title "Project Status" --width 600 --height 400
project | e_window | string
version | 1.0.1 | string
status | active | string
Project Dashboard
Development Progress Report
Last Updated: 2025-10-11
We have made significant progress on the e_window project.
Key accomplishments:
- Implemented structured Card API
- Fixed positioning issues
- Added document protocol support
- Created comprehensive examples
Next steps:
- Add more animation options
- Improve error handling
- Write documentation
Structured Card API
Instead of manually constructing document strings, use the structured Card API:
Card Structure
use Card;
let card = new
// Window configuration
.window_title // Sets window title
.size // Sets window size
.position // Sets window position
// Fields (key-value pairs)
.field // String field
.typed_field // Typed field
// Structured content
.card_title // Line 1 after blank separator
.header // Line 2
.caption // Line 3
.body_line // Body content (line 4+)
.body_line
.body; // Or set all body at once
API Methods
Window Configuration
.window_title // Window title bar
.size // Window dimensions
.position // Window position
Fields (Key-Value Pairs)
.field // String field
.typed_field // Typed field
Structured Content
.card_title // Card title (line 1)
.header // Header (line 2)
.caption // Caption (line 3)
.body_line // Add single body line
.body_lines // Set body from vector
.body // Set body from string (splits on \n)
Convenience Methods
.show_blocking // Show card and wait (blocking)
.show.await // Show card and wait (async)
Migration from Legacy API
The old content-based API is deprecated but still supported:
// OLD (deprecated)
let card = new
.title // ❌ Deprecated - use window_title()
.content // ❌ Deprecated - use card_title(), header(), etc.
.add_content; // ❌ Deprecated - use body_line()
// NEW (recommended)
let card = new
.window_title // ✅ Clear window title
.card_title // ✅ Structured content title
.body_line; // ✅ Structured body content
Complete Example
use Card;
// Close the window
window.close().await?;
Ok(())
}
## API Reference
### WindowConfig
Configure window properties before launching:
```rust
let config = WindowConfig::new()
.title("My App") // Window title
.size(800, 600) // Window size
.position(100, 100) // Window position
.decode_debug(true) // Enable debug output
.add_arg("--custom-flag"); // Add custom CLI argument
Card (Structured API)
Create structured content for display using the new API:
let card = new
// Window configuration
.window_title // Window title bar
.size // Window size
.position // Window position
// Fields section (displayed as table)
.field // String field
.typed_field // Typed field
// Structured content (after blank line separator)
.card_title // Content title (line 1)
.header // Header text (line 2)
.caption // Caption text (line 3)
.body_line // Body content (lines 4+)
.body_line
.body; // Or set body all at once
Card (Legacy API - Deprecated)
The old content-based API is still supported but deprecated:
// ⚠️ DEPRECATED - Use structured API above instead
let card = new
.title // ❌ Use window_title() instead
.size
.position
.field
.typed_field
.content // ❌ Use card_title(), header(), etc.
.add_content // ❌ Use body_line() instead
.add_content;
EWindow
Control a running window instance:
// Launch window
let mut window = launch.await?;
// Show content
window.show_card.await?;
// Control window
window.set_title.await?;
window.set_rect.await?;
window.set_rect_animated.await?;
// Wait and close
window.delay.await?;
window.close.await?;
Animation Easing
Supported easing types for animated operations:
AnimationEasing::LinearAnimationEasing::EaseInAnimationEasing::EaseOutAnimationEasing::EaseInOutAnimationEasing::BounceAnimationEasing::ElasticAnimationEasing::BackAnimationEasing::Custom("custom-easing")
Examples
The crate includes several comprehensive examples demonstrating different features:
Message Box Examples
Message Box Demo
Comprehensive demonstration of the message box API:
- All message box types (Ok, OkCancel, YesNo, YesNoCancel, etc.)
- Auto-closing notifications with countdown timers
- Input dialogs and file selection
- Both blocking and async variants
- Error handling and timeout scenarios
Simple Message Box Demo
Quick examples of common message box patterns:
- Info, warning, and error notifications
- Yes/No questions and confirmations
- Text input and file selection dialogs
Enhanced Message Box Demo
Advanced message box features:
- Custom timeout values
- Complex button combinations
- Input validation patterns
- Async runtime integration
Structured API Examples
Simple Structured Demo
Demonstrates the new structured Card API with:
- Window configuration
- Fields section
- Structured content (title, header, caption, body)
- Multiple card creation patterns
Structured Card Demo
Shows advanced structured content features:
- Complex field configurations
- Multi-line body content
- Window positioning with structured content
Positioning Examples
Test Positioning
Tests explicit window positioning functionality:
- Fixed position windows
- Auto-centering behavior verification
- Content display with positioning
Control API Examples
Simple Demo
A basic usage demonstration:
- Basic window creation with configuration
- Simple card display
- Automatic cleanup
Realtime Control Demo
Demonstrates dynamic window control with animated positioning:
- Animated window movement to different screen positions
- Dynamic card content updates
- Real-time title and size changes
- Smooth transitions with easing
Panic Card Simulation
Shows how to display error/panic information:
- Structured error display
- Formatted panic information
- User-controlled window lifetime
Grid Demo
or demo_ewindow_grid if you installed it.
Demonstrates precise positioning in a grid layout:
- 3x3 grid positioning
- Animated movement between grid cells
- Visual grid representation
- Systematic position demonstration
Error Handling
The crate provides comprehensive error handling through the EWindowError type:
use ;
match launch_default.await
Prerequisites
e_windowexecutable must be available in PATH or built in the workspace- Tokio runtime for async operations
- Windows OS for advanced window manipulation features
API Evolution and Comparison
Legacy vs Structured API
The crate has evolved from a content-based API to a structured API that better reflects the e_window document protocol:
Legacy API (Deprecated)
// Old approach - manual content construction
let card = new
.title // ❌ Ambiguous - window or content title?
.content; // ❌ Hard to manage
New Structured API (Recommended)
// New approach - structured fields
let card = new
.window_title // ✅ Clear window title
.card_title // ✅ Clear content title
.header // ✅ Structured header
.caption // ✅ Structured caption
.body_line // ✅ Structured body
.body_line;
Direct e_window vs e_window_api
Direct Usage (Low-level)
// Manual process management and document construction
let mut child = new
.args
.stdin
.spawn?;
let stdin = child.stdin.as_mut.unwrap;
// Manual document format construction
stdin.write_all?;
stdin.write_all?;
stdin.write_all?;
stdin.write_all?; // Blank line separator
stdin.write_all?;
stdin.write_all?;
stdin.write_all?;
stdin.write_all?;
stdin.write_all?;
e_window_api Usage (High-level)
// Structured API with automatic document generation
let card = new
.window_title
.size
.field
.card_title
.header
.caption
.body;
card.show_blocking?; // Handles all the complexity automatically
Generated Document Format
The structured API automatically generates the correct e_window document format:
let card = new
.window_title
.field
.card_title
.header
.body;
println!;
Output:
--title "Demo"
version | 1.0 | string
Hello
World
Welcome!
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.