diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/windowing/StarButtonGroup.hpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/windowing/StarButtonGroup.hpp')
-rw-r--r-- | source/windowing/StarButtonGroup.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/source/windowing/StarButtonGroup.hpp b/source/windowing/StarButtonGroup.hpp new file mode 100644 index 0000000..07bd135 --- /dev/null +++ b/source/windowing/StarButtonGroup.hpp @@ -0,0 +1,59 @@ +#ifndef STAR_BUTTON_GROUP_HPP +#define STAR_BUTTON_GROUP_HPP + +#include "StarWidget.hpp" + +namespace Star { + +STAR_CLASS(ButtonWidget); +STAR_CLASS(ButtonGroup); +STAR_CLASS(ButtonGroupWidget); + +// Manages group of buttons in which *at most* a single button can be checked +// at any time. +class ButtonGroup { +public: + friend class ButtonWidget; + + static int const NoButton = -1; + + // Callback is called when any child buttons checked state is changed, and + // its parameter is the button being checked. + void setCallback(WidgetCallbackFunc callback); + + ButtonWidget* button(int id) const; + List<ButtonWidget*> buttons() const; + size_t buttonCount() const; + + int addButton(ButtonWidget* button, int id = NoButton); + void removeButton(ButtonWidget* button); + + int id(ButtonWidget* button) const; + + void select(int id); + + // Will return null if no button is checked. + ButtonWidget* checkedButton() const; + // Will return NoButton if no button is checked. + int checkedId() const; + + // when true it is not required for one of the buttons to be selected + bool toggle() const; + void setToggle(bool toggleMode); + +protected: + // Should be called by child button widgets when they are changed from + // unchecked to checked. + void wasChecked(ButtonWidget* self); + +private: + WidgetCallbackFunc m_callback; + Map<int, ButtonWidget*> m_buttons; + Map<ButtonWidget*, int> m_buttonIds; + bool m_toggle; +}; + +class ButtonGroupWidget : public ButtonGroup, public Widget {}; +} + +#endif |