Skip to content

Commit 1e2805a

Browse files
committed
refactor: simplify static color logic
1 parent e3b6d4b commit 1e2805a

2 files changed

Lines changed: 20 additions & 25 deletions

File tree

src/kde_material_you_colors/utils/color_utils.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,31 +363,28 @@ def argbFromHex(hex):
363363
)
364364

365365

366-
def static_color(scheme: DynamicScheme, color, blend=True) -> dict:
366+
def static_color(scheme: DynamicScheme, argb: int, blend=True) -> dict:
367367
"""_summary_
368368
369369
Args:
370370
scheme (DynamicScheme): DynamicScheme to use as source
371-
color (int): color to generate static version of
372-
blend (bool, optional): Whether to blend the color with the scheme's source color. Defaults to True.
371+
argb (int): argb value of the color to generate static version of
372+
blend (bool, optional): Whether to blend the color towards the source color. Defaults to True.
373373
374374
Returns:
375375
dict: Static color roles for the given color in hex format
376376
"""
377-
md = MaterialDynamicColors()
378377
if blend:
379-
color = Blend.harmonize(color, scheme.source_color_argb)
380-
hct = Hct.from_int(color)
381-
palette = TonalPalette.from_hue_and_chroma(hct.hue, hct.chroma)
378+
argb = Blend.harmonize(argb, scheme.source_color_argb)
382379

383-
scheme2 = copy.copy(scheme)
384-
scheme2.error_palette = palette
380+
scheme.error_palette = TonalPalette.from_int(argb)
381+
mdc = MaterialDynamicColors()
385382

386383
return {
387-
"color": md.error.get_hex(scheme2)[:-2],
388-
"onColor": md.onError.get_hex(scheme2)[:-2],
389-
"container": md.errorContainer.get_hex(scheme2)[:-2],
390-
"onContainer": md.onErrorContainer.get_hex(scheme2)[:-2],
384+
"color": mdc.error.get_hex(scheme)[:-2],
385+
"onColor": mdc.onError.get_hex(scheme)[:-2],
386+
"container": mdc.errorContainer.get_hex(scheme)[:-2],
387+
"onContainer": mdc.onErrorContainer.get_hex(scheme)[:-2],
391388
}
392389

393390

src/kde_material_you_colors/utils/m3_scheme_utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from materialyoucolor.scheme.scheme_monochrome import SchemeMonochrome
1212
from materialyoucolor.scheme import *
1313
from materialyoucolor.palettes.tonal_palette import TonalPalette
14-
from materialyoucolor.dislike.dislike_analyzer import DislikeAnalyzer
15-
from materialyoucolor.blend import Blend
1614
from materialyoucolor.dynamiccolor.dynamic_color import DynamicColor
1715
from kde_material_you_colors.config import Configs
1816
from kde_material_you_colors.utils.color_utils import rgb2hex
@@ -96,22 +94,22 @@ def themeFromSourceColor(
9694
colorsDark = getColors(schemeDark, chroma_mult, tone_mult, True)
9795
# Base text states taken from Breeze Color Scheme
9896
base_text_states = [
99-
{"name": "link", "value": argbFromHex("#2980b9"), "blend": True},
100-
{"name": "visited", "value": argbFromHex("#9b59b6"), "blend": True},
101-
{"name": "negative", "value": argbFromHex("#da4453"), "blend": True},
102-
{"name": "neutral", "value": argbFromHex("#f67400"), "blend": True},
103-
{"name": "positive", "value": argbFromHex("#27ae60"), "blend": True},
97+
{"name": "link", "value": 4280910009, "hex": "#2980b9"},
98+
{"name": "visited", "value": 4288371126, "hex": "#9b59b6"},
99+
{"name": "negative", "value": 4292494419, "hex": "#da4453"},
100+
{"name": "neutral", "value": 4294341632, "hex": "#f67400"},
101+
{"name": "positive", "value": 4280790624, "hex": "#27ae60"},
104102
]
105103

106104
cc = {}
105+
seed_color_hex = hexFromArgb(seed_color)
107106

108107
for color in base_text_states:
109108
cc[color["name"]] = {
110-
"source": hexFromArgb(seed_color),
111-
"value": hexFromArgb(color["value"]),
112-
"blend": color["blend"],
113-
"light": static_color(scheme, color["value"], color["blend"]),
114-
"dark": static_color(schemeDark, color["value"], color["blend"]),
109+
"source": seed_color_hex,
110+
"value": color["hex"],
111+
"light": static_color(scheme, color["value"], True),
112+
"dark": static_color(schemeDark, color["value"], True),
115113
}
116114

117115
out = {

0 commit comments

Comments
 (0)