Skip to content

Commit

Permalink
Merge pull request #131 from r37r05p3C7/style-fixes
Browse files Browse the repository at this point in the history
Minor style fixes
  • Loading branch information
Willy-JL authored Feb 24, 2024
2 parents 2bca3ae + f92c2d2 commit bf13da8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def rgba_0_1_to_hex(rgba: tuple[int, int, int, int | None]):
return f"#{r}{g}{b}{a}"


# credit: https://stackoverflow.com/a/1855903
@functools.cache
def foreground_color(bg: tuple[float, float, float, float | None]):
# calculcates 'perceptive luminance'
luma = 0.299 * bg[0] + 0.587 * bg[1] + 0.114 * bg[2]
return (0.04, 0.04, 0.04, 1.0) if luma > 0.5 else (1.0, 1.0, 1.0, 1.0)
gamma = 2.2
# https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
luma = 0.2126 * pow(bg[0], gamma) + 0.7152 * pow(bg[1], gamma) + 0.0722 * pow(bg[2], gamma)
return (0.04, 0.04, 0.04, 1.0) if luma > pow(0.5, gamma) else (1.0, 1.0, 1.0, 1.0)
2 changes: 2 additions & 0 deletions modules/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ def get_type_label_width(self):
def draw_type_widget(self, type: Type, wide=True, align=False):
quick_filter = globals.settings.quick_filters
self.begin_framed_text(type.color, interaction=quick_filter)
imgui.push_style_color(imgui.COLOR_TEXT, 1.0, 1.0, 1.0, 1.0)
if wide:
x_padding = 4
backup_y_padding = imgui.style.frame_padding.y
Expand All @@ -1094,6 +1095,7 @@ def draw_type_widget(self, type: Type, wide=True, align=False):
flt = Filter(FilterMode.Type)
flt.match = type
self.filters.append(flt)
imgui.pop_style_color()
self.end_framed_text(interaction=quick_filter)

def draw_tag_widget(self, tag: Tag, quick_filter=True, change_highlight=True):
Expand Down

0 comments on commit bf13da8

Please sign in to comment.