From 4cd8be8f4cf10c512d45c54028d608e48f8a64f2 Mon Sep 17 00:00:00 2001 From: mar77i Date: Thu, 26 Dec 2024 20:48:11 +0100 Subject: [PATCH] add an iconify button --- ui.py | 9 ++++++--- zenbook_conf.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ui.py b/ui.py index 6a3715d..5f8f208 100644 --- a/ui.py +++ b/ui.py @@ -190,14 +190,17 @@ class Button(UIChild): self.pushed = False self.callback = callback + def render_label(self, color): + return self.parent.font.render(self.label, True, color) + def draw(self): if not self.pushed: - frame_color = "gray" - fs = self.parent.font.render(self.label, True, "gray") + frame_color = label_color = "gray" else: pygame.draw.rect(self.parent.surf, "darkgray", self.rect) frame_color = "lightgray" - fs = self.parent.font.render(self.label, True, "black") + label_color = "black" + fs = self.render_label(label_color) pygame.draw.rect(self.parent.surf, frame_color, self.rect, 8) fs_size = fs.get_size() center = self.rect.center diff --git a/zenbook_conf.py b/zenbook_conf.py index 56a262b..5900dfe 100755 --- a/zenbook_conf.py +++ b/zenbook_conf.py @@ -18,6 +18,26 @@ from xinput import XinputConf from xrandr import XrandrConf +class IconifyButton(Button): + """ + Place an underscore in a 64 pixel high button where it's visible + With the 96 size font, underscores kind of fall out of the visible area + """ + + def render_label(self, color): + fs = super().render_label(color) + fs_rect = fs.get_rect() + y_offset = 28 + fs = fs.subsurface( + pygame.Rect( + (fs_rect.left, fs_rect.top + y_offset), + (fs_rect.width, fs_rect.height - y_offset), + ) + ) + return fs + + + class ZenbookConf(FPSMixin, UIParent): BACKGROUND_COLOR = 0x333333 @@ -128,6 +148,12 @@ class ZenbookConf(FPSMixin, UIParent): "×", self.quit, ), + IconifyButton( + self, + pygame.Rect((window_size[0] - 256, 0), (128, 64)), + "_", + self.iconify, + ), ) ) @@ -158,6 +184,9 @@ class ZenbookConf(FPSMixin, UIParent): def quit(self): self.running = False + def iconify(self): + pygame.display.iconify() + if __name__ == "__main__": ZenbookConf().run() -- 2.47.1