cmdfx 0.2.1
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
switch.h File Reference

Switch extensions for the CmdFX Button API. More...

#include <stdbool.h>
#include "cmdfx/ui/button.h"

Go to the source code of this file.

Macros

#define CMDFX_BUTTON_TYPE_SWITCH   1
 Represents a CmdFX switch button.
 

Functions

CmdFX_ButtonButton_createSwitch (CmdFX_Sprite *sprite, CmdFX_ButtonCallback callback, bool state)
 Creates a switch button.
 
CmdFX_ButtonButton_createSwitchWith (char **on, char **off, char ***ansiOn, char ***ansiOff, CmdFX_ButtonCallback callback, bool state)
 Creates a switch button with the given on and off states.
 
bool Switch_getState (CmdFX_Button *button)
 Gets the state of the switch button.
 
int Switch_setState (CmdFX_Button *button, bool state)
 Sets the state of the switch button.
 
int Switch_toggleState (CmdFX_Button *button)
 Toggles the state of the switch button.
 

Detailed Description

Switch extensions for the CmdFX Button API.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.2.0
Date
2025-04-17

Macro Definition Documentation

◆ CMDFX_BUTTON_TYPE_SWITCH

#define CMDFX_BUTTON_TYPE_SWITCH   1

Represents a CmdFX switch button.

Switch buttons are a type of button that can be toggled on and off. They also can change costumes based on their state. Their extra field is a pointer to a boolean that indicates the state of the switch.

Function Documentation

◆ Button_createSwitch()

CmdFX_Button * Button_createSwitch ( CmdFX_Sprite * sprite,
CmdFX_ButtonCallback callback,
bool state )

Creates a switch button.

This function creates a switch button with the given sprite and callback function.

Parameters
sprite
callback
state
Returns
CmdFX_Button*

◆ Button_createSwitchWith()

CmdFX_Button * Button_createSwitchWith ( char ** on,
char ** off,
char *** ansiOn,
char *** ansiOff,
CmdFX_ButtonCallback callback,
bool state )

Creates a switch button with the given on and off states.

This function creates a switch button with the given on and off states. The button will be created with the given sprite and callback function.

Parameters
onThe string to display when the button is on.
offThe string to display when the button is off.
ansiOnThe ANSI codes to use when the button is on.
ansiOffThe ANSI codes to use when the button is off.
callbackThe callback function to call when the button is clicked.
stateThe initial state of the button (0 = off, 1 = on).
Returns
CmdFX_Button* A pointer to the newly created switch button.

◆ Switch_getState()

bool Switch_getState ( CmdFX_Button * button)

Gets the state of the switch button.

This function gets the state of the switch button. The state is stored in the extra field of the button, which is a pointer to a boolean.

Parameters
buttonThe button to get the state of.
Returns
bool The state of the switch button (0 = off, 1 = on).

◆ Switch_setState()

int Switch_setState ( CmdFX_Button * button,
bool state )

Sets the state of the switch button.

This function sets the state of the switch button. The state is stored in the extra field of the button, which is a pointer to a boolean.

Parameters
buttonThe button to set the state of.
stateThe new state of the switch button (0 = off, 1 = on).
Returns
int 0 if successful, -1 if an error occurred.

◆ Switch_toggleState()

int Switch_toggleState ( CmdFX_Button * button)

Toggles the state of the switch button.

This function toggles the state of the switch button. The state is stored in the extra field of the button, which is a pointer to a boolean.

Parameters
buttonThe button to toggle the state of.
Returns
int 0 if successful, -1 if an error occurred.