mirror of
https://github.com/danbulant/cushy
synced 2026-06-24 17:12:11 +00:00
Refactored LabelBackground to WidgetBackground
This commit is contained in:
parent
81f6f8c4d3
commit
d844a44b33
4 changed files with 28 additions and 32 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
use gooey::styles::components::TextColor;
|
use gooey::styles::components::{TextColor, WidgetBackground};
|
||||||
use gooey::styles::{ColorSource, ColorTheme, FixedTheme, SurfaceTheme, Theme, ThemePair};
|
use gooey::styles::{ColorSource, ColorTheme, FixedTheme, SurfaceTheme, Theme, ThemePair};
|
||||||
use gooey::value::{Dynamic, MapEach};
|
use gooey::value::{Dynamic, MapEach};
|
||||||
use gooey::widget::MakeWidget;
|
use gooey::widget::MakeWidget;
|
||||||
use gooey::widgets::label::LabelBackground;
|
|
||||||
use gooey::widgets::{Input, Label, Stack};
|
use gooey::widgets::{Input, Label, Stack};
|
||||||
use gooey::Run;
|
use gooey::Run;
|
||||||
use kludgine::Color;
|
use kludgine::Color;
|
||||||
|
|
@ -250,9 +249,9 @@ fn color_theme(theme: Dynamic<ColorTheme>, label: &str) -> impl MakeWidget {
|
||||||
|
|
||||||
fn swatch(background: Dynamic<Color>, label: &str, text: Dynamic<Color>) -> impl MakeWidget {
|
fn swatch(background: Dynamic<Color>, label: &str, text: Dynamic<Color>) -> impl MakeWidget {
|
||||||
Label::new(label)
|
Label::new(label)
|
||||||
|
.with(&TextColor, text)
|
||||||
|
.with(&WidgetBackground, background)
|
||||||
.fit_horizontally()
|
.fit_horizontally()
|
||||||
.fit_vertically()
|
.fit_vertically()
|
||||||
.with(&TextColor, text)
|
|
||||||
.with(&LabelBackground, background)
|
|
||||||
.expand()
|
.expand()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use kludgine::shapes::{Shape, StrokeOptions};
|
||||||
use kludgine::Kludgine;
|
use kludgine::Kludgine;
|
||||||
|
|
||||||
use crate::graphics::Graphics;
|
use crate::graphics::Graphics;
|
||||||
use crate::styles::components::{HighlightColor, VisualOrder};
|
use crate::styles::components::{HighlightColor, VisualOrder, WidgetBackground};
|
||||||
use crate::styles::{ComponentDefaultvalue, ComponentDefinition, Styles, Theme, ThemePair};
|
use crate::styles::{ComponentDefaultvalue, ComponentDefinition, Styles, Theme, ThemePair};
|
||||||
use crate::value::Dynamic;
|
use crate::value::Dynamic;
|
||||||
use crate::widget::{EventHandling, ManagedWidget, WidgetId, WidgetInstance, WidgetRef};
|
use crate::widget::{EventHandling, ManagedWidget, WidgetId, WidgetInstance, WidgetRef};
|
||||||
|
|
@ -488,6 +488,9 @@ impl<'context, 'window, 'clip, 'gfx, 'pass> GraphicsContext<'context, 'window, '
|
||||||
"redraw called without set_widget_layout"
|
"redraw called without set_widget_layout"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let background = self.query_style(&WidgetBackground);
|
||||||
|
self.gfx.fill(background);
|
||||||
|
|
||||||
self.current_node
|
self.current_node
|
||||||
.tree
|
.tree
|
||||||
.note_widget_rendered(self.current_node.id());
|
.note_widget_rendered(self.current_node.id());
|
||||||
|
|
|
||||||
|
|
@ -376,3 +376,21 @@ impl FocusableWidgets {
|
||||||
matches!(self, Self::OnlyTextual)
|
matches!(self, Self::OnlyTextual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [`Color`] to be used as a highlight color.
|
||||||
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||||
|
pub struct WidgetBackground;
|
||||||
|
|
||||||
|
impl NamedComponent for WidgetBackground {
|
||||||
|
fn name(&self) -> Cow<'_, ComponentName> {
|
||||||
|
Cow::Owned(ComponentName::named::<Global>("widget_background_color"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ComponentDefinition for WidgetBackground {
|
||||||
|
type ComponentType = Color;
|
||||||
|
|
||||||
|
fn default_value(&self, _context: &WidgetContext<'_, '_>) -> Color {
|
||||||
|
Color::CLEAR_WHITE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
//! A read-only text widget.
|
//! A read-only text widget.
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use kludgine::figures::units::{Px, UPx};
|
use kludgine::figures::units::{Px, UPx};
|
||||||
use kludgine::figures::{IntoUnsigned, Point, ScreenScale, Size};
|
use kludgine::figures::{IntoUnsigned, Point, ScreenScale, Size};
|
||||||
use kludgine::text::{MeasuredText, Text, TextOrigin};
|
use kludgine::text::{MeasuredText, Text, TextOrigin};
|
||||||
use kludgine::Color;
|
|
||||||
|
|
||||||
use crate::context::{GraphicsContext, LayoutContext, WidgetContext};
|
use crate::context::{GraphicsContext, LayoutContext};
|
||||||
use crate::styles::components::{IntrinsicPadding, TextColor};
|
use crate::styles::components::{IntrinsicPadding, TextColor};
|
||||||
use crate::styles::{ComponentDefinition, ComponentGroup, ComponentName, NamedComponent};
|
use crate::styles::ComponentGroup;
|
||||||
use crate::value::{IntoValue, Value};
|
use crate::value::{IntoValue, Value};
|
||||||
use crate::widget::Widget;
|
use crate::widget::Widget;
|
||||||
use crate::{ConstraintLimit, Name};
|
use crate::{ConstraintLimit, Name};
|
||||||
|
|
@ -37,17 +35,13 @@ impl Widget for Label {
|
||||||
|
|
||||||
let size = context.gfx.region().size;
|
let size = context.gfx.region().size;
|
||||||
let center = Point::from(size) / 2;
|
let center = Point::from(size) / 2;
|
||||||
let styles = context.query_styles(&[&TextColor, &LabelBackground]);
|
|
||||||
|
|
||||||
let background = styles.get(&LabelBackground, context);
|
|
||||||
context.gfx.fill(background);
|
|
||||||
|
|
||||||
if let Some(measured) = &self.prepared_text {
|
if let Some(measured) = &self.prepared_text {
|
||||||
context
|
context
|
||||||
.gfx
|
.gfx
|
||||||
.draw_measured_text(measured, TextOrigin::Center, center, None, None);
|
.draw_measured_text(measured, TextOrigin::Center, center, None, None);
|
||||||
} else {
|
} else {
|
||||||
let text_color = styles.get(&TextColor, context);
|
let text_color = context.query_style(&TextColor);
|
||||||
self.text.map(|contents| {
|
self.text.map(|contents| {
|
||||||
context.gfx.draw_text(
|
context.gfx.draw_text(
|
||||||
Text::new(contents, text_color)
|
Text::new(contents, text_color)
|
||||||
|
|
@ -90,21 +84,3 @@ impl ComponentGroup for Label {
|
||||||
Name::new("Label")
|
Name::new("Label")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Color`] to be used as a highlight color.
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
|
||||||
pub struct LabelBackground;
|
|
||||||
|
|
||||||
impl NamedComponent for LabelBackground {
|
|
||||||
fn name(&self) -> Cow<'_, ComponentName> {
|
|
||||||
Cow::Owned(ComponentName::named::<Label>("background_color"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComponentDefinition for LabelBackground {
|
|
||||||
type ComponentType = Color;
|
|
||||||
|
|
||||||
fn default_value(&self, _context: &WidgetContext<'_, '_>) -> Color {
|
|
||||||
Color::CLEAR_WHITE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue