Checkbox.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 #include <mc_rtc/gui/elements.h>
9 
10 namespace mc_rtc::gui
11 {
12 
13 namespace details
14 {
15 
23 template<typename GetT, typename Callback>
24 struct CheckboxImpl : public VoidCallbackElement<DataElement<GetT>, Callback>
25 {
26  static constexpr auto type = Elements::Checkbox;
27 
28  CheckboxImpl(const std::string & name, GetT get_fn, Callback cb)
29  : VoidCallbackElement<DataElement<GetT>, Callback>(name, cb, get_fn)
30  {
32  "Checkbox element getter callback must return a boolean");
33  }
34 
37 };
38 
39 } // namespace details
40 
42 template<typename GetT, typename Callback>
43 auto Checkbox(const std::string & name, GetT get_fn, Callback cb)
44 {
45  return details::CheckboxImpl(name, get_fn, cb);
46 }
47 
49 inline auto Checkbox(const std::string & name, bool & value)
50 {
51  return details::CheckboxImpl(name, details::read(value), [&value]() { value = !value; });
52 }
53 
54 } // namespace mc_rtc::gui
mc_rtc::gui::details::CheckboxImpl::CheckboxImpl
CheckboxImpl(const std::string &name, GetT get_fn, Callback cb)
Definition: Checkbox.h:28
mc_rtc::gui::details::CheckboxImpl::type
static constexpr auto type
Definition: Checkbox.h:26
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
elements.h
mc_rtc::gui::details::CheckboxImpl::CheckboxImpl
CheckboxImpl()
Definition: Checkbox.h:36
mc_rtc::gui::DataElement
Definition: elements.h:104
mc_rtc::gui::Checkbox
auto Checkbox(const std::string &name, GetT get_fn, Callback cb)
Definition: Checkbox.h:43
mc_rtc::gui::Elements::Checkbox
@ Checkbox
mc_rtc::gui::VoidCallbackElement
Definition: elements.h:183
mc_rtc::gui::details::CheckboxImpl
Definition: Checkbox.h:24
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61