Skip to content

Instantly share code, notes, and snippets.

@SqrtRyan
Created July 1, 2025 22:51
Show Gist options
  • Save SqrtRyan/004177e33131bcda66e8a78237e1c01a to your computer and use it in GitHub Desktop.
Save SqrtRyan/004177e33131bcda66e8a78237e1c01a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Additional custom components for the imgui_skia framework.
"""
from imgui_skia import Component, draw_rect, draw_text, Button
class ToggleButton(Button):
"""A button that toggles between two states with different labels."""
def __init__(self, label_off="Off", label_on="On", value=False, on_change=None, **kwargs):
super().__init__(**kwargs)
self.label_off = label_off
self.label_on = label_on
self.value = value # This will use state binding if a State object is passed
self.on_change = on_change
@property
def label(self):
"""Get the current label based on state."""
return self.label_on if self.value else self.label_off
def on_click(self):
"""Toggle the button state."""
self.value = not self.value
if self.on_change:
self.on_change(self.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment