Skip to content

Commit 4918b16

Browse files
committed
Move MultiTheme to kas::theme
1 parent 47f8358 commit 4918b16

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

kas-wgpu/examples/gallery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn main() -> Result<(), kas_wgpu::Error> {
136136
);
137137

138138
#[cfg(feature = "stack_dst")]
139-
let theme = kas_wgpu::theme::MultiTheme::builder()
139+
let theme = kas::theme::MultiTheme::builder()
140140
.add("shaded", kas_wgpu::theme::ShadedTheme::new())
141141
.add("flat", kas_wgpu::theme::FlatTheme::new())
142142
.build();

kas-wgpu/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
//! Toolkit for kas
77
88
#![cfg_attr(feature = "gat", feature(generic_associated_types))]
9-
#![feature(unsize)]
10-
11-
#[cfg(all(feature = "gat", feature = "stack_dst"))]
12-
compile_error!("Crate features 'gat' and 'stack_dst' are incompatible.");
139

1410
pub mod draw;
1511
mod event_loop;

kas-wgpu/src/theme/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
88
mod dimensions;
99
mod flat_theme;
10-
#[cfg(feature = "stack_dst")]
11-
mod multi_theme;
1210
mod shaded_theme;
1311

1412
pub(crate) use dimensions::{Dimensions, DimensionsParams, DimensionsWindow};
1513

1614
pub use flat_theme::FlatTheme;
17-
#[cfg(feature = "stack_dst")]
18-
pub use multi_theme::MultiTheme;
1915
pub use shaded_theme::ShadedTheme;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
#![cfg_attr(feature = "nightly", feature(new_uninit))]
2222
#![cfg_attr(feature = "gat", feature(generic_associated_types))]
23+
#![feature(unsize)]
2324

2425
#[cfg(all(feature = "gat", feature = "stack_dst"))]
2526
compile_error!("Crate features 'gat' and 'stack_dst' are incompatible.");

src/theme/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
2121
use kas::Align;
2222

23+
#[cfg(all(feature = "stack_dst", not(feature = "gat")))]
24+
mod multi_theme;
2325
#[cfg(all(feature = "stack_dst", not(feature = "gat")))]
2426
mod theme_dst;
2527
mod theme_handle;
2628
mod theme_traits;
2729

30+
#[cfg(all(feature = "stack_dst", not(feature = "gat")))]
31+
pub use multi_theme::MultiTheme;
2832
#[cfg(all(feature = "stack_dst", not(feature = "gat")))]
2933
pub use theme_dst::{StackDst, ThemeDst, WindowDst};
3034
pub use theme_handle::{DrawHandle, SizeHandle};

kas-wgpu/src/theme/multi_theme.rs renamed to src/theme/multi_theme.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,42 @@
55

66
//! Wrapper around mutliple themes, supporting run-time switching
77
8+
use rusttype::Font;
89
use std::collections::HashMap;
910
use std::marker::Unsize;
10-
use wgpu_glyph::Font;
1111

1212
use kas::draw::Colour;
1313
use kas::geom::Rect;
1414
use kas::theme::{self, StackDst, Theme, ThemeAction, ThemeApi, ThemeDst};
1515

