[−][src]Trait kas::theme::Theme
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<Draw> + 'static
The associated Window
implementation.
type DrawHandle: DrawHandle
The associated DrawHandle
implementation.
Required methods
fn new_window(&self, draw: &mut Draw, dpi_factor: f32) -> Self::Window
Construct per-window storage
A reference to the draw backend is provided allowing configuration.
See also documentation on Window::set_dpi_factor
.
unsafe fn draw_handle(
&self,
draw: &mut Draw,
theme_window: &mut Self::Window,
rect: Rect
) -> Self::DrawHandle
&self,
draw: &mut Draw,
theme_window: &mut Self::Window,
rect: Rect
) -> Self::DrawHandle
Construct a DrawHandle
object
Drawing via this DrawHandle
is restricted to the specified rect
.
The theme_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
.
Note: this function is marked unsafe because the returned object requires a lifetime bound not exceeding that of all three pointers passed in. This ought to be expressible using generic associated types but currently is not: https://github.com/rust-lang/rust/issues/67089
fn get_fonts<'a>(&self) -> Vec<Font<'a>>
Get the list of available fonts
Currently, all fonts used must be specified up front by this method. (Dynamic addition of fonts may be enabled in the future.)
This is considered a "getter" rather than a "constructor" method since
the Font
type is cheap to copy, and each window requires its own copy.
It may also be useful to retain a Font
handle for access to its
methods.
Corresponding FontId
s may be created from the index into this list.
The first font in the list will be the default font.
TODO: this part of the API is dependent on rusttype::Font
. We should
build an abstraction over this, or possibly just pass the font bytes
(although this makes re-use of fonts between windows difficult).
fn light_direction(&self) -> (f32, f32)
Light source
This affects shadows on frames, etc. The light source has neutral colour and intensity such that the colour of flat surfaces is unaffected.
Return value: (a, b)
where 0 ≤ a < pi/2
is the angle to the screen
normal (i.e. a = 0
is straight at the screen) and b
is the bearing
(from UP, clockwise), both in radians.
Currently this is not updated after initial set-up.
fn clear_colour(&self) -> Colour
Background colour