Skip to content

Commit 297e278

Browse files
authored
Merge pull request #660 from kas-gui/push-puqoyzywsrnm
Remove type parameter D: DrawImpl from kas::theme::dimensions::Window
2 parents a884b97 + da3ae70 commit 297e278

5 files changed

Lines changed: 24 additions & 21 deletions

File tree

crates/kas-core/src/theme/anim.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
use crate::Id;
99
use crate::draw::DrawImpl;
10-
use std::marker::PhantomData;
1110
use std::time::{Duration, Instant};
1211

1312
#[derive(Debug)]
@@ -18,14 +17,13 @@ struct Config {
1817

1918
/// State holding theme animation data
2019
#[derive(Debug)]
21-
pub struct AnimState<D> {
20+
pub struct AnimState {
2221
c: Config,
2322
now: Instant, // frame start time
2423
text_cursor: TextCursor,
25-
_d: PhantomData<D>,
2624
}
2725

28-
impl<D> AnimState<D> {
26+
impl AnimState {
2927
pub fn new(config: &crate::config::ThemeConfig) -> Self {
3028
let c = Config {
3129
cursor_blink_rate: config.cursor_blink_rate(),
@@ -41,7 +39,6 @@ impl<D> AnimState<D> {
4139
state: false,
4240
time: now,
4341
},
44-
_d: PhantomData,
4542
}
4643
}
4744

@@ -61,11 +58,14 @@ struct TextCursor {
6158
state: bool,
6259
time: Instant,
6360
}
64-
impl<D: DrawImpl> AnimState<D> {
61+
impl AnimState {
6562
/// Flashing text cursor: return true to draw
6663
///
6764
/// Assumption: only one widget may draw a text cursor at any time.
68-
pub fn text_cursor(&mut self, draw: &mut D, id: &Id, byte: usize) -> bool {
65+
pub fn text_cursor<D>(&mut self, draw: &mut D, id: &Id, byte: usize) -> bool
66+
where
67+
D: DrawImpl,
68+
{
6969
let entry = &mut self.text_cursor;
7070
let widget = id.to_nzu64().get();
7171
if entry.widget == widget && entry.byte == byte {
@@ -86,12 +86,15 @@ impl<D: DrawImpl> AnimState<D> {
8686
}
8787
}
8888

89-
impl<D: DrawImpl> AnimState<D> {
89+
impl AnimState {
9090
/// Fade over a boolean transition
9191
///
9292
/// Normally returns `1.0` if `state` else `0.0`, but within a short time
9393
/// after a state change will linearly transition between these values.
94-
pub fn fade_bool(&mut self, draw: &mut D, state: bool, last_change: Option<Instant>) -> f32 {
94+
pub fn fade_bool<D>(&mut self, draw: &mut D, state: bool, last_change: Option<Instant>) -> f32
95+
where
96+
D: DrawImpl,
97+
{
9598
if let Some(dur) = last_change.and_then(|inst| self.elapsed(inst))
9699
&& dur < self.c.fade_dur
97100
{

crates/kas-core/src/theme/dimensions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ impl Dimensions {
160160
}
161161
}
162162

163-
/// A convenient implementation of [`crate::window::Window`]
164-
pub struct Window<D> {
163+
/// A convenient implementation of [`crate::theme::Window`]
164+
pub struct Window {
165165
pub config: Rc<RefCell<Config>>,
166166
pub dims: Dimensions,
167-
pub anim: AnimState<D>,
167+
pub anim: AnimState,
168168
}
169169

170-
impl<D> Window<D> {
170+
impl Window {
171171
pub fn new(dims: &Parameters, config: &WindowConfig) -> Self {
172172
Window {
173173
config: config.clone_base(),
@@ -187,7 +187,7 @@ impl<D> Window<D> {
187187
}
188188
}
189189

190-
impl<D: 'static> super::Window for Window<D> {
190+
impl super::Window for Window {
191191
fn size(&self) -> &dyn ThemeSize {
192192
self
193193
}
@@ -197,7 +197,7 @@ impl<D: 'static> super::Window for Window<D> {
197197
}
198198
}
199199

200-
impl<D: 'static> ThemeSize for Window<D> {
200+
impl ThemeSize for Window {
201201
fn scale_factor(&self) -> f32 {
202202
self.dims.scale
203203
}

crates/kas-core/src/theme/flat_theme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ fn dimensions() -> dim::Parameters {
7979
pub struct DrawHandle<'a, DS: DrawSharedImpl> {
8080
pub(crate) draw: DrawIface<'a, DS>,
8181
pub(crate) ev: &'a mut EventState,
82-
pub(crate) w: &'a mut dim::Window<DS::Draw>,
82+
pub(crate) w: &'a mut dim::Window,
8383
pub(crate) cols: &'a ColorsLinear,
8484
}
8585

8686
impl<DS: DrawSharedImpl> Theme<DS> for FlatTheme
8787
where
8888
DS::Draw: DrawRoundedImpl,
8989
{
90-
type Window = dim::Window<DS::Draw>;
90+
type Window = dim::Window;
9191
type Draw<'a> = DrawHandle<'a, DS>;
9292

9393
fn init(&mut self, config: &RefCell<Config>) {

crates/kas-core/src/theme/simple_theme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ impl SimpleTheme {
5555
pub struct DrawHandle<'a, DS: DrawSharedImpl> {
5656
pub(crate) draw: DrawIface<'a, DS>,
5757
pub(crate) ev: &'a mut EventState,
58-
pub(crate) w: &'a mut dim::Window<DS::Draw>,
58+
pub(crate) w: &'a mut dim::Window,
5959
pub(crate) cols: &'a ColorsLinear,
6060
}
6161

6262
impl<DS: DrawSharedImpl> Theme<DS> for SimpleTheme {
63-
type Window = dim::Window<DS::Draw>;
63+
type Window = dim::Window;
6464
type Draw<'a> = DrawHandle<'a, DS>;
6565

6666
fn init(&mut self, _: &RefCell<Config>) {}

crates/kas-wgpu/src/shaded_theme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ const NORMS_RAISED: (f32, f32) = (0.0, 0.7);
6868
pub struct DrawHandle<'a, DS: DrawSharedImpl> {
6969
draw: DrawIface<'a, DS>,
7070
ev: &'a mut EventState,
71-
w: &'a mut dim::Window<DS::Draw>,
71+
w: &'a mut dim::Window,
7272
cols: &'a ColorsLinear,
7373
}
7474

7575
impl<DS: DrawSharedImpl> Theme<DS> for ShadedTheme
7676
where
7777
DS::Draw: DrawRoundedImpl + DrawShadedImpl,
7878
{
79-
type Window = dim::Window<DS::Draw>;
79+
type Window = dim::Window;
8080
type Draw<'a> = DrawHandle<'a, DS>;
8181

8282
fn init(&mut self, config: &RefCell<Config>) {

0 commit comments

Comments
 (0)