class ffw::GuiRadio
Class List > ffw :: GuiRadio
Create a radio widgets. More...
Inherits the following classes: ffw::GuiWidget
Classes
Type | Name |
---|---|
class | Button |
struct | Style |
class | Value |
Public Functions
Type | Name |
---|---|
GuiRadio (GuiWindow * context, const std::string & label, int base, GuiRadio * other = nullptr) | |
virtual | ~GuiRadio () |
void | setLabel (const std::string & label) |
const std::string & | getLabel () const |
int | getBaseValue () const |
void | setValue (int value) |
int | getValue () const |
void | resetValue () |
void | assignValue (bool value) |
void | setButtonSize (float width) |
const GuiRadio::Button * | getButton () const |
GuiRadio::Button * | getButton () |
virtual ffw::Pointf | getMinimumWrapSize () override |
void | setStyle (const GuiRadio::Style * style, bool defaults = false) |
Detailed Description
It is possible to group together multiple radio widgets together (when you click one, it will turn off other radios). The setValue() and getValue() operates on integers and the value is based on the base value set in the constructor. In the example below we are creating widgets with base values of 100, 200, and 300.
auto gui = ffw::GuiWindowNanoVG(nvg);
auto root = gui.getLayout();
// Create three radios that will belong to the same group.
// To group radios, simply add first of the group member as
// the 4th parameter. The base value is the 3rd parameter.
// This is similar as in HTML: <input type="radio" value="100" .../>
auto radio1 = new ffw::GuiRadio(&gui, "Radio #1", 100);
auto radio2 = new ffw::GuiRadio(&gui, "Radio #2", 200, radio1);
auto radio3 = new ffw::GuiRadio(&gui, "Radio #3", 300, radio1);
radio1->addEventCallback([](ffw::GuiEvent e) {
// The "e.data.action.value" will be
// the base value, either 100, 200, or 300
std::cout << "Radio selected value: " << e.data.action.value << std::endl;
}, ffw::GuiEventType::ACTION);
// To change which radio is set, simply call setValue()
// on any of the grouped radios. This also works on
// getting the value via getValue().
radio1->setValue(200);
root->addWidget(radio1);
root->addWidget(radio2);
root->addWidget(radio3);
// Do not free the created widgets! They will be deleted by the gui window!
while(true){
// Render the gui
}
Public Functions Documentation
function GuiRadio
ffw::GuiRadio::GuiRadio (
GuiWindow * context,
const std::string & label,
int base,
GuiRadio * other = nullptr
)
function ~GuiRadio
virtual ffw::GuiRadio::~GuiRadio ()
function setLabel
void ffw::GuiRadio::setLabel (
const std::string & label
)
function getLabel
const std::string & ffw::GuiRadio::getLabel () const
function getBaseValue
int ffw::GuiRadio::getBaseValue () const
function setValue
void ffw::GuiRadio::setValue (
int value
)
function getValue
int ffw::GuiRadio::getValue () const
function resetValue
void ffw::GuiRadio::resetValue ()
function assignValue
void ffw::GuiRadio::assignValue (
bool value
)
function setButtonSize
void ffw::GuiRadio::setButtonSize (
float width
)
function getButton (1/2)
const GuiRadio::Button * ffw::GuiRadio::getButton () const
function getButton (2/2)
GuiRadio::Button * ffw::GuiRadio::getButton ()
function getMinimumWrapSize
virtual ffw::Pointf ffw::GuiRadio::getMinimumWrapSize ()
Implements GuiWidget::getMinimumWrapSize
function setStyle
void ffw::GuiRadio::setStyle (
const GuiRadio::Style * style,
bool defaults = false
)
The documentation for this class was generated from the following file: include/ffw/gui/guiradio.h