Skip to content

Commit 0661801

Browse files
committed
#1106 Add the class method to get an on_primary color setting from setting.
1 parent 5fa5c44 commit 0661801

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

apysc/_material_design/setting/material_settings_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,27 @@ def get_primary_color(cls, *, argument_color: Optional[Color]) -> Color:
162162
color_name="primary",
163163
argument_color=argument_color,
164164
)
165+
166+
@classmethod
167+
def get_on_primary_color(cls, *, argument_color: Optional[Color]) -> Color:
168+
"""
169+
Get an `on_primary` color setting from setting.
170+
171+
Parameters
172+
----------
173+
argument_color : Optional[Color]
174+
A specified argument color.
175+
176+
Returns
177+
-------
178+
target_color : Color
179+
A target on-primary color.
180+
This value becomes according to the following priorities:
181+
1. If the `argument_color` is not the `None`
182+
2. If a color scheme is set in the `MaterialSettings`
183+
3. A fixed color value.
184+
"""
185+
return cls._get_target_color_and_add_expressions_by_color_name(
186+
color_name="on_primary",
187+
argument_color=argument_color,
188+
)

tests/_material_design/setting/test_material_settings_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ def test_get_primary_color(self) -> None:
6262
argument_color=None
6363
)
6464
assert target_color == ap.MaterialSettingsUtils._fixed_color_scheme.primary
65+
66+
@apply_test_settings()
67+
def test_get_on_primary_color(self) -> None:
68+
target_color: ap.Color = ap.MaterialSettingsUtils.get_on_primary_color(
69+
argument_color=None
70+
)
71+
assert target_color == ap.MaterialSettingsUtils._fixed_color_scheme.on_primary

0 commit comments

Comments
 (0)