Skip to content

Commit

Permalink
Added WIP theming system
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Nov 10, 2023
1 parent 724f6d7 commit d7384b6
Show file tree
Hide file tree
Showing 11 changed files with 865 additions and 159 deletions.
108 changes: 105 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ intentional = "0.1.0"
tracing = "0.1.40"

tracing-subscriber = { version = "0.3", optional = true }
palette = "0.7.3"


# [patch."https://github.com/khonsulabs/kludgine"]
Expand Down
23 changes: 22 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use std::sync::Arc;
use kludgine::app::winit::event::{
DeviceId, Ime, KeyEvent, MouseButton, MouseScrollDelta, TouchPhase,
};
use kludgine::app::winit::window;
use kludgine::figures::units::{Px, UPx};
use kludgine::figures::{IntoSigned, Point, Rect, Size};
use kludgine::shapes::{Shape, StrokeOptions};
use kludgine::Kludgine;

use crate::graphics::Graphics;
use crate::styles::components::{HighlightColor, VisualOrder};
use crate::styles::{ComponentDefaultvalue, ComponentDefinition, Styles};
use crate::styles::{ComponentDefaultvalue, ComponentDefinition, Styles, Theme, ThemePair};
use crate::value::Dynamic;
use crate::widget::{EventHandling, ManagedWidget, WidgetId, WidgetInstance, WidgetRef};
use crate::window::sealed::WindowCommand;
Expand Down Expand Up @@ -661,13 +662,15 @@ pub struct WidgetContext<'context, 'window> {
current_node: ManagedWidget,
redraw_status: &'context RedrawStatus,
window: &'context mut RunningWindow<'window>,
theme: &'context ThemePair,
pending_state: PendingState<'context>,
}

impl<'context, 'window> WidgetContext<'context, 'window> {
pub(crate) fn new(
current_node: ManagedWidget,
redraw_status: &'context RedrawStatus,
theme: &'context ThemePair,
window: &'context mut RunningWindow<'window>,
) -> Self {
Self {
Expand All @@ -683,6 +686,7 @@ impl<'context, 'window> WidgetContext<'context, 'window> {
}),
current_node,
redraw_status,
theme,
window,
}
}
Expand All @@ -693,6 +697,7 @@ impl<'context, 'window> WidgetContext<'context, 'window> {
current_node: self.current_node.clone(),
redraw_status: self.redraw_status,
window: &mut *self.window,
theme: self.theme,
pending_state: self.pending_state.borrowed(),
}
}
Expand All @@ -710,6 +715,7 @@ impl<'context, 'window> WidgetContext<'context, 'window> {
current_node,
redraw_status: self.redraw_status,
window: &mut *self.window,
theme: self.theme,
pending_state: self.pending_state.borrowed(),
})
}
Expand Down Expand Up @@ -909,6 +915,21 @@ impl<'context, 'window> WidgetContext<'context, 'window> {
pub fn window_mut(&mut self) -> &mut RunningWindow<'window> {
self.window
}

/// Returns the theme pair for the window.
#[must_use]
pub fn theme_pair(&self) -> &ThemePair {
self.theme
}

/// Returns the current theme in either light or dark mode.
#[must_use]
pub fn theme(&self) -> &Theme {
match self.window.theme() {
window::Theme::Light => &self.theme.light,
window::Theme::Dark => &self.theme.dark,
}
}
}

pub(crate) struct WindowHandle {
Expand Down
Loading

0 comments on commit d7384b6

Please sign in to comment.