Trait kas_theme::Theme [−][src]
pub trait Theme<D: DrawShared>: ThemeApi { type Config: ThemeConfig; type Window: Window<D>; type DrawHandle: DrawHandle; fn config(&self) -> Cow<'_, Self::Config>; fn apply_config(&mut self, config: &Self::Config) -> TkAction; fn init(&mut self, draw: &mut D); 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,
shared: &mut D,
draw: &mut D::Draw,
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 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 Config: ThemeConfig[src]
type Config: ThemeConfig[src]The associated config type
type DrawHandle: DrawHandle[src]
type DrawHandle: DrawHandle[src]The associated DrawHandle implementation.
Required methods
fn apply_config(&mut self, config: &Self::Config) -> TkAction[src]
fn apply_config(&mut self, config: &Self::Config) -> TkAction[src]Apply/set the passed config
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.
fn new_window(&self, dpi_factor: f32) -> Self::Window[src]
fn new_window(&self, 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 = i32::conv_nearest(MARGIN * factor);
A reference to the draw backend is provided allowing configuration.
fn update_window(&self, window: &mut Self::Window, dpi_factor: f32)[src]
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.
unsafe fn draw_handle(
&self,
shared: &mut D,
draw: &mut D::Draw,
window: &mut Self::Window
) -> Self::DrawHandle[src]
unsafe fn draw_handle(
&self,
shared: &mut D,
draw: &mut D::Draw,
window: &mut Self::Window
) -> 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).
fn clear_color(&self) -> Rgba[src]
fn clear_color(&self) -> Rgba[src]Background colour
Implementations on Foreign Types
type DrawHandle = <T as Theme<D>>::DrawHandleunsafe fn draw_handle(
&self,
shared: &mut D,
draw: &mut D::Draw,
window: &mut Self::Window
) -> Self::DrawHandle[src]Implementors
type Window = DimensionsWindowtype DrawHandle = DrawHandle<'static, D>unsafe fn draw_handle<'a>(
&'a self,
shared: &'a mut D,
draw: &'a mut D::Draw,
window: &'a mut Self::Window
) -> Self::DrawHandle[src]type DrawHandle = StackDst<dyn DrawHandle>unsafe fn draw_handle<'a>(
&'a self,
shared: &'a mut D,
draw: &'a mut D::Draw,
window: &'a mut Self::Window
) -> StackDst<dyn DrawHandle>[src]type Window = DimensionsWindowtype DrawHandle = DrawHandle<'static, D>unsafe fn draw_handle<'a>(
&'a self,
shared: &'a mut D,
draw: &'a mut D::Draw,
window: &'a mut Self::Window
) -> Self::DrawHandle[src]