95 if (
auto* drawList = ImGui::GetWindowDrawList())
99 drawList->AddRectFilled(bounds.Min, bounds.Max, IM_COL32(25, 25, 25, 255));
105 const float step = bounds.GetWidth() /
static_cast<float>(n);
106 ImRect rect(bounds.Min.x, bounds.Min.y, bounds.Min.x + step, bounds.Max.y);
107 for (
size_t i = 0; i < n; ++i)
112 drawList->AddRectFilledMultiColor(rect.Min, rect.Max, col1, col2, col2, col1);
113 rect.TranslateX(step);
120 ImGuiContext& G = *GImGui;
121 const ImGuiStyle& style = G.Style;
122 ImGuiWindow* Window = G.CurrentWindow;
123 if (Window->SkipItems) {
return false; }
125 const ImVec2 pos = ImGui::GetCurrentWindow()->DC.CursorPos;
126 const ImVec2 label_size = ImGui::CalcTextSize(label,
nullptr,
true);
127 ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0F, label_size.y + style.FramePadding.y * 2.0F);
128 const ImRect rect = ImRect(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
130 ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32_BLACK_TRANS);
131 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1, 1, 1, 0.1F));
132 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1, 1, 1, 0.2F));
133 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0);
134 const bool pressed = ImGui::Button(label, size);
135 ImGui::PopStyleColor(3);
136 ImGui::PopStyleVar(1);
138 bool changed =
false;
140 if (pressed) { ImGui::OpenPopup(fmt::format(
"Colormap##{}", label).c_str()); }
141 if (ImGui::BeginPopup(fmt::format(
"Colormap##{}", label).c_str()))
143 if (ImGui::BeginTable(fmt::format(
"##{} colormap table", label).c_str(), 5, ImGuiTableFlags_SizingFixedFit, ImVec2(0.0F, 0.0F)))
145 ImGui::TableSetupColumn(
"Value");
146 ImGui::TableSetupColumn(
"Color");
147 ImGui::TableSetupColumn(
"");
148 ImGui::TableSetupColumn(
"");
149 ImGui::TableSetupColumn(
"");
151 int colormapRemovalIdx = -1;
153 ImGui::TableHeadersRow();
154 for (
size_t i = 0; i < cmap.
colormap.size(); i++)
156 auto& [value, color] = cmap.
colormap.at(i);
157 ImGui::TableNextColumn();
158 ImGui::SetNextItemWidth(100.0F);
160 i != 0 ? cmap.
colormap.at(i - 1).first : std::numeric_limits<double>::lowest(),
161 i != cmap.
colormap.size() - 1 ? cmap.
colormap.at(i + 1).first : std::numeric_limits<double>::max(),
162 0.0, 0.0,
"%.6g", ImGuiInputTextFlags_CharsScientific))
168 ImGui::TableNextColumn();
169 ImGui::SetNextItemWidth(300.0F);
170 if (ImGui::ColorEdit4(fmt::format(
"##{} colormap color {}", label, i).c_str(), &color.Value.x))
176 ImGui::TableNextColumn();
177 if (ImGui::Button(fmt::format(
"⌃##{} insert colormap above {}", label, i).c_str())) { insertIdx =
static_cast<int>(i); }
178 if (ImGui::IsItemHovered()) { ImGui::SetTooltip(
"Insert entry above?"); }
180 ImGui::TableNextColumn();
181 if (ImGui::Button(fmt::format(
"⌄##{} insert colormap below {}", label, i).c_str())) { insertIdx =
static_cast<int>(i) + 1; }
182 if (ImGui::IsItemHovered()) { ImGui::SetTooltip(
"Insert entry below?"); }
184 ImGui::TableNextColumn();
187 if (ImGui::Button(fmt::format(
"X##{} remove colormap {}", label, i).c_str())) { colormapRemovalIdx =
static_cast<int>(i); }
188 if (ImGui::IsItemHovered()) { ImGui::SetTooltip(
"Remove?"); }
191 if (colormapRemovalIdx >= 0)
193 cmap.
colormap.erase(cmap.
colormap.begin() +
static_cast<std::ptrdiff_t
>(colormapRemovalIdx));
199 cmap.
colormap.insert(cmap.
colormap.begin() +
static_cast<std::ptrdiff_t
>(insertIdx),
200 std::make_pair(cmap.
colormap.at(
static_cast<size_t>(insertIdx !=
static_cast<int>(cmap.
colormap.size()) ? insertIdx : insertIdx - 1)).first,
201 ImColor(1.0F, 1.0F, 1.0F, 1.0F)));
247 bool changes =
false;
251 std::string colormapName = activeColormap ? activeColormap->get().name :
"";
252 if (ImGui::BeginCombo(fmt::format(
"{}Colormap Mask", label).c_str(), colormapName.c_str()))
254 if (ImGui::Selectable(
"##Empty colormap mask", colormapName.empty(), 0))
264 if (colormapName.empty()) { ImGui::SetItemDefaultFocus(); }
268 const bool is_selected = (cmap.getId() ==
id);
269 if (ImGui::Selectable(fmt::format(
"G: {}##Global colormap", cmap.name).c_str(), is_selected, 0))
279 if (is_selected) { ImGui::SetItemDefaultFocus(); }
283 const bool is_selected = (cmap.getId() ==
id);
284 if (ImGui::Selectable(fmt::format(
"F: {}##Flow colormap", cmap.name).c_str(), is_selected, 0))
294 if (is_selected) { ImGui::SetItemDefaultFocus(); }
bool InputDoubleL(const char *label, double *v, double v_min, double v_max, double step, double step_fast, const char *format, ImGuiInputTextFlags flags)
Shows a value limited InputText GUI element for 'double'.