Skip to content
Drew Chase (Home) edited this page Mar 17, 2026 · 2 revisions

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"] }

ImageData

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,
}

Constructors

ImageData::from_bytes(bytes)

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();

ImageData::from_raw(pixels, width, height)

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);

Canvas::draw_image

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);

Image Widget

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)

Builder Methods

Method Description
width(f32) Fixed width in pixels
height(f32) Fixed height in pixels
fit(ImageFit) How the image scales to fill its bounds

ImageFit

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

Example

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");
}

SVG Support

The svg feature adds SVG rendering via usvg (parser) + tiny-skia (rasterizer).

aurora_ui = { path = "...", features = ["software", "svg"] }

SvgData

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

Svg Widget

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

Supported SVG Features

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.

Platform

  • App - Application builder, windowing, and event loop
  • MultiWindow - Window spawning, modals, messaging
  • Native Menu - OS menu bars (menu feature)
  • System Tray - System tray icons (tray feature)
  • Threading - Background tasks, thread-safe state

Core

  • Color - Color utilities and color schemes
  • Undo / Redo - UndoStack and text input undo

Geometry

  • Rect - Rectangle geometry
  • Point - Point geometry
  • Size - Size geometry
  • Edges - Edge insets (padding, margins, borders)
  • Corners - Corner radii for rounded rectangles

GPU

  • GpuContext - GPU surface abstraction and backends

Render

Text

Widgets

  • 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

Components

  • 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

  • Theme - Color profiles, slots, and runtime switching

Animation

  • Animation - Tweens, easing, keyframes, timelines, and presets

Code

  • Syntax - Syntax highlighting for 16+ languages

Accessibility

Internationalization

  • i18n - Locale detection, message formatting, RTL layout

Integrations

  • Iconify - Compile-time icons from iconify.design
  • Fonts - Compile-time Google Fonts embedding

Clone this wiki locally