Trait kas_theme::Theme[][src]

pub trait Theme<DS: DrawSharedImpl>: ThemeApi {
    type Config: ThemeConfig;
    type Window: Window;
    type DrawHandle: DrawHandle;
    fn config(&self) -> Cow<'_, Self::Config>;
fn apply_config(&mut self, config: &Self::Config) -> TkAction;
fn init(&mut self, shared: &mut SharedState<DS>);
fn new_window(&self, dpi_factor: f32) -> Self::Window;
fn update_window(&self, window: &mut Self::Window, dpi_factor: f32);
unsafe fn draw_handle(
        &self,
        draw: DrawIface<'_, DS>,
        window: &mut Self::Window
    ) -> Self::DrawHandle;
fn clear_color(&self) -> Rgba; }
Expand description

A theme provides widget sizing and drawing implementations.

The theme is generic over some DrawIface.

Objects of this type are copied within each window’s data structure. For large resources (e.g. fonts and icons) consider using external storage.

Associated Types

The associated config type

The associated Window implementation.

The associated DrawHandle implementation.

Required methods

Get current config

Apply/set the passed config

Theme initialisation

The toolkit must call this method before Theme::new_window to allow initialisation specific to the DrawIface.

At a minimum, a theme must load a font to [kas::text::fonts]. The first font loaded (by any theme) becomes the default font.

Construct per-window storage

On “standard” monitors, the dpi_factor is 1. High-DPI screens may have a factor of 2 or higher. The factor may not be an integer; e.g. 9/8 = 1.125 works well with many 1440p screens. It is recommended to round dimensions to the nearest integer, and cache the result:

self.margin = i32::conv_nearest(MARGIN * factor);

A reference to the draw backend is provided allowing configuration.

Update a window created by Theme::new_window

This is called when the DPI factor changes or theme dimensions change.

Prepare to draw and construct a DrawHandle object

This is called once per window per frame and should do any necessary preparation such as loading fonts and textures which are loaded on demand.

Drawing via this DrawHandle is restricted to the specified rect.

The window is guaranteed to be one created by a call to Theme::new_window on self, and the draw reference is guaranteed to be identical to the one passed to Theme::new_window.

Safety

(This section only applies when not using the gat feature.)

All references passed into the method must outlive the returned object.

Background colour

Implementations on Foreign Types

Implementors