Skip to content

Commit

Permalink
Muted color variations
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Nov 5, 2024
1 parent 365b758 commit affbdc1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
43 changes: 40 additions & 3 deletions examples/theme_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ChangingThemeApp(App[None]):
ColorSample {
width: 1fr;
color: $text;
padding: 0 1;
&.hover-surface {
&:hover {
background: $surface;
Expand Down Expand Up @@ -162,6 +163,30 @@ class ChangingThemeApp(App[None]):
&.text-disabled {
color: $text-disabled;
}
&.primary-muted {
color: $text-primary;
background: $primary-muted;
}
&.secondary-muted {
color: $text-secondary;
background: $secondary-muted;
}
&.accent-muted {
color: $text-accent;
background: $accent-muted;
}
&.warning-muted {
color: $text-warning;
background: $warning-muted;
}
&.error-muted {
color: $text-error;
background: $error-muted;
}
&.success-muted {
color: $text-success;
background: $success-muted;
}
}
ListView {
height: auto;
Expand Down Expand Up @@ -280,7 +305,6 @@ def compose(self) -> ComposeResult:
self.title = "Theme Sandbox"
with Grid(id="palette"):
theme = self.current_theme
color_system = theme.to_color_system()
for variable, value in vars(theme).items():
if variable not in {
"name",
Expand All @@ -291,19 +315,32 @@ def compose(self) -> ComposeResult:
}:
yield ColorSample(f"{variable}", classes=variable)
for color_name in [
"muted",
"primary",
"secondary",
"accent",
"warning",
"error",
"success",
"muted",
]:
yield ColorSample(
f"text-{color_name}",
f"text-{color_name} on background",
classes=f"text-{color_name} background hover-surface",
)

for color_name in [
"primary",
"secondary",
"accent",
"warning",
"error",
"success",
]:
yield ColorSample(
f"text-{color_name} on {color_name}-muted",
classes=f"text-{color_name} {color_name}-muted",
)

yield Header(show_clock=True, icon="🐟")
yield ThemeList(id="theme-list")
with VerticalScroll(id="widget-list") as container:
Expand Down
10 changes: 10 additions & 0 deletions src/textual/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ def luminosity_range(spread: float) -> Iterable[tuple[str, float]]:
colors["text-muted"] = "ansi_default"
colors["text-disabled"] = "ansi_default"

# Muted variants of base colors
colors["primary-muted"] = get("primary-muted", primary.with_alpha(0.3).hex)
colors["secondary-muted"] = get(
"secondary-muted", secondary.with_alpha(0.3).hex
)
colors["accent-muted"] = get("accent-muted", accent.with_alpha(0.3).hex)
colors["warning-muted"] = get("warning-muted", warning.with_alpha(0.3).hex)
colors["error-muted"] = get("error-muted", error.with_alpha(0.3).hex)
colors["success-muted"] = get("success-muted", success.with_alpha(0.3).hex)

# Foreground colors
colors["foreground-muted"] = get(
"foreground-muted", foreground.with_alpha(0.6).hex
Expand Down

0 comments on commit affbdc1

Please sign in to comment.