Skip to content

Commit

Permalink
Remove base_style
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jan 1, 2024
1 parent 3ce457a commit 2dba44d
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 64 deletions.
6 changes: 3 additions & 3 deletions examples/widget-gallery/src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ pub fn menu_view() -> impl View {
stack({
(
label(|| "Click me (Popout menu)")
.base_style(|s| s.padding(10.0).margin_bottom(10.0).border(1.0))
.style(|s| s.padding(10.0).margin_bottom(10.0).border(1.0))
.popout_menu(|| {
Menu::new("")
.entry(MenuItem::new("I am a menu item!"))
.separator()
.entry(MenuItem::new("I am another menu item"))
}),
label(|| "Right click me (Context menu)")
.base_style(|s| s.padding(10.0).border(1.0))
.style(|s| s.padding(10.0).border(1.0))
.context_menu(|| {
Menu::new("")
.entry(MenuItem::new("Menu item"))
.entry(MenuItem::new("Menu item with something on the\tright"))
}),
)
})
.base_style(|s| s.flex_col())
.style(|s| s.flex_col())
}
4 changes: 0 additions & 4 deletions src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ impl Id {
}
}

pub fn update_base_style(&self, style: Style) {
self.add_update_message(UpdateMessage::BaseStyle { id: *self, style });
}

pub(crate) fn update_style(&self, style: Style, offset: StackOffset<Style>) {
self.add_update_message(UpdateMessage::Style {
id: *self,
Expand Down
4 changes: 0 additions & 4 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ pub(crate) enum UpdateMessage {
id: Id,
state: Box<dyn Any>,
},
BaseStyle {
id: Id,
style: Style,
},
Style {
id: Id,
style: Style,
Expand Down
5 changes: 0 additions & 5 deletions src/view_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ pub struct ViewState {
pub(crate) layout_props: LayoutProps,
pub(crate) view_style_props: ViewStyleProps,
pub(crate) animation: Option<Animation>,
pub(crate) base_style: Option<Style>,
pub(crate) class: Option<StyleClassRef>,
pub(crate) dragging_style: Option<Style>,
pub(crate) combined_style: Style,
Expand All @@ -161,7 +160,6 @@ impl ViewState {
request_style_recursive: false,
has_style_selectors: StyleSelectors::default(),
animation: None,
base_style: None,
class: None,
combined_style: Style::new(),
taffy_style: taffy::style::Style::DEFAULT,
Expand Down Expand Up @@ -197,9 +195,6 @@ impl ViewState {
if let Some(view_class) = view_class {
computed_style = computed_style.apply_classes_from_context(&[view_class], context);
}
if let Some(base_style) = self.base_style.clone() {
computed_style.apply_mut(base_style);
}
computed_style = computed_style
.apply_classes_from_context(classes, context)
.apply(view_data.style());
Expand Down
32 changes: 1 addition & 31 deletions src/views/decorator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use crate::{
pub trait Decorators: View + Sized {
/// Alter the style of the view.
///
/// -----
///
/// Note: repeated applications of `style` overwrite previous styles.
/// Earlier applications of `style` have lower priority than later calls.
/// ```rust
/// # use floem::{peniko::Color, view::View, views::{Decorators, label, stack}};
/// fn view() -> impl View {
Expand All @@ -32,8 +30,6 @@ pub trait Decorators: View + Sized {
/// ))
/// }
/// ```
/// If you are returning from a function that produces a view, you may want
/// to use `base_style` for the returned [`View`] instead.
fn style(mut self, style: impl Fn(Style) -> Style + 'static) -> Self {
let id = self.id();
let offset = self.view_data_mut().style.next_offset();
Expand All @@ -45,32 +41,6 @@ pub trait Decorators: View + Sized {
self
}

/// Alter the base style of the view.
/// This is applied before `style`, and so serves as a good place to set defaults.
/// ```rust
/// # use floem::{peniko::Color, view::View, views::{Decorators, label, stack}};
/// fn view() -> impl View {
/// label(|| "Hello".to_string())
/// .base_style(|s| s.font_size(20.0).color(Color::RED))
/// }
///
/// fn other() -> impl View {
/// stack((
/// view(), // will be red and size 20
/// // will be green and size 20
/// view().style(|s| s.color(Color::GREEN)),
/// ))
/// }
/// ```
fn base_style(self, style: impl Fn(Style) -> Style + 'static) -> Self {
let id = self.id();
create_effect(move |_| {
let style = style(Style::new());
id.update_base_style(style);
});
self
}

/// The visual style to apply when the mouse hovers over the element
fn dragging_style(self, style: impl Fn(Style) -> Style + 'static) -> Self {
let id = self.id();
Expand Down
2 changes: 1 addition & 1 deletion src/views/drag_resize_window_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn drag_resize_window_area<V: View + 'static>(
.on_event_stop(EventListener::PointerDown, move |_| {
drag_resize_window(direction)
})
.base_style(move |s| {
.style(move |s| {
let cursor = match direction {
ResizeDirection::East => CursorStyle::ColResize,
ResizeDirection::West => CursorStyle::ColResize,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ pub fn labeled_checkbox<S: Display + 'static>(
) -> impl View {
h_stack((checkbox_svg(checked), views::label(label)))
.class(LabeledCheckboxClass)
.base_style(|s| s.items_center().justify_center())
.style(|s| s.items_center().justify_center())
.keyboard_navigatable()
}
15 changes: 0 additions & 15 deletions src/window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,21 +785,6 @@ impl WindowHandle {
cx.update_view(&mut self.view, id_path.dispatch(), state);
}
}
UpdateMessage::BaseStyle { id, style } => {
let state = cx.app_state.view_state(id);
let old_any_inherited = state
.base_style
.as_ref()
.map(|style| style.any_inherited())
.unwrap_or(false);
let new_any_inherited = style.any_inherited();
state.base_style = Some(style);
if new_any_inherited || old_any_inherited {
cx.app_state.request_style_recursive(id);
} else {
cx.request_style(id);
}
}
UpdateMessage::Style { id, style, offset } => {
update_data(id, &mut self.view, |data| {
let old_any_inherited = data.style().any_inherited();
Expand Down

0 comments on commit 2dba44d

Please sign in to comment.