Theme

Trait Theme 

Source
pub trait Theme<DS: DrawSharedImpl>: ThemeControl {
    type Config: ThemeConfig;
    type Window: Window;
    type Draw<'a>: ThemeDraw
       where DS: 'a,
             Self: 'a;

    // Required methods
    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);
    fn draw<'a>(
        &'a self,
        draw: DrawIface<'a, DS>,
        ev: &'a mut EventState,
        window: &'a mut Self::Window,
    ) -> Self::Draw<'a>;
    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.

Required Associated Types§

Source

type Config: ThemeConfig

The associated config type

Source

type Window: Window

The associated Window implementation.

Source

type Draw<'a>: ThemeDraw where DS: 'a, Self: 'a

The associated [ThemeDraw] implementation.

Required Methods§

Source

fn config(&self) -> Cow<'_, Self::Config>

Get current configuration

Source

fn apply_config(&mut self, config: &Self::Config) -> TkAction

Apply/set the passed config

Source

fn init(&mut self, shared: &mut SharedState<DS>)

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.

Source

fn new_window(&self, dpi_factor: f32) -> Self::Window

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.

Source

fn update_window(&self, window: &mut Self::Window, dpi_factor: f32)

Update a window created by Theme::new_window

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

Source

fn draw<'a>( &'a self, draw: DrawIface<'a, DS>, ev: &'a mut EventState, window: &'a mut Self::Window, ) -> Self::Draw<'a>

Prepare to draw and construct a [ThemeDraw] 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 [ThemeDraw] object is restricted to the specified rect.

The window is guaranteed to be one created by a call to Theme::new_window on self.

Source

fn clear_color(&self) -> Rgba

Background colour

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Theme<DS>, DS: DrawSharedImpl> Theme<DS> for Box<T>

Source§

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

Source§

type Config = <T as Theme<DS>>::Config

Source§

type Draw<'a> = <T as Theme<DS>>::Draw<'a> where T: 'a

Source§

fn config(&self) -> Cow<'_, Self::Config>

Source§

fn apply_config(&mut self, config: &Self::Config) -> TkAction

Source§

fn init(&mut self, shared: &mut SharedState<DS>)

Source§

fn new_window(&self, dpi_factor: f32) -> Self::Window

Source§

fn update_window(&self, window: &mut Self::Window, dpi_factor: f32)

Source§

fn draw<'a>( &'a self, draw: DrawIface<'a, DS>, ev: &'a mut EventState, window: &'a mut Self::Window, ) -> Self::Draw<'a>

Source§

fn clear_color(&self) -> Rgba

Implementors§

Source§

impl<DS: DrawSharedImpl> Theme<DS> for FlatTheme
where DS::Draw: DrawRoundedImpl,

Source§

type Config = Config

Source§

type Window = Window<<DS as DrawSharedImpl>::Draw>

Source§

type Draw<'a> = DrawHandle<'a, DS>

Source§

impl<DS: DrawSharedImpl> Theme<DS> for MultiTheme<DS>

Source§

type Config = Config

Source§

type Window = Box<dyn Window>

Source§

type Draw<'a> = Box<dyn ThemeDraw + 'a>

Source§

impl<DS: DrawSharedImpl> Theme<DS> for ShadedTheme
where DS::Draw: DrawRoundedImpl + DrawShadedImpl,

Source§

type Config = Config

Source§

type Window = Window<<DS as DrawSharedImpl>::Draw>

Source§

type Draw<'a> = DrawHandle<'a, DS>

Source§

impl<DS: DrawSharedImpl> Theme<DS> for SimpleTheme
where DS::Draw: DrawRoundedImpl,

Source§

type Config = Config

Source§

type Window = Window<<DS as DrawSharedImpl>::Draw>

Source§

type Draw<'a> = DrawHandle<'a, DS>