Overload  1.1
Game engine with editor
SliderSingleScalar.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <OvMaths/FVector2.h>
10 #include <OvTools/Eventing/Event.h>
11 
15 
16 namespace OvUI::Widgets::Sliders
17 {
21  template <typename T>
22  class SliderSingleScalar : public DataWidget<T>
23  {
24  static_assert(std::is_scalar<T>::value, "Invalid SliderSingleScalar T (Scalar expected)");
25 
26  public:
38  (
39  ImGuiDataType p_dataType,
40  T p_min,
41  T p_max,
42  T p_value,
43  ESliderOrientation p_orientation,
44  const std::string& p_label,
45  const std::string& p_format
46  ) : DataWidget<T>(value), m_dataType(p_dataType), min(p_min), max(p_max), value(p_value), orientation(p_orientation), label(p_label), format(p_format) {}
47 
48  protected:
49  void _Draw_Impl() override
50  {
51  if (max < min)
52  max = min;
53 
54  if (value < min)
55  value = min;
56  else if (value > max)
57  value = max;
58 
59  bool valueChanged = false;
60 
61  switch (orientation)
62  {
64  valueChanged = ImGui::SliderScalar((label + this->m_widgetID).c_str(), m_dataType, &value, &min, &max, format.c_str());
65  break;
67  valueChanged = ImGui::VSliderScalar((label + this->m_widgetID).c_str(), Internal::Converter::ToImVec2(verticalModeSize), m_dataType, &value, &min, &max, format.c_str());
68  break;
69  }
70 
71  if (valueChanged)
72  {
74  this->NotifyChange();
75  }
76  }
77 
78  public:
79  T min;
80  T max;
81  T value;
83  OvMaths::FVector2 verticalModeSize; /* Only applied with ESliderOrientation::VERTICAL */
84  std::string label;
85  std::string format;
87 
88  private:
89  ImGuiDataType m_dataType;
90  };
91 }
OvUI::Widgets::Sliders::SliderSingleScalar::_Draw_Impl
void _Draw_Impl() override
Definition: SliderSingleScalar.h:49
OvUI::Widgets::Sliders::SliderSingleScalar
Definition: SliderSingleScalar.h:22
OvUI::Widgets::Sliders::ESliderOrientation::VERTICAL
OvTools::Eventing::Event< T >
OvUI::Widgets::Sliders::SliderSingleScalar::ValueChangedEvent
OvTools::Eventing::Event< T > ValueChangedEvent
Definition: SliderSingleScalar.h:86
OvUI::Widgets::DataWidget::NotifyChange
void NotifyChange()
Definition: DataWidget.h:53
OvUI::Widgets::Sliders::SliderSingleScalar::verticalModeSize
OvMaths::FVector2 verticalModeSize
Definition: SliderSingleScalar.h:83
ESliderOrientation.h
OvUI::Widgets::Sliders::SliderSingleScalar::max
T max
Definition: SliderSingleScalar.h:80
OvTools::Eventing::Event::Invoke
void Invoke(ArgTypes... p_args)
Definition: Event.inl:52
FVector2.h
OvUI::Widgets::Sliders::SliderSingleScalar::orientation
ESliderOrientation orientation
Definition: SliderSingleScalar.h:82
Converter.h
OvMaths::FVector2
Definition: FVector2.h:16
OvUI::Widgets::Sliders::SliderSingleScalar::value
T value
Definition: SliderSingleScalar.h:81
DataWidget.h
Event.h
OvUI::Widgets::Sliders::SliderSingleScalar::SliderSingleScalar
SliderSingleScalar(ImGuiDataType p_dataType, T p_min, T p_max, T p_value, ESliderOrientation p_orientation, const std::string &p_label, const std::string &p_format)
Definition: SliderSingleScalar.h:38
OvUI::Widgets::Sliders
Definition: ESliderOrientation.h:9
OvUI::Widgets::AWidget::m_widgetID
std::string m_widgetID
Definition: AWidget.h:81
OvUI::Widgets::Sliders::SliderSingleScalar::min
T min
Definition: SliderSingleScalar.h:79
OvUI::Widgets::Sliders::SliderSingleScalar::label
std::string label
Definition: SliderSingleScalar.h:84
OvUI::Internal::Converter::ToImVec2
static ImVec2 ToImVec2(const OvMaths::FVector2 &p_value)
Definition: Converter.cpp:19
OvUI::Widgets::Sliders::SliderSingleScalar::format
std::string format
Definition: SliderSingleScalar.h:85
OvUI::Widgets::DataWidget
Definition: DataWidget.h:18
OvUI::Widgets::Sliders::ESliderOrientation
ESliderOrientation
Definition: ESliderOrientation.h:14
OvUI::Widgets::Sliders::ESliderOrientation::HORIZONTAL