cmdfx 0.3.2
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{
22
30class Switch : public Button {
31 public:
32 Switch(CmdFX_Button* btn) : Button(btn) {
33 }
34 Switch(Sprite& sprite, CmdFX_ButtonCallback callback, bool state = false)
35 : Button(Button_createSwitch(sprite.getSprite(), callback, state)) {
36 }
37 Switch(
38 std::vector<std::string>& on, std::vector<std::string>& off,
39 std::vector<std::vector<std::string>>& ansiOn,
40 std::vector<std::vector<std::string>>& ansiOff,
41 CmdFX_ButtonCallback callback, bool state = false
42 )
44 to2DArray(on), to2DArray(off), to3DArray(ansiOn),
45 to3DArray(ansiOff), callback, state
46 )) {
47 }
48
49 bool isOn() const {
50 return Switch_getState(getButton());
51 }
52
53 void setOn(bool state) {
54 Switch_setState(getButton(), state);
55 }
56
57 void toggle() {
58 if (isOn()) {
59 setOn(false);
60 }
61 else {
62 setOn(true);
63 }
64 }
65};
66
67} // namespace CmdFX
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:33
CmdFX_Sprite * getSprite()
Get the Sprite object associated with this class.
Definition sprites.hpp:60
Primary namespace for CmdFX.
Definition cmdfx.hpp:26
char ** to2DArray(std::vector< std::string > string)
Converts a 1D vector of strings to a 2D array of characters.
Definition builder.hpp:64
char *** to3DArray(std::vector< std::vector< std::string > > string)
Converts a 2D vector of strings to a 3D array of characters.
Definition builder.hpp:80
Represents a CmdFX button.
Definition button.h:45
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.