Switch
Switch
A customizable toggle switch widget supporting animations, axis alignment, and drag actions.
Specific kwargs
| Argument |
Type |
Description |
base_state |
bool |
initial toggle state of the switch. |
axis |
SwitchAxis |
the alignment axis (Auto, Horizontal, or Vertical). |
on_switch_change |
Callable / None |
callback function triggered when state changes. |
easing_func |
Callable |
easing function used for the switch transition animation. |
animation_time / anim_time |
float |
duration of the switch transition in seconds. |
Getters
| Name |
ReturnType |
Description |
state |
bool |
current toggle state of the switch. |
bg_circle_coords |
NvVector2 |
current position of the switch circle. |
minimal_side |
float |
the smaller side dimension between height and width. |
Setters
| Name |
Kwargs |
Description |
state |
value: bool |
sets the toggle state and runs transitions. |
bg_circle_coords |
value: NvVector2 |
manually triggers movement transition for the circle. |
Use case
from nevu_ui import *
import pygame
pygame.init()
window = Window((500, 500), title = "Switch example")
menu = Menu(window, (100%vw, 100%vh))
layout = Grid([100%fillw, 100%fillh], x=3, y=3)
widget = Switch(base_state = True, size = (120, 50))
layout.add_item(widget, 2, 2)
menu.layout = layout
while True:
window.begin_frame()
window.update()
menu.update()
menu.draw()
window.end_frame()
from nevu_ui import *
import pyray
window = Window((500, 500), title = "Switch example", backend = Backend.RayLib)
menu = Menu(window, (100%vw, 100%vh))
layout = Grid([100%fillw, 100%fillh], x=3, y=3)
widget = Switch(base_state = True, size = (120, 50))
layout.add_item(widget, 2, 2)
menu.layout = layout
while True:
window.begin_frame()
window.update()
menu.update()
menu.draw()
window.end_frame()
Created with GGen v1.3.0 for nevu_ui v0.8.2