Skip to main content

Crate eternal_ui_skia

Crate eternal_ui_skia 

Source
Expand description

Skia rendering for eternal-ui.

Two types implement the toolkit’s backend traits: SkiaFonts measures text (the Fonts trait) and SkiaRenderer draws one frame onto a Skia Canvas (the Renderer trait). Where the canvas comes from is up to the application: a CPU raster surface, or a GPU surface through one of skia-safe’s gl, metal or vulkan features.

use eternal_ui::{ui, Element, Size, Ui};
use eternal_ui_skia::{SkiaFonts, SkiaRenderer};

let mut ui: Ui<()> = Ui::new();
ui.set_root(ui! { <panel><button>"Hello"</button></panel> });

let fonts = SkiaFonts::new();
let mut surface = skia_safe::surfaces::raster_n32_premul((200, 100)).unwrap();
ui.layout(Size::new(200.0, 100.0), &fonts);
let mut renderer = SkiaRenderer::new(surface.canvas(), &fonts);
ui.paint(&mut renderer);

Shapes are drawn without anti-aliasing and text without subpixel positioning, so 1px borders and pixel fonts stay crisp. Call SkiaFonts::set_smooth for the ordinary anti-aliased look.

Fonts come from the system by default. Load your own, such as a pixel font shipped with the application, with SkiaFonts::load_font_file or SkiaFonts::load_font, and name them in the stylesheet’s font-family.

Structs§

SkiaFonts
Finds fonts and measures text with Skia.
SkiaRenderer
Draws one frame of a Ui onto a Skia canvas.

Enums§

FontError
A font could not be loaded.