15 #include <unordered_set>
21 namespace visualization {
25 static int g_next_number_edit_id = 1;
44 impl_->id_ =
"##numedit" +
std::to_string(g_next_number_edit_id++);
54 if (impl_->type_ ==
INT) {
55 impl_->value_ = std::round(val);
66 if (impl_->type_ ==
INT) {
67 impl_->min_value_ = std::round(min_value);
68 impl_->max_value_ = std::round(max_value);
70 impl_->min_value_ = min_value;
71 impl_->max_value_ = min_value;
79 impl_->num_decimal_digits_ = num_digits;
83 impl_->preferred_width_ =
width;
87 impl_->on_changed_ = on_changed;
97 if (impl_->min_value_ < 0) {
101 int height = int(std::round(ImGui::GetTextLineHeightWithSpacing()));
102 auto padding =
height - int(std::round(ImGui::GetTextLineHeight()));
103 int incdec_width = 0;
104 if (impl_->type_ ==
INT) {
106 incdec_width = 2 *
height + padding;
110 (num_digits *
context.theme.font_size) / 2 + padding + incdec_width;
111 if (impl_->preferred_width_ > 0) {
112 width = impl_->preferred_width_;
119 ImGui::SetCursorScreenPos(
120 ImVec2(
float(
frame.x),
float(
frame.y) - ImGui::GetScrollY()));
122 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding,
125 ImGui::PushStyleColor(
128 ImGui::PushStyleColor(
129 ImGuiCol_FrameBgHovered,
131 ImGui::PushStyleColor(
132 ImGuiCol_FrameBgActive,
138 if (impl_->type_ ==
INT) {
139 int ivalue = int(impl_->value_);
140 if (ImGui::InputInt(impl_->id_.c_str(), &ivalue)) {
146 if (impl_->num_decimal_digits_ >= 0) {
148 snprintf(buff, 31,
"%%.%df", impl_->num_decimal_digits_);
151 if (impl_->value_ < 10) {
153 }
else if (impl_->value_ < 100) {
155 }
else if (impl_->value_ < 1000) {
161 double dvalue = impl_->value_;
162 if (ImGui::InputDouble(impl_->id_.c_str(), &dvalue, 0.0, 0.0,
168 ImGui::PopItemWidth();
172 ImGui::PopStyleColor(3);
173 ImGui::PopStyleVar();
175 if (ImGui::IsItemDeactivatedAfterEdit()) {
176 if (impl_->on_changed_) {
177 impl_->on_changed_(impl_->value_);
double GetMinimumValue() const
int GetDecimalPrecision()
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
void SetPreferredWidth(int width)
void SetLimits(double min_value, double max_value)
void SetDecimalPrecision(int num_digits)
Widget::DrawResult Draw(const DrawContext &context) override
void SetOnValueChanged(std::function< void(double)> on_changed)
double GetMaximumValue() const
double GetDoubleValue() const
void SetValue(double val)
__host__ __device__ int2 abs(int2 v)
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
ImVec4 colorToImgui(const Color &color)
Generic file read and write utility for python interface.
std::string to_string(const T &n)
std::function< void(double)> on_changed_