diff --git a/examples/gameui.rs b/examples/gameui.rs index 9c93ee2..4a6cb89 100644 --- a/examples/gameui.rs +++ b/examples/gameui.rs @@ -21,7 +21,7 @@ fn main() -> gooey::Result { .and(Input::new(chat_message.clone()).on_key(move |input| { match (input.state, input.logical_key) { (ElementState::Pressed, Key::Enter) => { - let new_message = chat_message.map_mut(|text| std::mem::take(text)); + let new_message = chat_message.map_mut(std::mem::take); chat_log.map_mut(|chat_log| { chat_log.push_str(&new_message); chat_log.push('\n'); diff --git a/src/context.rs b/src/context.rs index 4f53ea8..834a5fe 100644 --- a/src/context.rs +++ b/src/context.rs @@ -15,7 +15,7 @@ use kludgine::{Color, Kludgine}; use crate::graphics::Graphics; use crate::styles::components::{HighlightColor, VisualOrder, WidgetBackground}; use crate::styles::{ComponentDefaultvalue, ComponentDefinition, Styles, Theme, ThemePair}; -use crate::value::{Dynamic, Value}; +use crate::value::{Dynamic, IntoValue, Value}; use crate::widget::{EventHandling, ManagedWidget, WidgetId, WidgetInstance, WidgetRef}; use crate::window::sealed::WindowCommand; use crate::window::{RunningWindow, ThemeMode}; @@ -196,7 +196,7 @@ impl<'context, 'window> EventContext<'context, 'window> { } true } - Err(_) => false, + Err(()) => false, }; if new { if let Some(active) = self.pending_state.active.clone() { @@ -250,7 +250,7 @@ impl<'context, 'window> EventContext<'context, 'window> { } true } - Err(_) => false, + Err(()) => false, }; if new { if let Some(focus) = self.pending_state.focus.clone() { @@ -890,8 +890,8 @@ impl<'context, 'window> WidgetContext<'context, 'window> { /// /// Style queries for children will return any values matching this /// collection. - pub fn attach_styles(&self, styles: Value) { - self.current_node.attach_styles(styles); + pub fn attach_styles(&self, styles: impl IntoValue) { + self.current_node.attach_styles(styles.into_value()); } /// Attaches `theme` to the widget hierarchy for this widget. diff --git a/src/lib.rs b/src/lib.rs index 7ace2ba..7d0ef5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ pub mod animation; pub mod context; mod graphics; mod names; +#[macro_use] pub mod styles; mod tick; mod tree; diff --git a/src/styles.rs b/src/styles.rs index 19a137b..931ccc7 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -22,6 +22,7 @@ use crate::styles::components::{FocusableWidgets, VisualOrder}; use crate::utils::Lazy; use crate::value::{Dynamic, IntoValue, Value}; +#[macro_use] pub mod components; /// A collection of style components organized by their name. @@ -58,7 +59,7 @@ impl Styles { /// Adds a [`Component`] for the name provided and returns self. #[must_use] - pub fn with(mut self, name: &impl NamedComponent, component: impl Into) -> Self { + pub fn with(mut self, name: &impl NamedComponent, component: impl IntoComponentValue) -> Self { self.insert(name, component); self } @@ -1007,7 +1008,7 @@ impl SurfaceTheme { Self { color: neutral.color(98), dim_color: neutral_variant.color(70), - bright_color: neutral.color(99), + bright_color: neutral.color(100), lowest_container: neutral.color(100), low_container: neutral.color(96), container: neutral.color(95), @@ -1027,7 +1028,7 @@ impl SurfaceTheme { Self { color: neutral.color(10), dim_color: neutral_variant.color(2), - bright_color: neutral.color(10), + bright_color: neutral.color(11), lowest_container: neutral.color(15), low_container: neutral.color(20), container: neutral.color(25), @@ -1158,6 +1159,7 @@ impl ColorSource { #[must_use] pub fn contrast_between(self, other: Self) -> ZeroToOne { let saturation_delta = self.saturation.difference_between(other.saturation); + let self_hue = self.hue.into_positive_degrees(); let other_hue = other.hue.into_positive_degrees(); // Calculate the shortest distance between the hues, taking into account @@ -1277,7 +1279,7 @@ impl ColorExt for Color { let other_alpha = ZeroToOne::new(self.alpha_f32()); let alpha_delta = check_alpha.difference_between(other_alpha); - lightness_delta * source_change * alpha_delta + ZeroToOne::new((*lightness_delta + *source_change + *alpha_delta) / 3.) } fn most_contrasting(self, others: &[Self]) -> Self diff --git a/src/styles/components.rs b/src/styles/components.rs index 0baa24c..b077d91 100644 --- a/src/styles/components.rs +++ b/src/styles/components.rs @@ -12,6 +12,52 @@ use crate::styles::{ Component, ComponentDefinition, ComponentName, Dimension, Global, NamedComponent, }; +macro_rules! define_components { + ($($widget:ident { $($(#$doc:tt)* $component:ident($type:ty, $name:expr, $($default:tt)*))* })*) => {$($( + $(#$doc)* + #[derive(Clone, Copy, Eq, PartialEq, Debug)] + pub struct $component; + + const _: () = { + use $crate::styles::{ComponentDefinition, ComponentName, NamedComponent}; + impl NamedComponent for $component { + fn name(&self) -> Cow<'_, ComponentName> { + Cow::Owned(ComponentName::named::