16-
use crate::draw::DrawPipe;
17-
18-
/// Supported theme type
19-
type DynTheme = dyn ThemeDst<DrawPipe>;
20-
2116
/// Wrapper around mutliple themes, supporting run-time switching
22-
pub struct MultiTheme {
17+
pub struct MultiTheme<Draw> {
2318
names: HashMap<String, usize>,
24-
themes: Vec<StackDst<DynTheme>>,
19+
themes: Vec<StackDst<dyn ThemeDst<Draw>>>,
2520
active: usize,
2621
}
2722

28-
pub struct MultiThemeBuilder {
23+
pub struct MultiThemeBuilder<Draw> {
2924
names: HashMap<String, usize>,
30-
themes: Vec<StackDst<DynTheme>>,
25+
themes: Vec<StackDst<dyn ThemeDst<Draw>>>,
3126
}
3227

33-
impl MultiTheme {
28+
impl<Draw> MultiTheme<Draw> {
3429
/// Construct with builder pattern
35-
pub fn builder() -> MultiThemeBuilder {
30+
pub fn builder() -> MultiThemeBuilder<Draw> {
3631
MultiThemeBuilder {
3732
names: HashMap::new(),
3833
themes: vec![],
3934
}
4035
}
4136
}
4237

43-
impl MultiThemeBuilder {
38+
impl<Draw> MultiThemeBuilder<Draw> {
4439
/// Add a theme
4540
pub fn add<S: ToString, U>(mut self, name: S, theme: U) -> Self
4641
where
47-
U: Unsize<DynTheme>,
48-
Box<U>: Unsize<DynTheme>,
42+
U: Unsize<dyn ThemeDst<Draw>>,
43+
Box<U>: Unsize<dyn ThemeDst<Draw>>,
4944
{
5045
let index = self.themes.len();
5146
self.names.insert(name.to_string(), index);
@@ -56,7 +51,7 @@ impl MultiThemeBuilder {
5651
/// Build
5752
///
5853
/// Fails if no themes were added.
59-
pub fn try_build(self) -> Result<MultiTheme, ()> {
54+
pub fn try_build(self) -> Result<MultiTheme<Draw>, ()> {
6055
if self.themes.len() == 0 {
6156
return Err(());
6257
}
@@ -70,17 +65,17 @@ impl MultiThemeBuilder {
7065
/// Build
7166
///
7267
/// Panics if no themes were added.
73-
pub fn build(self) -> MultiTheme {
68+
pub fn build(self) -> MultiTheme<Draw> {
7469
self.try_build()
7570
.unwrap_or_else(|_| panic!("MultiThemeBuilder: no themes added"))
7671
}
7772
}
7873

79-
impl Theme<DrawPipe> for MultiTheme {
80-
type Window = StackDst<dyn theme::WindowDst<DrawPipe>>;
74+
impl<Draw: 'static> Theme<Draw> for MultiTheme<Draw> {
75+
type Window = StackDst<dyn theme::WindowDst<Draw>>;
8176
type DrawHandle = StackDst<dyn theme::DrawHandle>;
8277

83-
fn new_window(&self, draw: &mut DrawPipe, dpi_factor: f32) -> Self::Window {
78+
fn new_window(&self, draw: &mut Draw, dpi_factor: f32) -> Self::Window {
8479
self.themes[self.active].new_window(draw, dpi_factor)
8580
}
8681

@@ -90,7 +85,7 @@ impl Theme<DrawPipe> for MultiTheme {
9085

9186
unsafe fn draw_handle<'a>(
9287
&'a self,
93-
draw: &'a mut DrawPipe,
88+
draw: &'a mut Draw,
9489
window: &'a mut Self::Window,
9590
rect: Rect,
9691
) -> StackDst<dyn theme::DrawHandle> {
@@ -110,7 +105,7 @@ impl Theme<DrawPipe> for MultiTheme {
110105
}
111106
}
112107

113-
impl ThemeApi for MultiTheme {
108+
impl<Draw> ThemeApi for MultiTheme<Draw> {
114109
fn set_font_size(&mut self, size: f32) -> ThemeAction {
115110
// Slightly inefficient, but sufficient: update both
116111
// (Otherwise we would have to call set_colours in set_theme too.)

src/theme/theme_traits.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
//! Theme traits
77
8+
use rusttype::Font;
89
use std::any::Any;
910
use std::ops::{Deref, DerefMut};
1011

11-
use rusttype::Font;
12-
1312
use super::{DrawHandle, SizeHandle, ThemeAction};
1413
use kas::draw::Colour;
1514
use kas::geom::Rect;

0 commit comments

Comments
 (0)