mirror of
https://github.com/danbulant/cushy
synced 2026-07-06 03:30:38 +00:00
parent
ab474e2b7d
commit
5b928327dc
3 changed files with 10 additions and 19 deletions
|
|
@ -99,6 +99,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
its child changes size.
|
its child changes size.
|
||||||
- `Stack` and `Grid` now properly recompute exact-sized `Lp` children when the
|
- `Stack` and `Grid` now properly recompute exact-sized `Lp` children when the
|
||||||
display scale is changed.
|
display scale is changed.
|
||||||
|
- `Button`'s colors are now fully reactive. The caching code to prevent color
|
||||||
|
duplicate change animations has been simplified to fix this.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -958,7 +958,7 @@ pub trait MakeWidget: Sized {
|
||||||
dynamic: impl IntoDynamicComponentValue,
|
dynamic: impl IntoDynamicComponentValue,
|
||||||
) -> Style
|
) -> Style
|
||||||
where
|
where
|
||||||
Value<C::ComponentType>: IntoComponentValue,
|
C::ComponentType: IntoComponentValue,
|
||||||
{
|
{
|
||||||
Style::new(Styles::new().with_dynamic(name, dynamic), self)
|
Style::new(Styles::new().with_dynamic(name, dynamic), self)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,7 @@ use kludgine::shapes::{Shape, StrokeOptions};
|
||||||
use kludgine::Color;
|
use kludgine::Color;
|
||||||
|
|
||||||
use crate::animation::{AnimationHandle, AnimationTarget, IntoAnimate, LinearInterpolate, Spawn};
|
use crate::animation::{AnimationHandle, AnimationTarget, IntoAnimate, LinearInterpolate, Spawn};
|
||||||
use crate::context::{
|
use crate::context::{AsEventContext, EventContext, GraphicsContext, LayoutContext, WidgetContext};
|
||||||
AsEventContext, EventContext, GraphicsContext, LayoutContext, WidgetCacheKey, WidgetContext,
|
|
||||||
};
|
|
||||||
use crate::styles::components::{
|
use crate::styles::components::{
|
||||||
AutoFocusableControls, DefaultActiveBackgroundColor, DefaultActiveForegroundColor,
|
AutoFocusableControls, DefaultActiveBackgroundColor, DefaultActiveForegroundColor,
|
||||||
DefaultBackgroundColor, DefaultDisabledBackgroundColor, DefaultDisabledForegroundColor,
|
DefaultBackgroundColor, DefaultDisabledBackgroundColor, DefaultDisabledForegroundColor,
|
||||||
|
|
@ -50,8 +48,7 @@ struct PerWindow {
|
||||||
|
|
||||||
#[derive(Default, Debug, Eq, PartialEq, Clone, Copy)]
|
#[derive(Default, Debug, Eq, PartialEq, Clone, Copy)]
|
||||||
struct CacheState {
|
struct CacheState {
|
||||||
key: WidgetCacheKey,
|
style: Option<ButtonColors>,
|
||||||
kind: ButtonKind,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type of a [`Button`] or similar clickable widget.
|
/// The type of a [`Button`] or similar clickable widget.
|
||||||
|
|
@ -232,13 +229,6 @@ impl Button {
|
||||||
let kind = self.kind.get_tracking_redraw(context);
|
let kind = self.kind.get_tracking_redraw(context);
|
||||||
let visual_state = Self::visual_style(context);
|
let visual_state = Self::visual_style(context);
|
||||||
|
|
||||||
let window_local = self.per_window.entry(context).or_default();
|
|
||||||
|
|
||||||
window_local.cached_state = CacheState {
|
|
||||||
key: context.cache_key(),
|
|
||||||
kind,
|
|
||||||
};
|
|
||||||
|
|
||||||
if context.is_default() {
|
if context.is_default() {
|
||||||
kind.colors_for_default(visual_state, context)
|
kind.colors_for_default(visual_state, context)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -253,6 +243,10 @@ impl Button {
|
||||||
fn update_colors(&mut self, context: &mut WidgetContext<'_>, immediate: bool) {
|
fn update_colors(&mut self, context: &mut WidgetContext<'_>, immediate: bool) {
|
||||||
let new_style = self.determine_stateful_colors(context);
|
let new_style = self.determine_stateful_colors(context);
|
||||||
let window_local = self.per_window.entry(context).or_default();
|
let window_local = self.per_window.entry(context).or_default();
|
||||||
|
if window_local.cached_state.style.as_ref() == Some(&new_style) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window_local.cached_state.style = Some(new_style);
|
||||||
|
|
||||||
match (immediate, &window_local.active_colors) {
|
match (immediate, &window_local.active_colors) {
|
||||||
(false, Some(style)) => {
|
(false, Some(style)) => {
|
||||||
|
|
@ -371,12 +365,7 @@ impl Widget for Button {
|
||||||
#![allow(clippy::similar_names)]
|
#![allow(clippy::similar_names)]
|
||||||
|
|
||||||
let current_style = self.kind.get_tracking_redraw(context);
|
let current_style = self.kind.get_tracking_redraw(context);
|
||||||
let window_local = self.per_window.entry(context).or_default();
|
self.update_colors(context, false);
|
||||||
if window_local.cached_state.key != context.cache_key()
|
|
||||||
|| window_local.cached_state.kind != current_style
|
|
||||||
{
|
|
||||||
self.update_colors(context, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let style = self.current_style(context);
|
let style = self.current_style(context);
|
||||||
context.fill(style.background);
|
context.fill(style.background);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue