166 if(widget_state == enable) {
183 const std::string&
id()
const 244 template <
class T,
class W,
class CT>
265 const bool mandatory,
266 const std::function<T()>& callback_load_value,
267 const std::function<
void(CT)>& callback_save_value)
271 , callback_load_value_(callback_load_value)
272 , callback_save_value_(callback_save_value)
274 static_assert(!std::is_same_v<styled_widget, W>,
"Second template argument cannot be styled_widget");
291 field(
const std::string&
id,
const bool mandatory, T& linked_variable)
294 , link_(linked_variable)
295 , callback_load_value_(nullptr)
296 , callback_save_value_(nullptr)
298 static_assert(!std::is_same_v<styled_widget, W>,
"Second template argument cannot be styled_widget");
318 field(
const std::string&
id,
const bool mandatory,
const T& value)
322 , callback_load_value_(nullptr)
323 , callback_save_value_(nullptr)
325 static_assert(std::is_same_v<styled_widget, W>,
"Second template argument must be styled_widget");
412 if(callback_load_value_) {
413 value_ = callback_load_value_();
426 if(callback_save_value_) {
427 callback_save_value_(value_);
447 throw std::runtime_error(
"Mandatory field widget is null");
456 void save(
const bool must_be_active)
460 if(!must_be_active ||
get_widget()->get_active()) {
461 if constexpr(std::is_same_v<W, styled_widget>) {
462 value_ =
widget->get_label();
463 }
else if constexpr(std::is_same_v<W, selectable_item>) {
464 value_ =
widget->get_value_bool();
466 value_ =
widget->get_value();
478 if constexpr(std::is_same_v<W, styled_widget>) {
479 widget->set_label(value_);
481 widget->set_value(value_);
492 const bool mandatory,
493 const std::function<
bool()>& callback_load_value,
494 const std::function<
void(
const bool)>& callback_save_value,
495 const std::function<
void(
widget&)>& callback_change,
496 const bool initial_fire)
498 id, mandatory, callback_load_value, callback_save_value)
499 , callback_change_(callback_change)
500 , initial_fire_(initial_fire)
505 const bool mandatory,
506 bool& linked_variable,
507 const std::function<
void(
widget&)>& callback_change,
508 const bool initial_fire)
510 , callback_change_(callback_change)
511 , initial_fire_(initial_fire)
519 if(callback_change_) {
522 callback_change_(*
widget);
540 const bool mandatory,
541 const std::function<std::string()>& callback_load_value,
542 const std::function<
void(
const std::string&)>&
545 id, mandatory, callback_load_value, callback_save_value)
550 const bool mandatory,
551 std::string& linked_variable)
553 id, mandatory, linked_variable)
562 widget->save_to_history();
572 const bool mandatory,
573 const std::string& text,
574 const bool use_markup)
576 , use_markup_(use_markup)
field_base(const std::string &id, const bool mandatory)
Constructor.
virtual void finalize_generic()=0
See widget_finalize.
virtual void finalize_specialized()
See widget_finalize.
Small abstract helper class.
Abstract base class for text items.
void init_specialized()
Overridden from field_base.
void widget_restore()
Inherited from field_base.
bool is_mandatory() const
field_label(const std::string &id, const bool mandatory, const std::string &text, const bool use_markup)
field_text(const std::string &id, const bool mandatory, std::string &linked_variable)
void attach_to_window(window &window)
Attaches the field to a window.
Abstract base class for the fields.
void restore()
Stores the internal value_ in the widget.
virtual void init_specialized()
See widget_init.
Specialized field class for boolean.
const styled_widget * get_widget() const
void widget_save()
Inherited from field_base.
void set_widget_value(CT value)
Sets the value of the field.
virtual void widget_restore()=0
Restores a widget.
T & link_
The variable linked to the field.
virtual void widget_save()=0
Saves a widget.
void set_cache_value(CT value)
Sets the value of the field.
void detach_from_window()
Detaches the field from a window.
void init_generic()
Inherited from field_base.
virtual void init_generic()=0
See widget_init.
const std::string & id() const
field_text(const std::string &id, const bool mandatory, const std::function< std::string()> &callback_load_value, const std::function< void(const std::string &)> &callback_save_value)
const bool mandatory_
Is the widget optional or mandatory in this window.
Contains all forward declarations for field.hpp.
bool use_markup_
Whether or not the label uses markup.
styled_widget * widget_
The widget attached to the field.
field(const std::string &id, const bool mandatory, const std::function< T()> &callback_load_value, const std::function< void(CT)> &callback_save_value)
Constructor.
void widget_finalize()
Finalizes the widget.
styled_widget * get_widget()
void init_specialized()
Overridden from field_base.
T value_
The value_ of the widget, this value is also available once the widget is destroyed.
field_bool(const std::string &id, const bool mandatory, const std::function< bool()> &callback_load_value, const std::function< void(const bool)> &callback_save_value, const std::function< void(widget &)> &callback_change, const bool initial_fire)
Specialized field class for a styled_widget, used for labels and images.
void finalize_specialized()
Overridden from field_base.
T get_widget_value()
Gets the value of the field.
field_bool(const std::string &id, const bool mandatory, bool &linked_variable, const std::function< void(widget &)> &callback_change, const bool initial_fire)
void save(const bool must_be_active)
Stores the value in the widget in the interval value_.
const std::string id_
The id field of the widget, should be unique in a window.
std::function< void(widget &)> callback_change_
field(const std::string &id, const bool mandatory, const T &value)
Constructor.
void validate_widget()
Test whether the widget exists if the widget is mandatory.
void widget_set_enabled(const bool enable, const bool sync)
Enables a widget.
std::function< void(CT)> callback_save_value_
The callback function to save the value.
field(const std::string &id, const bool mandatory, T &linked_variable)
Constructor.
void widget_init()
Initializes the widget.
std::function< T()> callback_load_value_
The callback function to load the value.
Specialized field class for text.
void finalize_generic()
Inherited from field_base.
base class of top level items, the only item which needs to store the final canvases to draw on...
Template class to implement the generic field implementation.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.