-
Notifications
You must be signed in to change notification settings - Fork 0
Image
The image feature adds raster image support to AuroraUI. It provides ImageData for decoding PNG/JPEG files, Canvas::draw_image for blitting RGBA pixels, and an Image widget for use in the widget tree.
Enable it in your Cargo.toml:
aurora_ui = { path = "...", features = ["software", "image"] }Decoded raster image data in RGBA format. Decode once and reuse — decoding does not happen during paint.
pub struct ImageData {
pub pixels: Vec<u8>, // RGBA, 4 bytes per pixel
pub width: u32,
pub height: u32,
}Decodes a PNG or JPEG from raw bytes. Typically used with include_bytes!:
use aurora_render::image_data::ImageData;
let img = ImageData::from_bytes(include_bytes!("logo.png")).unwrap();Creates an ImageData from pre-decoded RGBA pixels:
use aurora_render::image_data::ImageData;
let pixels = vec![255, 0, 0, 255]; // one red pixel
let img = ImageData::from_raw(pixels, 1, 1);Blits RGBA image data into the canvas at a destination rectangle. Handles scaling (nearest-neighbor), alpha blending, and respects the active clip rect.
canvas.draw_image(&img.pixels, img.width, img.height, dest_rect);A widget that displays a raster image. The image data is shared via Arc<ImageData> so the widget is cheap to clone and pass around.
use std::sync::Arc;
use aurora_render::image_data::ImageData;
use aurora_widgets::image_widget::{Image, ImageFit};
let data = Arc::new(ImageData::from_bytes(include_bytes!("photo.jpg")).unwrap());
Image::new(data)
.width(200.0)
.height(150.0)
.fit(ImageFit::Cover)| Method | Description |
|---|---|
width(f32) |
Fixed width in pixels |
height(f32) |
Fixed height in pixels |
fit(ImageFit) |
How the image scales to fill its bounds |
Controls how the source image maps to the widget's layout rectangle.
pub enum ImageFit {
Cover, // scale to fill, crop excess (default)
Contain, // scale to fit, letterbox if needed
Fill, // stretch to fill, ignores aspect ratio
None, // display at native pixel size
}| Fit | Aspect ratio preserved? | Fills bounds? | May crop? |
|---|---|---|---|
Cover |
Yes | Yes | Yes |
Contain |
Yes | No (letterboxed) | No |
Fill |
No | Yes | No |
None |
Yes | No | No |
This example generates images programmatically and displays them with different fit modes:
use std::sync::Arc;
use aurora_ui::aurora_render::image_data::ImageData;
use aurora_ui::aurora_widgets::image_widget::{Image, ImageFit};
use aurora_ui::prelude::*;
fn main() {
// Decode from embedded bytes
let img = Arc::new(ImageData::from_bytes(include_bytes!("photo.jpg")).unwrap());
App::new()
.title("Image Example")
.size((600, 400))
.run(move |window, _frame| {
window.root(
row!()
.spacing(10.0)
.padding(Edges::all(10.0))
.child(Image::new(img.clone()).fit(ImageFit::Contain))
.child(Image::new(img.clone()).fit(ImageFit::Cover))
.child(Image::new(img.clone()).fit(ImageFit::Fill))
);
})
.expect("Failed to run app");
}The svg feature adds SVG rendering via usvg (parser) + tiny-skia (rasterizer).
aurora_ui = { path = "...", features = ["software", "svg"] }A parsed SVG document. Parse once, rasterize at any size.
use aurora_render::svg_data::SvgData;
let svg = SvgData::from_bytes(include_bytes!("icon.svg")).unwrap();
let rgba = svg.render(64, 64); // RGBA pixels at 64x64| Method | Description |
|---|---|
SvgData::from_bytes(bytes) |
Parse an SVG from raw bytes |
size() -> (f32, f32) |
Intrinsic viewBox dimensions |
render(width, height) -> Vec<u8> |
Rasterize to RGBA at the given size |
Displays an SVG, rasterized at layout size. Cached — only re-rasterizes when the size changes.
use std::sync::Arc;
use aurora_render::svg_data::SvgData;
use aurora_widgets::svg_widget::Svg;
let data = Arc::new(SvgData::from_bytes(include_bytes!("icon.svg")).unwrap());
Svg::new(data)
.width(48.0)
.height(48.0)| Method | Description |
|---|---|
width(f32) |
Fixed width in pixels |
height(f32) |
Fixed height in pixels |
| Feature | Status |
|---|---|
| Solid color fills/strokes | Supported |
| Linear gradients | Supported |
| Radial gradients | Supported |
| Path commands (move, line, quad, cubic, close) | Supported |
| Transforms (translate, scale, rotate, skew) | Supported |
| Stroke properties (width, cap, join, miter) | Supported |
| Fill rules (NonZero, EvenOdd) | Supported |
| Anti-aliasing | Supported |
| Patterns | Not supported |
| Embedded images | Not supported |
| Text nodes | Not supported |
| Filter effects (blur, drop-shadow) | Not supported |
AuroraUI is a cross-platform desktop UI framework that treats performance as a first-class constraint — not an afterthought.
- App - Application builder, windowing, and event loop
- MultiWindow - Window spawning, modals, messaging
-
Native Menu - OS menu bars (
menufeature) -
System Tray - System tray icons (
trayfeature) - Threading - Background tasks, thread-safe state
- Color - Color utilities and color schemes
- Undo / Redo - UndoStack and text input undo
- Rect - Rectangle geometry
- Point - Point geometry
- Size - Size geometry
- Edges - Edge insets (padding, margins, borders)
- Corners - Corner radii for rounded rectangles
- GpuContext - GPU surface abstraction and backends
- Canvas - 2D drawing API
- FontManager - Font loading and management
- TextLayout - Text shaping, measurement, and rendering
- Text - Text widget
- Layout - Column, Row, Stack, Positioned
- ScrollView - Scrollable viewport with scrollbar
- VirtualList - Virtualized list for large datasets
- Button - Styled button with any child content
- BoxWidget - Colored rectangle container
- TextInput - Single-line text input
- TouchArea - Invisible hit-testing region
- Drag & Drop - Draggable sources and drop zones
- ContentSwitch - Conditional child display
- Image - Raster image display (PNG, JPEG)
-
Composite - Stateful composites &
#[composite_widget] - TreeView - Hierarchical data with expand/collapse
- Display - Badge, Card, Alert, Progress, Spinner, Kbd, and more
- Stepper - Step-by-step progress indicator
- Forms - Checkbox, Switch, Slider, RadioGroup, Tabs, Accordion, and more
- SegmentedControl - iOS-style segmented toggle bar
- NumberInput - Numeric input with +/- buttons
- RichTextEditor - Rich text editing with bold/italic/underline
- Form Validation - Validators, error states, form-level validation
- Overlays - Tooltip, Popover, Dialog, DropdownMenu, Select, Toast
- Sheet - Slide-in panel from screen edge
- TagInput - Multi-value input with removable tags
- SplitPane - Resizable split view with drag handle
- ColorPicker - Color selection with hex/RGB
- TimePicker - Time selection with hour/minute spinners
- DateRangePicker - Dual-calendar date range selection
- DateTimePicker - Combined date and time selection
- Data & Advanced - Table, Calendar, Combobox, Command, and more
- Theme - Color profiles, slots, and runtime switching
- Animation - Tweens, easing, keyframes, timelines, and presets
- Syntax - Syntax highlighting for 16+ languages
- Accessibility - Screen reader support via AccessKit
- i18n - Locale detection, message formatting, RTL layout