From f85b2f988b8296ac61be1e4d45bae2b6002099c5 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 27 Dec 2023 13:43:10 -0800 Subject: [PATCH] Added Default components Closes #116 --- .crate-docs.md | 7 ++++++- .rustme/docs.md | 7 ++++++- CHANGELOG.md | 9 +++++++++ README.md | 7 ++++++- src/styles/components.rs | 26 ++++++++++++++++++++++++++ src/widgets/button.rs | 38 ++++++++++++++++++++------------------ src/widgets/checkbox.rs | 16 ++++++++++------ 7 files changed, 83 insertions(+), 27 deletions(-) diff --git a/.crate-docs.md b/.crate-docs.md index a890c14..f9a45a2 100644 --- a/.crate-docs.md +++ b/.crate-docs.md @@ -3,7 +3,12 @@ [![Documentation for `main` branch](https://img.shields.io/badge/docs-main-informational)](https://gooey.rs/main/docs/gooey/) Gooey is an experimental Graphical User Interface (GUI) crate for the Rust -programming language. It is powered by: +programming language. It features a reactive data model and aims to enable +easily creating responsive, efficient user interfaces. To enable easy +cross-platform development, Gooey uses its own collection of consistently-styled +[`Widget`s][widget]. + +Gooey is powered by: - [`Kludgine`][kludgine], a 2d graphics library powered by: - [`winit`][winit] for windowing/input diff --git a/.rustme/docs.md b/.rustme/docs.md index 5fbf365..6937956 100644 --- a/.rustme/docs.md +++ b/.rustme/docs.md @@ -3,7 +3,12 @@ [![Documentation for `main` branch](https://img.shields.io/badge/docs-main-informational)]($docs$) Gooey is an experimental Graphical User Interface (GUI) crate for the Rust -programming language. It is powered by: +programming language. It features a reactive data model and aims to enable +easily creating responsive, efficient user interfaces. To enable easy +cross-platform development, Gooey uses its own collection of consistently-styled +[`Widget`s][widget]. + +Gooey is powered by: - [`Kludgine`][kludgine], a 2d graphics library powered by: - [`winit`][winit] for windowing/input diff --git a/CHANGELOG.md b/CHANGELOG.md index df6f997..7cc3ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `PendingWindow` is a new type that can return a `WindowHandle` for a window that hasn't opened yet. This can be used to allow a widget on a window to close the window. +- Style components for customizing default widget colors have been added: + - `DefaultForegroundColor` + - `DefaultBackgroundColor` + - `DefaultHoveredForegroundColor` + - `DefaultHoveredBackgroundColor` + - `DefaultActiveForegroundColor` + - `DefaultActiveBackgroundColor` + - `DefaultDisabledForegroundColor` + - `DefaultDisabledBackgroundColor` [91]: https://github.com/khonsulabs/gooey/issues/91 [92]: https://github.com/khonsulabs/gooey/issues/92 diff --git a/README.md b/README.md index d2d03e7..9228c1d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,12 @@ [![Documentation for `main` branch](https://img.shields.io/badge/docs-main-informational)](https://gooey.rs/main/docs/gooey/) Gooey is an experimental Graphical User Interface (GUI) crate for the Rust -programming language. It is powered by: +programming language. It features a reactive data model and aims to enable +easily creating responsive, efficient user interfaces. To enable easy +cross-platform development, Gooey uses its own collection of consistently-styled +[`Widget`s][widget]. + +Gooey is powered by: - [`Kludgine`][kludgine], a 2d graphics library powered by: - [`winit`][winit] for windowing/input diff --git a/src/styles/components.rs b/src/styles/components.rs index d8dab6d..5783290 100644 --- a/src/styles/components.rs +++ b/src/styles/components.rs @@ -154,6 +154,32 @@ define_components! { TertiaryColor(Color, "tertiary_color", .tertiary.color) /// The error color from the current theme. ErrorColor(Color, "error_color", .error.color) + /// The foreground color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default). + DefaultForegroundColor(Color, "default_foreground_color", .primary.on_color) + /// The background color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default). + DefaultBackgroundColor(Color, "default_background_color", .primary.color) + /// The foreground color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default) that is hovered by + /// the cursor. + DefaultHoveredForegroundColor(Color, "default_hovered_foreground_color", @DefaultForegroundColor) + /// The background color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default) that is hovered by + /// the cursor. + DefaultHoveredBackgroundColor(Color, "default_hovered_background_color", .primary.color_bright) + /// The foreground color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default) that is activated. + DefaultActiveForegroundColor(Color, "default_active_foreground_color", .primary.on_color) + /// The background color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default) that is activated. + DefaultActiveBackgroundColor(Color, "default_active_background_color", .primary.color_dim) + /// The foreground color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default) that is disabled. + DefaultDisabledForegroundColor(Color, "default_disabled_foreground_color", .primary.on_color) + /// The background color to use when drawing a [default + /// widget](crate::widget::MakeWidget::into_default) that is disabled. + DefaultDisabledBackgroundColor(Color, "default_disabled_background_color", .primary.color_dim) /// Intrinsic, uniform padding for a widget. /// /// This component is opt-in and does not automatically work for all widgets. diff --git a/src/widgets/button.rs b/src/widgets/button.rs index 1b07dca..8f8b593 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -13,8 +13,10 @@ use crate::context::{ AsEventContext, EventContext, GraphicsContext, LayoutContext, WidgetCacheKey, WidgetContext, }; use crate::styles::components::{ - AutoFocusableControls, Easing, HighlightColor, IntrinsicPadding, OpaqueWidgetColor, - OutlineColor, SurfaceColor, TextColor, + AutoFocusableControls, DefaultActiveBackgroundColor, DefaultActiveForegroundColor, + DefaultBackgroundColor, DefaultDisabledBackgroundColor, DefaultDisabledForegroundColor, + DefaultForegroundColor, DefaultHoveredBackgroundColor, DefaultHoveredForegroundColor, Easing, + HighlightColor, IntrinsicPadding, OpaqueWidgetColor, OutlineColor, SurfaceColor, TextColor, }; use crate::styles::{ColorExt, Styles}; use crate::utils::ModifiersExt; @@ -69,46 +71,46 @@ impl ButtonKind { match self { ButtonKind::Solid => match visual_state { VisualState::Normal => ButtonColors { - background: context.theme().primary.color, - foreground: context.theme().primary.on_color, + background: context.get(&DefaultBackgroundColor), + foreground: context.get(&DefaultForegroundColor), outline: context.get(&ButtonOutline), }, VisualState::Hovered => ButtonColors { - background: context.theme().primary.color_bright, - foreground: context.theme().primary.on_color, + background: context.get(&DefaultHoveredBackgroundColor), + foreground: context.get(&DefaultHoveredForegroundColor), outline: context.get(&ButtonHoverOutline), }, VisualState::Active => ButtonColors { - background: context.theme().primary.color_dim, - foreground: context.theme().primary.on_color, + background: context.get(&DefaultActiveBackgroundColor), + foreground: context.get(&DefaultActiveForegroundColor), outline: context.get(&ButtonActiveOutline), }, VisualState::Disabled => ButtonColors { - background: context.theme().primary.color_dim, - foreground: context.theme().primary.on_color, + background: context.get(&DefaultDisabledBackgroundColor), + foreground: context.get(&DefaultDisabledForegroundColor), outline: context.get(&ButtonDisabledOutline), }, }, ButtonKind::Outline | ButtonKind::Transparent => match visual_state { VisualState::Normal => ButtonColors { background: context.get(&ButtonOutline), - foreground: context.theme().primary.color, - outline: context.theme().primary.color, + foreground: context.get(&DefaultBackgroundColor), + outline: context.get(&DefaultBackgroundColor), }, VisualState::Hovered => ButtonColors { background: context.get(&ButtonHoverOutline), - foreground: context.theme().primary.color, - outline: context.theme().primary.color_bright, + foreground: context.get(&DefaultHoveredBackgroundColor), + outline: context.get(&DefaultHoveredBackgroundColor), }, VisualState::Active => ButtonColors { background: context.get(&ButtonActiveOutline), - foreground: context.theme().primary.color, - outline: context.theme().surface.color, + foreground: context.get(&DefaultActiveBackgroundColor), + outline: context.get(&DefaultActiveBackgroundColor), }, VisualState::Disabled => ButtonColors { background: context.get(&ButtonDisabledOutline), - foreground: context.theme().primary.on_color, - outline: context.theme().primary.color_dim, + foreground: context.get(&DefaultDisabledBackgroundColor), + outline: context.get(&DefaultDisabledBackgroundColor), }, }, } diff --git a/src/widgets/checkbox.rs b/src/widgets/checkbox.rs index 04eb69f..000e825 100644 --- a/src/widgets/checkbox.rs +++ b/src/widgets/checkbox.rs @@ -3,8 +3,8 @@ use std::error::Error; use std::fmt::Display; use std::ops::Not; -use kludgine::figures::units::{Lp, Px}; -use kludgine::figures::{Point, Rect, ScreenScale, Size}; +use kludgine::figures::units::Lp; +use kludgine::figures::{Point, Rect, Round, ScreenScale, Size}; use kludgine::shapes::{PathBuilder, Shape, StrokeOptions}; use crate::context::{GraphicsContext, LayoutContext}; @@ -183,15 +183,19 @@ impl Widget for CheckboxOrnament { .width .min(context.gfx.region().size.height); + let stroke_options = + StrokeOptions::px_wide(Lp::points(2).into_px(context.gfx.scale()).round()); + + let half_line = stroke_options.line_width / 2; + let checkbox_rect = Rect::new( Point::new( - Px::ZERO, - (context.gfx.region().size.height - checkbox_size) / 2, + half_line, + (context.gfx.region().size.height - checkbox_size) / 2 + half_line, ), - Size::squared(checkbox_size), + Size::squared(checkbox_size - stroke_options.line_width), ); - let stroke_options = StrokeOptions::lp_wide(Lp::points(2)).into_px(context.gfx.scale()); match self.value.get_tracking_redraw(context) { state @ (CheckboxState::Checked | CheckboxState::Indeterminant) => { let color = context.get(&WidgetAccentColor);