19 namespace visualization {
23 static const int NO_SELECTION = -1;
24 static int g_next_radiobtn_id = 1;
43 impl_->items_ = items;
44 impl_->selected_index_ = items.empty() ? NO_SELECTION : 0;
50 if (impl_->selected_index_ < 0 ||
51 impl_->selected_index_ >=
int(impl_->items_.size())) {
54 return impl_->items_[impl_->selected_index_].c_str();
60 impl_->selected_index_ =
std::min(
int(impl_->items_.size() - 1), index);
65 impl_->on_selection_changed_ =
callback;
70 auto fh = ImGui::GetFrameHeight();
71 auto& st = ImGui::GetStyle();
72 auto spacing = st.ItemSpacing.x + st.ItemInnerSpacing.x;
74 auto* font = ImGui::GetFont();
75 for (
auto& item : impl_->items_) {
76 auto item_size = font->CalcTextSizeA(
float(
context.theme.font_size),
77 float(constraints.
width), 0.0,
79 if (impl_->type_ == Type::VERT) {
83 size.x += fh + item_size.x + spacing;
87 if (impl_->type_ == Type::VERT) {
88 size.x += fh + st.ItemInnerSpacing.x;
96 ImGui::SetCursorScreenPos(
97 ImVec2(
float(
frame.x),
float(
frame.y) - ImGui::GetScrollY()));
103 auto selected_idx = impl_->selected_index_;
104 for (
size_t i = 0; i < impl_->items_.size(); ++i) {
105 if (impl_->type_ == Type::HORIZ && i > 0) {
108 auto pos = ImGui::GetCursorScreenPos();
109 pos.x = float(
frame.x);
110 ImGui::SetCursorScreenPos(pos);
113 bool is_selected = (int(i) == impl_->selected_index_);
115 ImGui::PushStyleColor(
118 ImGui::PushStyleColor(
119 ImGuiCol_FrameBgHovered,
121 context.theme.radiobtn_background_hover_on_color));
123 ImGui::PushStyleColor(
126 ImGui::PushStyleColor(
127 ImGuiCol_FrameBgHovered,
129 context.theme.radiobtn_background_hover_off_color));
131 ImGui::RadioButton(impl_->items_[i].c_str(), &selected_idx, i);
132 ImGui::PopStyleColor(2);
134 ImGui::PopItemWidth();
137 if (selected_idx != impl_->selected_index_) {
138 impl_->selected_index_ = selected_idx;
139 if (impl_->on_selection_changed_) {
140 impl_->on_selection_changed_(impl_->selected_index_);
std::function< void(std::shared_ptr< core::Tensor >)> callback
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)