Description: The UI Widget system provides a flexible and extensible framework for building graphical user interfaces inside games and applications. It includes base components, styling support, interaction handling, and layout-friendly design.
Description: Defines visual styling for widgets including colors, fonts, borders, and padding.
style = Style(
bg_color=(40,40,40),
hover_color=(60,60,60),
pressed_color=(20,20,20)
)
bg_color (tuple): Background colorhover_color (tuple): Color when hoveredpressed_color (tuple): Color when pressedborder_color (tuple): Border colortext_color (tuple): Text colorborder_width (int): Border thicknesspadding (int): Inner spacingfont_size (int): Font sizeA style configuration object used by widgets for rendering.
Description: Base class for all UI elements providing positioning, visibility, and interaction state.
class CustomWidget(Widget):
def draw(self, surface):
pygame.draw.rect(surface, (255,0,0), self.rect)
x (int): X positiony (int): Y positionwidth (int): Widthheight (int): Heightstyle (Style): Visual stylingvisible (bool): Visibility flagenabled (bool): Interaction flagA base widget object ready to be extended.
Description: Interactive clickable widget supporting hover, press, toggle state, and callbacks.
def on_click():
print("Clicked!")
btn = Button("Play", 300, 200, on_click=on_click)
text (str): Button labelx, y (int): Positionwidth, height (int): Sizeon_click (callable): Function called on clickstyle (Style): Visual styleA fully interactive button widget.
enabled=FalseDescription: Horizontal slider widget allowing users to select a numeric value within a range.
def on_change(val):
print(val)
slider = Slider(250, 300, min_val=0, max_val=100, on_change=on_change)
x, y (int): Positionwidth (int): Slider widthmin_val (float): Minimum valuemax_val (float): Maximum valuestart_val (float): Initial valuestyle (Style): Visual styleon_change (callable): Change callbackA slider widget with draggable control.
Description:It's a drawable card widget that houses other widgets
from VertexEngine import GameEngine, Scene
from VertexEngine.VertexWidgets.PygameVWidgets import *
from VertexEngine.Vertex import App
class Main(Scene):
def __init__(self, engine):
super().__init__(engine)
self.ui = UIManager()
self.styleBase = Style(bg_color=(255, 0, 0), pressed_color=(125,0,0))
self.button = Button(100, 75, 200, 50, "Example", lambda: self.respond(), self.styleBase)
# TIP: val is the DATA collected from the position of the slider handle based on how far it is to the right.
# You don't need to define val, you can name it anything, but val is reccomended
self.slider = Slider(200, 50, 400, 20, 0, 100, 50, lambda val: self.printIt(val))
self.card = Card(200, 200, 400, 300)
self.card.add_child(self.button)
self.ui.add(self.card)
self.ui.add(self.slider)
def printIt(self, val):
# print an INTEGER format of value
print(int(val))
def respond(self):
print("respond")
def draw(self, surface):
self.ui.draw(surface)
def update(self):
self.ui.update()
def handle_event(self, event):
self.ui.handle_event(event)
if __name__ == "__main__":
app = App()
engine = GameEngine(color=(0,0,0))
engine.setWindowTitle("Example")
engine.show()
engine.scene_manager.set_scene(Main(engine))
app.run()
Description: Central manager responsible for updating, drawing, and dispatching events to all widgets.
self.ui = UIManager()
self.ui.add(self.button)
self.ui.add(self.slider)
add(widget): Add widgetremove(widget): Remove widgethandle_event(event): Send input eventsupdate(): Update widgetsdraw(surface): Render widgetsA manager instance controlling all UI components.