CheckBox.hpp

Create/control an HTML checkbox and call a specified function when it changes.

This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2024 Michigan State University MIT Software license; see doc/LICENSE.md

Use example:

CheckBox my_checkbox(MyFun, “html_id”);

Where:

  • my_checkbox is the C++ object linking to the checkbox

  • MyFun takes a bool argument and is called every time the checkbox status changes

  • ”html_id” is the optional id you want it to use in the HTML code (otherwise it will generate a unique name on its own.)

Member functions to set state: CheckBox & SetCallback(const std::function<void(bool)> & in_callback) CheckBox & SetAutofocus(bool in_af) CheckBox & SetDisabled(bool in_dis)

Retrieving current state: bool IsSet() const bool HasAutofocus() const bool IsDisabled() const

Defines

INCLUDE_EMP_WEB_CHECK_BOX_HPP_GUARD
class CheckBox : public internal::WidgetFacet<CheckBox>
#include <CheckBox.hpp>

Create or control an HTML CheckBox object that you can manipulate and update as needed.

Public Types

using INFO_TYPE = CheckBoxInfo

Public Functions

inline CheckBox(const std::string &in_id = "")
inline CheckBox(const cb_type &in_cb, const std::string &in_id = "")

Create a new checkbox.

Parameters:
  • in_cb – The void(size_t) function to call when the checkbox is toggled.

  • in_id – The HTML ID to use for this checkbox (leave blank for auto-generated)

inline CheckBox(const CheckBox &in)

Link to an existing checkbox.

inline CheckBox(const Widget &in)
inline virtual ~CheckBox()
inline bool IsChecked() const
inline CheckBox &SetChecked(bool in = true)
inline CheckBox &SetCallback(const cb_type &in_cb)

Set a new callback function to trigger when the checkbox is toggled.

inline CheckBox &SetAutofocus(bool _in = true)

Setup this checkbox to have autofocus (or remove it!)

inline CheckBox &SetDisabled(bool _in = true)

Setup this checkbox to be disabled (or re-enable it!)

inline bool HasAutofocus() const

Determine if this checkbox currently has autofocus.

inline bool IsDisabled() const

Determine if this checkbox is currently disabled.

Protected Types

using cb_type = std::function<void(size_t)>

Protected Functions

inline CheckBoxInfo *Info()
inline const CheckBoxInfo *Info() const
inline CheckBox(CheckBoxInfo *in_info)

Friends

friend class CheckBoxInfo