NumberSlider.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 
7 #include <mc_rtc/gui/elements.h>
8 
9 namespace mc_rtc::gui
10 {
11 
12 namespace details
13 {
14 
23 template<typename GetT, typename SetT>
24 struct NumberSliderImpl : public CommonInputImpl<GetT, SetT>
25 {
26  static constexpr auto type = Elements::NumberSlider;
27 
28  NumberSliderImpl(const std::string & name, GetT get_fn, SetT set_fn, double min, double max)
29  : CommonInputImpl<GetT, SetT>(name, get_fn, set_fn), min_(min), max_(max)
30  {
31  }
32 
34 
35  static constexpr size_t write_size() { return CommonInputImpl<GetT, SetT>::write_size() + 2; }
36 
38  {
40  writer.write(min_);
41  writer.write(max_);
42  }
43 
44 private:
45  double min_;
46  double max_;
47 };
48 
49 } // namespace details
50 
52 template<typename GetT, typename SetT>
53 auto NumberSlider(const std::string & name, GetT get_fn, SetT set_fn, double min, double max)
54 {
55  return details::NumberSliderImpl(name, get_fn, set_fn, min, max);
56 }
57 
59 template<typename T>
60 auto NumberSlider(const std::string & name, T & value, double min, double max)
61 {
62  return details::NumberSliderImpl(name, details::read(value), details::write(value), min, max);
63 }
64 
65 } // namespace mc_rtc::gui
mc_rtc::gui::DataElement::write_size
static constexpr size_t write_size()
Definition: elements.h:106
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::details::NumberSliderImpl::NumberSliderImpl
NumberSliderImpl(const std::string &name, GetT get_fn, SetT set_fn, double min, double max)
Definition: NumberSlider.h:28
mc_rtc::gui::Elements::NumberSlider
@ NumberSlider
mc_rtc::gui::details::NumberSliderImpl::type
static constexpr auto type
Definition: NumberSlider.h:26
mc_rtc::gui::details::NumberSliderImpl::NumberSliderImpl
NumberSliderImpl()
Definition: NumberSlider.h:33
mc_rtc::gui::details::NumberSliderImpl
Definition: NumberSlider.h:24
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
elements.h
mc_rtc::gui::NumberSlider
auto NumberSlider(const std::string &name, GetT get_fn, SetT set_fn, double min, double max)
Definition: NumberSlider.h:53
mc_rtc::gui::details::write
auto write(T &value)
Definition: traits.h:224
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::NumberSliderImpl::write
void write(mc_rtc::MessagePackBuilder &writer)
Definition: NumberSlider.h:37
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
mc_rtc::gui::CommonInputImpl
Definition: elements.h:166
mc_rtc::gui::details::NumberSliderImpl::write_size
static constexpr size_t write_size()
Definition: NumberSlider.h:35
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61