cmdfx 0.3.0
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
switch.hpp
Go to the documentation of this file.
1
11#pragma once
12
13extern "C" {
14 #include "cmdfx/ui/switch.h"
15}
16
18#include "cmdfx/ui/button.hpp"
19
20namespace CmdFX {
21
28 class Switch : public Button {
29 public:
30 Switch(CmdFX_Button* btn) : Button(btn) {}
31 Switch(Sprite& sprite, CmdFX_ButtonCallback callback, bool state = false)
32 : Button(Button_createSwitch(sprite.getSprite(), callback, state)) {}
33 Switch(std::vector<std::string>& on, std::vector<std::string>& off, std::vector<std::vector<std::string>>& ansiOn, std::vector<std::vector<std::string>>& ansiOff, CmdFX_ButtonCallback callback, bool state = false)
34 : Button(Button_createSwitchWith(to2DArray(on), to2DArray(off), to3DArray(ansiOn), to3DArray(ansiOff), callback, state)) {}
35
36 bool isOn() const {
37 return Switch_getState(getButton());
38 }
39
40 void setOn(bool state) {
41 Switch_setState(getButton(), state);
42 }
43
44 void toggle() {
45 if (isOn()) {
46 setOn(false);
47 } else {
48 setOn(true);
49 }
50 }
51 };
52
53}
C++ Extensions for the Builder API.
void(* CmdFX_ButtonCallback)(void *button, CmdFX_MouseEvent *event, unsigned long long time)
The callback function to be called when the button is clicked.
Definition button.h:33
C++ Extensions for CmdFX Button UI.
A C++ wrapper around a CmdFX_Sprite struct.
Definition sprites.hpp:32
CmdFX_Sprite * getSprite()
Get the Sprite object associated with this class.
Definition sprites.hpp:53
Primary namespace for CmdFX.
Definition cmdfx.hpp:22
char ** to2DArray(std::vector< std::string > string)
Converts a 1D vector of strings to a 2D array of characters.
Definition builder.hpp:39
char *** to3DArray(std::vector< std::vector< std::string > > string)
Converts a 2D vector of strings to a 3D array of characters.
Definition builder.hpp:55
Represents a CmdFX button.
Definition button.h:42
Switch extensions for the CmdFX Button API.
bool Switch_getState(CmdFX_Button *button)
Gets the state of the switch button.
CmdFX_Button * Button_createSwitch(CmdFX_Sprite *sprite, CmdFX_ButtonCallback callback, bool state)
Creates a switch button.
int Switch_setState(CmdFX_Button *button, bool state)
Sets the state of the switch button.
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.