Brisk, a GUI application framework for modern C++

const NameValueOrderedList<TextAlign> textAlignList{ { "Start", TextAlign::Start },

                                                     { "Center", TextAlign::Center },

                                                     { "End", TextAlign::End } };

class Example : public Component {

public:

    Rc<Widget> build() final {

        // rcnew Widget{...} is equivalent to std::shared_ptr<Widget>(new Widget{...})

        return rcnew Widget{

            layout = Layout::Vertical,

            rcnew Text{

                "Switch (widgets/Switch.hpp)",

                classes = { "section-header" }, // Widgets can be styled using stylesheets

            },

            rcnew HLayout{

                rcnew Widget{

                    rcnew Switch{

                        // Bind the switch value to the m_toggled variable (bidirectional)

                        value = Value{ &m_toggled },

                        rcnew Text{ "Switch" },

                    },

                },

                gapColumn = 10_apx, // CSS Flex-like properties

                rcnew Text{

                    text = Value{ &m_label }, // Text may be dynamic

                    visible =

                        Value{ &m_toggled }, // The Switch widget controls the visibility of this text widget

                },

            },

            // Button widget

            rcnew Button{

                rcnew Text{ "Click" },

                // Using lifetime() ensures that callbacks will be detached once the Component is deleted

                onClick = lifetime() |

                          [this]() {

                              // Notify bindings about the change

                              bindings->assign(m_label) = "Updated text";

                          },

            },

            // ComboBox widget

            rcnew ComboBox{

                Value{ &m_textAlignment },  // Bind ComboBox value to an enumeration

                notManaged(&textAlignList), // Pass the list of name-value pairs to populate the ComboBox

            },

            // The Builder creates widgets dynamically whenever needed

            Builder([this](Widget* target) {

                for (int i = 0; i < m_number; ++i) {

                    target->apply(rcnew Widget{

                        dimensions = { 40_apx, 40_apx },

                    });

                }

            }),

            depends = Value{ &m_number }, // Instructs to rebuild this if m_number changes

        };

    }

private:

    bool m_toggled            = false;

    TextAlign m_textAlignment = TextAlign::Start;

    std::string m_label       = "OK";

    float m_progress          = 0;

    int m_number              = 0;

};