Skip to content

Commit

Permalink
pass down disabled state from parent to child for styling
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Dec 27, 2023
1 parent 77bcbcb commit e795021
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,22 +421,23 @@ impl AppState {
self.compute_layout();
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn compute_style(
&mut self,
id: Id,
view_data: &mut ViewData,
view_style: Option<Style>,
view_interact_state: InteractionState,
view_class: Option<StyleClassRef>,
classes: &[StyleClassRef],
context: &Style,
) -> bool {
let interact_state = self.get_interact_state(&id);
let screen_size_bp = self.screen_size_bp;
let view_state = self.view_state(id);
view_state.compute_style(
view_data,
view_style,
interact_state,
view_interact_state,
screen_size_bp,
view_class,
classes,
Expand Down Expand Up @@ -1162,6 +1163,8 @@ pub struct StyleCx<'a> {
pub(crate) direct: Style,
saved: Vec<Rc<Style>>,
pub(crate) now: Instant,
saved_disabled: Vec<bool>,
disabled: bool,
}

impl<'a> StyleCx<'a> {
Expand All @@ -1173,6 +1176,8 @@ impl<'a> StyleCx<'a> {
direct: Default::default(),
saved: Default::default(),
now: Instant::now(),
saved_disabled: Default::default(),
disabled: false,
}
}

Expand Down Expand Up @@ -1208,10 +1213,14 @@ impl<'a> StyleCx<'a> {
});
}

let mut view_interact_state = self.app_state.get_interact_state(&id);
view_interact_state.is_disabled |= self.disabled;
self.disabled = view_interact_state.is_disabled;
let mut new_frame = self.app_state.compute_style(
id,
view.view_data_mut(),
view_style,
view_interact_state,
view_class,
classes,
&self.current,
Expand Down Expand Up @@ -1265,10 +1274,12 @@ impl<'a> StyleCx<'a> {

pub fn save(&mut self) {
self.saved.push(self.current.clone());
self.saved_disabled.push(self.disabled);
}

pub fn restore(&mut self) {
self.current = self.saved.pop().unwrap_or_default();
self.disabled = self.saved_disabled.pop().unwrap_or_default();
}

pub fn get_prop<P: StyleProp>(&self, _prop: P) -> Option<P::Type> {
Expand Down

0 comments on commit e795021

Please sign in to comment.