[][src]Trait kas_theme::Theme

pub trait Theme<D: DrawShared>: ThemeApi {
    type Window: Window + 'static;
    type DrawHandle: DrawHandle;
    pub fn init(&mut self, draw: &mut D);
pub fn new_window(
        &self,
        draw: &mut D::Draw,
        dpi_factor: f32
    ) -> Self::Window;
pub fn update_window(&self, window: &mut Self::Window, dpi_factor: f32);
pub unsafe fn draw_handle(
        &self,
        draw: &mut D::Draw,
        window: &mut Self::Window,
        rect: Rect
    ) -> Self::DrawHandle;
pub fn clear_color(&self) -> Colour; }

A theme provides widget sizing and drawing implementations.

The theme is generic over some Draw type.

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

type Window: Window + 'static[src]

The associated Window implementation.

type DrawHandle: DrawHandle[src]

The associated DrawHandle implementation.

Loading content...

Required methods

pub fn init(&mut self, draw: &mut D)[src]

Theme initialisation

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

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

pub fn new_window(&self, draw: &mut D::Draw, dpi_factor: f32) -> Self::Window[src]

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 = (MARGIN * factor).round() as u32;

A reference to the draw backend is provided allowing configuration.

pub fn update_window(&self, window: &mut Self::Window, dpi_factor: f32)[src]

Update a window created by Theme::new_window

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

pub unsafe fn draw_handle(
    &self,
    draw: &mut D::Draw,
    window: &mut Self::Window,
    rect: Rect
) -> Self::DrawHandle
[src]

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.

This method is marked unsafe since a lifetime restriction is required on the return value which can only be expressed with the unstable feature Generic Associated Types (rust#44265).

pub fn clear_color(&self) -> Colour[src]

Background colour

Loading content...

Implementations on Foreign Types

impl<T: Theme<D>, D: DrawShared> Theme<D> for Box<T>[src]

type Window = <T as Theme<D>>::Window

type DrawHandle = <T as Theme<D>>::DrawHandle

Loading content...

Implementors

impl<D: DrawShared + 'static> Theme<D> for FlatTheme where
    D::Draw: DrawRounded + DrawText
[src]

type Window = DimensionsWindow

type DrawHandle = DrawHandle<'static, D::Draw>

impl<D: DrawShared + 'static> Theme<D> for MultiTheme<D>[src]

type Window = StackDst<dyn WindowDst>

type DrawHandle = StackDst<dyn DrawHandle>

impl<D: DrawShared + 'static> Theme<D> for ShadedTheme where
    D::Draw: DrawRounded + DrawShaded + DrawText
[src]

type Window = DimensionsWindow

type DrawHandle = DrawHandle<'static, D::Draw>

Loading content...