Skip to content

Commit

Permalink
Consistently apply overridden theme
Browse files Browse the repository at this point in the history
Refs #196
  • Loading branch information
ecton committed Oct 24, 2024
1 parent 0e0c26f commit 0fe7f78
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `GraphicsContext::fill` now properly fills the entire region of the widget.
- `Slider` now correctly calculates its width when in a fully `SizeToFit`
layout.
- `ThemedMode` is now properly applied consistently. Previously sometimes the
window's theme mode would be used instead of the overridden mode.

### Added

Expand Down
21 changes: 17 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,10 @@ impl<'context> WidgetContext<'context> {
) -> Self {
let enabled = current_node.enabled(&window.handle());
let tree = current_node.tree();
Self {

let (effective_styles, overridden_theme, overridden_theme_mode) =
current_node.overridden_theme();
let mut context = Self {
pending_state: PendingState::Owned(PendingWidgetState {
focus: tree
.focused_widget()
Expand All @@ -926,7 +929,7 @@ impl<'context> WidgetContext<'context> {
unmounting: false,
}),
tree,
effective_styles: current_node.effective_styles(),
effective_styles,
cache: WidgetCacheKey {
kludgine_id: Some(window.kludgine_id()),
theme_mode,
Expand All @@ -937,7 +940,16 @@ impl<'context> WidgetContext<'context> {
font_state,
theme: Cow::Borrowed(theme),
window,
};

if let Some(theme) = overridden_theme {
context.theme = Cow::Owned(theme.get_tracking_redraw(&context));
}
if let Some(mode) = overridden_theme_mode {
context.cache.theme_mode = mode.get_tracking_redraw(&context);
}

context
}

/// Returns a new instance that borrows from `self`.
Expand Down Expand Up @@ -965,7 +977,7 @@ impl<'context> WidgetContext<'context> {
Widget::Managed: MapManagedWidget<WidgetContext<'child>>,
{
widget.manage(self).map(|current_node| {
let (effective_styles, theme, theme_mode) = current_node.overidden_theme();
let (effective_styles, theme, theme_mode) = current_node.overridden_theme();
let theme = if let Some(theme) = theme {
Cow::Owned(theme.get_tracking_redraw(self))
} else {
Expand Down Expand Up @@ -1171,7 +1183,8 @@ impl<'context> WidgetContext<'context> {
/// Attaches `theme_mode` to the widget hierarchy for this widget.
///
/// All children nodes will use this theme mode.
pub fn attach_theme_mode(&self, theme_mode: Value<ThemeMode>) {
pub fn attach_theme_mode(&mut self, theme_mode: Value<ThemeMode>) {
self.cache.theme_mode = theme_mode.get();
self.current_node.attach_theme_mode(theme_mode);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl Tree {
data.nodes.get_mut(id).expect("missing widget").theme_mode = Some(theme);
}

pub(crate) fn overriden_theme(
pub(crate) fn overridden_theme(
&self,
id: LotId,
) -> (Styles, Option<Value<ThemePair>>, Option<Value<ThemeMode>>) {
Expand Down
4 changes: 2 additions & 2 deletions src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1991,10 +1991,10 @@ impl MountedWidget {
self.tree().attach_theme_mode(self.node_id, theme);
}

pub(crate) fn overidden_theme(
pub(crate) fn overridden_theme(
&self,
) -> (Styles, Option<Value<ThemePair>>, Option<Value<ThemeMode>>) {
self.tree().overriden_theme(self.node_id)
self.tree().overridden_theme(self.node_id)
}

pub(crate) fn begin_layout(&self, constraints: Size<ConstraintLimit>) -> Option<Size<UPx>> {
Expand Down

0 comments on commit 0fe7f78

Please sign in to comment.