19 namespace visualization {
23 static int g_next_checkbox_id = 1;
36 impl_->name_ +
"##checkbox_" +
std::to_string(g_next_checkbox_id++);
46 impl_->on_checked_ = on_checked;
51 auto em = ImGui::GetTextLineHeight();
52 auto padding = ImGui::GetStyle().FramePadding;
53 auto text_size = ImGui::GetFont()->CalcTextSizeA(
54 float(
context.theme.font_size), 10000, 10000, impl_->name_.c_str());
56 auto checkbox_width =
height + padding.x;
57 return Size(
int(checkbox_width +
std::ceil(text_size.x + 2.0f * padding.x)),
63 ImGui::SetCursorScreenPos(
64 ImVec2(
float(
frame.x),
float(
frame.y) - ImGui::GetScrollY()));
69 if (impl_->is_checked_) {
70 ImGui::PushStyleColor(
73 ImGui::PushStyleColor(
74 ImGuiCol_FrameBgHovered,
77 ImGui::PushStyleColor(
80 ImGui::PushStyleColor(
81 ImGuiCol_FrameBgHovered,
83 context.theme.checkbox_background_hover_off_color));
88 if (ImGui::Checkbox(impl_->id_.c_str(), &impl_->is_checked_)) {
89 if (impl_->on_checked_) {
90 impl_->on_checked_(impl_->is_checked_);
94 ImGui::PopItemWidth();
98 ImGui::PopStyleColor(2);
Checkbox(const char *name)
void SetChecked(bool checked)
DrawResult Draw(const DrawContext &context) override
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
void SetOnChecked(std::function< void(bool)> on_checked)
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(bool)> on_checked_