alpha=255 not 256
This commit is contained in:
parent
46ecf1f19d
commit
f98845d019
@ -37,8 +37,8 @@ class BaseTheme:
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
main_color: RGBA = (39, 73, 114, 256),
|
||||
secondary_color: RGBA = (66, 150, 250, 256),
|
||||
main_color: RGBA = (39, 73, 114, 255),
|
||||
secondary_color: RGBA = (66, 150, 250, 255),
|
||||
main_font: str = Fonts.鸿蒙简体,
|
||||
):
|
||||
self.main_color = main_color
|
||||
@ -54,8 +54,8 @@ class FontTheme(BaseTheme):
|
||||
字体的主题
|
||||
"""
|
||||
def __init__(self,
|
||||
main_color: RGBA = (39, 73, 114, 256),
|
||||
secondary_color: RGBA = (66, 150, 250, 256),
|
||||
main_color: RGBA = (39, 73, 114, 255),
|
||||
secondary_color: RGBA = (66, 150, 250, 255),
|
||||
main_font: str = Fonts.鸿蒙简体,
|
||||
font_size: Optional[int] = 15,
|
||||
font_bold: Optional[bool] = False,
|
||||
@ -80,9 +80,9 @@ class ButtonTheme(BaseTheme):
|
||||
Button 的主题
|
||||
"""
|
||||
def __init__(self,
|
||||
main_color: RGBA = (39, 73, 114, 256),
|
||||
secondary_color: RGBA = (66, 150, 250, 256),
|
||||
hit_color: RGBA = (15, 135, 250, 256),
|
||||
main_color: RGBA = (39, 73, 114, 255),
|
||||
secondary_color: RGBA = (66, 150, 250, 255),
|
||||
hit_color: RGBA = (15, 135, 250, 255),
|
||||
main_font: str = Fonts.鸿蒙简体,
|
||||
font_theme: Optional[FontTheme] = None,
|
||||
):
|
||||
@ -107,42 +107,38 @@ class PressTextButton(widgets.WidgetBase):
|
||||
width: int,
|
||||
height: int,
|
||||
text: str,
|
||||
font_theme: Optional[FontTheme] = None,
|
||||
batch: Optional[Batch] = None,
|
||||
group: Optional[Group] = None,
|
||||
theme: Optional[ButtonTheme] = None,
|
||||
):
|
||||
super().__init__(x, y, width, height)
|
||||
self.back_ground_batch = batch or Batch()
|
||||
self.front_batch = batch or Batch()
|
||||
self.main_batch = batch or Batch()
|
||||
self.front_group = Group(order=10, parent=group)
|
||||
self.back_ground_group = Group(order=5, parent=group)
|
||||
self.pressed = False
|
||||
|
||||
self.theme = theme or ButtonTheme()
|
||||
self.font_theme = font_theme or FontTheme()
|
||||
|
||||
print(self.theme)
|
||||
self.untouched_color = self.theme.main_color
|
||||
self.touched_color = self.theme.secondary_color
|
||||
self.hit_color = self.theme.hit_color
|
||||
# from ImGui
|
||||
|
||||
self.text = text
|
||||
self.text_label = Label(font_name=self.font_theme.main_font, font_size=self.font_theme.font_size,
|
||||
batch=self.front_batch, group=self.front_group,
|
||||
self.text_label = Label(font_name=self.theme.font_theme.main_font, font_size=self.theme.font_theme.font_size,
|
||||
batch=self.main_batch, group=self.front_group,
|
||||
x=self._x, y=self._y, width=self._width,
|
||||
height=self._height,)
|
||||
self.font = pyglet.font.load(self.font_theme.main_font,
|
||||
self.font_theme.font_size,
|
||||
bold=self.font_theme.font_bold,
|
||||
italic=self.font_theme.font_italic,
|
||||
stretch=self.font_theme.font_stretch)
|
||||
self.font = pyglet.font.load(self.theme.font_theme.main_font,
|
||||
self.theme.font_theme.font_size,
|
||||
bold=self.theme.font_theme.font_bold,
|
||||
italic=self.theme.font_theme.font_italic,
|
||||
stretch=self.theme.font_theme.font_stretch)
|
||||
self.font_height = self.font.ascent - self.font.descent
|
||||
self.back_rec = Rectangle(x=self._x, y=self._y,
|
||||
width=self._width, height=self._height,
|
||||
color=self.untouched_color, # ImGui color
|
||||
batch=self.back_ground_batch, group=self.back_ground_group)
|
||||
batch=self.main_batch, group=self.back_ground_group)
|
||||
|
||||
self.value = text # 重新分配一下高度和宽度的位置
|
||||
|
||||
@ -164,7 +160,6 @@ class PressTextButton(widgets.WidgetBase):
|
||||
def on_mouse_motion(self, x, y, dx, dy):
|
||||
if (x, y) in self.back_rec:
|
||||
self.back_rec.color = self.touched_color
|
||||
print(self.back_rec.color)
|
||||
else:
|
||||
self.pressed = False
|
||||
self.back_rec.color = self.untouched_color
|
||||
|
Loading…
Reference in New Issue
Block a user