Skip to main content

Windowing

lui uses winit for windowing. The lui-driver-winit crate provides a complete window driver.

WinitDriver

use lui_driver_winit::WinitDriver;

let event_loop = EventLoop::new()?;
let window = Arc::new(event_loop.create_window(
Window::default_attributes()
.with_title("My App")
.with_inner_size(PhysicalSize::new(800, 600))
)?);

let mut driver = WinitDriver::bind(window, tree);

Event Handling

WinitDriver::handle_event() handles all window events automatically:

// In ApplicationHandler::window_event():
match event {
WindowEvent::RedrawRequested => {
driver.handle_event(&event);
}
WindowEvent::CursorMoved { .. } |
WindowEvent::MouseInput { .. } |
WindowEvent::MouseWheel { .. } |
WindowEvent::KeyboardInput { .. } |
WindowEvent::Resized { .. } |
WindowEvent::ScaleFactorChanged { .. } => {
driver.handle_event(&event);
}
_ => {}
}

Returns Option<PipelineTimings> on render frames for profiling.

Built-in Features

The winit driver includes:

FeatureKey/Trigger
Viewport scrollingMouse wheel
Scrollbar paint + dragMouse on scrollbar
Text selectionDrag-select
Clipboard copyCtrl+C
Clipboard pasteCtrl+V
Clipboard cutCtrl+X
Select allCtrl+A
ScreenshotF12 (configurable)
Devtools toggleF11 (when Devtools::attach() used)
Profiler dumpF9 (when profiler enabled)
ExitEscape (configurable)
System font discoveryAutomatic at startup

Multiple Windows

let devtools_win = Arc::new(event_loop.create_window(
Window::default_attributes().with_title("Devtools")
)?);
let mut dd = WinitDriver::bind(devtools_win, Tree::default());

// In event loop, dispatch to both:
driver.handle_event(&event);
dd.dispatch_to(&event, devtools.tree_mut());
dd.render(devtools.tree_mut());

DPI Handling

DPI scale factor is tracked from the winit window. The engine stores a dpi_scale_override on the tree for testing:

tree.set_dpi_scale_override(Some(1.5)); // Force 1.5x DPI
let effective = tree.effective_dpi_scale(host_scale); // Resolves override vs host

Physical pixel coordinates in layout and paint account for the DPI scale factor.

Cursor Management

CSS cursor property values are mapped to OS cursor icons:

CSS CursorOS Cursor
pointerHand
textI-beam
moveMove/SizeAll
defaultArrow
not-allowedNotAllowed
crosshairCrosshair
col-resizeSizeWe
row-resizeSizeNs
etc.etc.