Skip to content

Commit

Permalink
remove custom style trait
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton committed Aug 7, 2024
1 parent 4a1195e commit d661a82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
19 changes: 8 additions & 11 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,8 +1812,8 @@ impl Style {
}
}

pub fn apply_custom<CS: CustomStyle>(self, custom_style: CS) -> Self {
self.apply(custom_style.get_style())
pub fn apply_custom<CS: Into<Style>>(self, custom_style: CS) -> Self {
self.apply(custom_style.into())
}
}

Expand Down Expand Up @@ -1882,12 +1882,9 @@ impl Style {
}
}

pub trait CustomStyle {
fn new_custom_style() -> Self;
fn get_style(&self) -> Style;
}

pub trait CustomStylable<S: CustomStyle + 'static>: IntoView<V = Self::DV> + Sized {
pub trait CustomStylable<S: Default + Into<Style> + 'static>:
IntoView<V = Self::DV> + Sized
{
type DV: View;

/// # Add a custom style to the view with acess to this view's specialized custom style.
Expand All @@ -1901,10 +1898,10 @@ pub trait CustomStylable<S: CustomStyle + 'static>: IntoView<V = Self::DV> + Siz
let view_state = id.state();
let offset = view_state.borrow_mut().style.next_offset();
let style = create_updater(
move || style(S::new_custom_style()),
move |style| id.update_style(offset, style.get_style()),
move || style(S::default()),
move |style| id.update_style(offset, style.into()),
);
view_state.borrow_mut().style.push(style.get_style());
view_state.borrow_mut().style.push(style.into());
view
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/views/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
event::{Event, EventListener, EventPropagation},
id::ViewId,
prop, prop_extractor,
style::{CustomStylable, CustomStyle, Style, StyleClass, Width},
style::{CustomStylable, Style, StyleClass, Width},
style_class,
unit::PxPctAuto,
view::{default_compute_layout, IntoView, View},
Expand Down Expand Up @@ -310,13 +310,9 @@ impl<T> DropDown<T> {

#[derive(Debug, Clone, Default)]
pub struct DropDownCustomStyle(Style);
impl CustomStyle for DropDownCustomStyle {
fn new_custom_style() -> Self {
Self(Style::new())
}

fn get_style(&self) -> Style {
self.0.clone()
impl From<DropDownCustomStyle> for Style {
fn from(val: DropDownCustomStyle) -> Self {
val.0
}
}
impl<T> CustomStylable<DropDownCustomStyle> for DropDown<T> {
Expand Down
16 changes: 5 additions & 11 deletions src/views/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use crate::{
event::EventPropagation,
id::ViewId,
prop, prop_extractor,
style::{
Background, BorderRadius, CustomStylable, CustomStyle, Foreground, Height, Style,
StyleValue,
},
style::{Background, BorderRadius, CustomStylable, Foreground, Height, Style, StyleValue},
style_class,
unit::{PxPct, PxPctAuto},
view::View,
Expand Down Expand Up @@ -356,14 +353,11 @@ impl Slider {
}
}

#[derive(Debug, Default, Clone)]
pub struct SliderCustomStyle(Style);
impl CustomStyle for SliderCustomStyle {
fn new_custom_style() -> Self {
Self(Style::new())
}

fn get_style(&self) -> Style {
self.0.clone()
impl From<SliderCustomStyle> for Style {
fn from(val: SliderCustomStyle) -> Self {
val.0
}
}

Expand Down

0 comments on commit d661a82

Please sign in to comment.