18 namespace visualization {
22 static int g_next_slider_id = 1;
51 if (impl_->type_ ==
INT) {
52 impl_->value_ = std::round(impl_->value_);
61 impl_->min_value_ = min_value;
62 impl_->max_value_ = max_value;
63 if (impl_->type_ ==
INT) {
64 impl_->min_value_ = std::round(impl_->min_value_);
65 impl_->max_value_ = std::round(impl_->max_value_);
71 impl_->on_value_changed_ = on_value_changed;
76 auto line_height = ImGui::GetTextLineHeight();
77 auto height = line_height + 2.0 * ImGui::GetStyle().FramePadding.y;
84 ImGui::SetCursorScreenPos(
85 ImVec2(
float(
frame.x),
float(
frame.y) - ImGui::GetScrollY()));
87 auto new_value = impl_->value_;
90 if (impl_->type_ ==
INT) {
91 int i_new_value = int(new_value);
92 ImGui::SliderInt(impl_->id_.c_str(), &i_new_value,
93 int(impl_->min_value_),
int(impl_->max_value_));
94 new_value = double(i_new_value);
96 float f_new_value = float(new_value);
97 ImGui::SliderFloat(impl_->id_.c_str(), &f_new_value,
98 float(impl_->min_value_),
float(impl_->max_value_));
99 new_value = double(f_new_value);
101 ImGui::PopItemWidth();
105 if (impl_->value_ != new_value) {
106 impl_->value_ = new_value;
107 if (impl_->on_value_changed_) {
108 impl_->on_value_changed_(new_value);
DrawResult Draw(const DrawContext &context) override
Size CalcPreferredSize(const LayoutContext &theme, const Constraints &constraints) const override
void SetValue(double val)
int GetIntValue() const
Returns the value of the control as an integer.
double GetMinimumValue() const
double GetMaximumValue() const
void SetLimits(double min_value, double max_value)
double GetDoubleValue() const
Returns the value of the control as a double.
void SetOnValueChanged(std::function< void(double)> on_value_changed)
Sets a function to call when the value changes because of user action.
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
Generic file read and write utility for python interface.
std::string to_string(const T &n)
std::function< void(double)> on_value_changed_