Gama C Library
Gama C API Documentation
switch.h File Reference

Defines the theme and functionality for a toggle switch widget. More...

#include "../animate.h"
#include "../collision.h"
#include "../draw.h"

Go to the source code of this file.

Data Structures

struct  gmwSwitchTheme
 Structure defining the visual theme for a switch widget. More...

Functions

int gmw_switch_anim (double x, double y, double width, double height, int *value, double *anim)
 Creates and renders an animated switch widget that toggles on click.
int gmw_switch (double x, double y, double width, double height, int *value)
 Creates and renders a switch widget that toggles on click (non-animated version).

Variables

gmwSwitchTheme gmwSwitch
 Global switch theme instance with default values.

Detailed Description

Defines the theme and functionality for a toggle switch widget.

This file provides structures for customizing the appearance of an on-screen toggle switch and a function to render an interactive switch that allows users to toggle a boolean state.

Function Documentation

◆ gmw_switch()

int gmw_switch ( double x,
double y,
double width,
double height,
int * value )

Creates and renders a switch widget that toggles on click (non-animated version).

This is a simplified wrapper around gmw_switch_anim that does not use a separate animated visual position, causing the knob to snap to the current value.

Parameters
xThe x-coordinate of the switch's center.
yThe y-coordinate of the switch's center.
widthThe width of the switch.
heightThe height of the switch.
valuePointer to an integer to store the switch state (0=off, 1=on).
Returns
1 if the switch was clicked (toggled) in the current frame, 0 otherwise.

◆ gmw_switch_anim()

int gmw_switch_anim ( double x,
double y,
double width,
double height,
int * value,
double * anim )

Creates and renders an animated switch widget that toggles on click.

This function draws a toggle switch, tracks mouse interaction to update its state, and animates the knob's position smoothly between 'off' (0) and 'on' (1).

Parameters
xThe x-coordinate of the switch's center.
yThe y-coordinate of the switch's center.
widthThe width of the switch.
heightThe height of the switch.
valuePointer to an integer to store the switch state (0 for off, 1 for on). This value is toggled by user clicks.
animPointer to a double for the animated visual position of the knob. If NULL, value is used for the knob's position (non-animated).
Returns
1 if the switch was clicked (toggled) in the current frame, 0 otherwise.

Variable Documentation

◆ gmwSwitch

gmwSwitchTheme gmwSwitch

Global switch theme instance with default values.