]> git.mar77i.info Git - zenbook_conf/commitdiff
add an iconify button
authormar77i <mar77i@protonmail.ch>
Thu, 26 Dec 2024 19:48:11 +0000 (20:48 +0100)
committermar77i <mar77i@protonmail.ch>
Thu, 26 Dec 2024 19:48:11 +0000 (20:48 +0100)
ui.py
zenbook_conf.py

diff --git a/ui.py b/ui.py
index 6a3715dda5ba0eb48e1fd5c096354e4194a8c097..5f8f2084494704ce4bfd9f28594852d1d364d9b2 100644 (file)
--- 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
index 56a262be182d3510b09a48e7d299f45145b0447c..5900dfec44b1afd2eb73648fbd14c5a4870d6634 100755 (executable)
@@ -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()