31 float padding = 10.0f;
32 float bounding = 1.0f;
33 ImVec2 p = ImGui::GetCursorScreenPos();
34 ImDrawList* draw_list = ImGui::GetWindowDrawList();
35 const ImVec2 label_size = ImGui::CalcTextSize(label);
36 const ImVec2 button_size = ImVec2(label_size.x + padding * 2, label_size.y + padding * 2);
37 const ImVec2 bound_size = ImVec2(button_size.x + bounding * 2, button_size.y + bounding * 2);
38 ImVec2 p_button = ImVec2(p.x + bounding, p.y + bounding);
39 ImVec2 p_label = ImVec2(p_button.x + padding, p_button.y + padding);
41 float radius = bound_size.y * 0.30f;
44 if (ImGui::InvisibleButton(label, bound_size))
47 ImGuiStyle& style = ImGui::GetStyle();
50 if (ImGui::IsItemActivated()) col_bf4 = *v ? style.Colors[40] : style.Colors[23];
51 else if (ImGui::IsItemHovered()) col_bf4 = *v ? style.Colors[42] : style.Colors[24];
52 else col_bf4 = *v ? style.Colors[41] : style.Colors[22];
54 ImU32 col_bg = IM_COL32(255 * col_bf4.x, 255 * col_bf4.y, 255 * col_bf4.z, 255 * col_bf4.w);
55 ImU32 col_text = IM_COL32(255, 255, 255, 255);
56 ImU32 col_bound = IM_COL32(0,0,0,255);
59 draw_list->AddRect(p, ImVec2(p.x + bound_size.x, p.y + bound_size.y), col_bound , radius);
60 draw_list->AddRectFilled(p_button, ImVec2(p_button.x + button_size.x, p_button.y + button_size.y), col_bg, radius);
61 draw_list->AddText(p_label, col_text, label);
160bool ImGui::ImageButtonWithText(ImTextureID texId,
const char* label,
const ImVec2& imageSize,
const ImVec2 &uv0,
const ImVec2 &uv1,
int frame_padding,
const ImVec4 &bg_col,
const ImVec4 &tint_col) {
163 GImGui = GetCurrentContext();
164 ImGuiWindow* window = GetCurrentWindow();
166 if (window->SkipItems)
169 ImVec2 size = imageSize;
170 if (size.x<=0 && size.y<=0) {size.x=size.y=ImGui::GetTextLineHeightWithSpacing();}
172 if (size.x<=0) size.x=size.y;
173 else if (size.y<=0) size.y=size.x;
174 size*=window->FontWindowScale*ImGui::GetIO().FontGlobalScale;
177 const ImGuiStyle& style = GetStyle();
179 const ImGuiID
id = window->GetID(label);
180 const ImVec2 textSize = ImGui::CalcTextSize(label,NULL,
true);
181 const bool hasText = textSize.x>0;
183 const float innerSpacing = hasText ? ((frame_padding >= 0) ? (float)frame_padding : (style.ItemInnerSpacing.x)) : 0.f;
184 const ImVec2 padding = (frame_padding >= 0) ? ImVec2((
float)frame_padding, (
float)frame_padding) : style.FramePadding;
185 const ImVec2 totalSizeWithoutPadding(size.x+innerSpacing+textSize.x,size.y>textSize.y ? size.y : textSize.y);
186 const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + totalSizeWithoutPadding + padding*2);
188 start = window->DC.CursorPos + padding;
189 if (size.y<textSize.y) start.y+=(textSize.y-size.y)*.5f;
191 const ImRect image_bb(start, start + size);
192 start = window->DC.CursorPos + padding;start.x+=size.x+innerSpacing;
193 if (size.y>textSize.y) start.y+=(size.y-textSize.y)*.5f;
196 if (!ItemAdd(bb,
id))
199 bool hovered=
false, held=
false;
200 bool pressed = ButtonBehavior(bb,
id, &hovered, &held);
203 const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
204 RenderFrame(bb.Min, bb.Max, col,
true, ImClamp((
float)ImMin(padding.x, padding.y), 0.0f, style.FrameRounding));
206 window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, GetColorU32(bg_col));
208 window->DrawList->AddImage(texId, image_bb.Min, image_bb.Max, uv0, uv1, GetColorU32(tint_col));
210 if (textSize.x>0) ImGui::RenderText(start,label);
245 if (col ==
nullptr )
return false;
247 GImGui = GetCurrentContext();
248 ImGuiWindow* window = GetCurrentWindow();
249 if (window->SkipItems)
252 ImDrawList* draw_list = window->DrawList;
253 ImGuiStyle& style = GetStyle();
254 ImGuiIO& io = GetIO();
255 ImGuiID
id = window->GetID(label);
257 const float width = CalcItemWidth();
263 float text_width = GetFrameHeight() * 3;
264 float text_height = GetFrameHeight();
265 float bars_width = GetFrameHeight() * 1.5;
266 float bars_height = ImMax(bars_width * 1, width - 1 * (bars_width + style.ItemInnerSpacing.x));
267 float offset_width = bars_width * 0.2;
268 ImVec2 bar_pos = window->DC.CursorPos;
269 ImVec2 real_bar_pos = bar_pos + ImVec2(0, 0.3 * text_height );
270 ImRect bb(bar_pos, bar_pos + ImVec2(bars_width + offset_width + text_width, bars_height + text_height));
271 int grid_count = length - 1;
274 ItemSize(ImVec2(bars_width + offset_width + text_width, bars_height + text_height));
275 if (!ItemAdd(bb,
id))
282 for (
int i = 0; i <= grid_count; ++i){
284 draw_list->AddRectFilledMultiColor(
285 ImVec2(real_bar_pos.x, real_bar_pos.y + i * (bars_height / grid_count)),
286 ImVec2(real_bar_pos.x + bars_width, real_bar_pos.y + (i + 1) * (bars_height / grid_count)),
287 col[i], col[i], col[i + 1], col[i + 1]);
289 if (values !=
nullptr){
292 sprintf(buf,
"%-6.4f", values[i]);
294 sprintf(buf,
"%-6.2e", values[i]);
295 draw_list->AddText(ImVec2(bar_pos.x + bars_width + offset_width, bar_pos.y + i * (bars_height / grid_count)), IM_COL32(255,255,255,255),buf);
298 RenderFrameBorder(ImVec2(real_bar_pos.x, real_bar_pos.y), ImVec2(real_bar_pos.x + bars_width, real_bar_pos.y + bars_height), 0.0f);
306 float x =
dyno::clamp((v - v_min) / (v_max - v_min),
float(0),
float(1));
307 float r =
dyno::clamp(
float(-4 * abs(x - 0.75) + 2),
float(0),
float(1));
308 float g =
dyno::clamp(
float(-4 * abs(x - 0.50) + 2),
float(0),
float(1));
309 float b =
dyno::clamp(
float(-4 * abs(x) + 2),
float(0),
float(1));
310 return IM_COL32(r * 255, g * 255, b* 255, 150);
314 float x =
dyno::clamp((v - v_min) / (v_max - v_min),
float(0),
float(1));
315 float r =
dyno::clamp(
float(-4 * abs(x - 0.75) + 1.5),
float(0),
float(1));
316 float g =
dyno::clamp(
float(-4 * abs(x - 0.50) + 1.5),
float(0),
float(1));
317 float b =
dyno::clamp(
float(-4 * abs(x - 0.25) + 1.5),
float(0),
float(1));
318 return IM_COL32(r * 255, g * 255, b* 255, 150);
323 ImGuiStyle& style = ImGui::GetStyle();
324 style.ScaleAllSizes(scale);
325 style.WindowRounding = 7.0f;
326 style.ChildRounding = 7.0f;
327 style.FrameRounding = 7.0f;
328 style.PopupRounding = 7.0f;
330 ImGuiIO& io = ImGui::GetIO();
335 std::string arialPath = getAssetPath() +
"font/arial.ttf";
336 io.Fonts->AddFontFromFileTTF(arialPath.c_str(), 13.0f);
339 config.MergeMode =
true;
340 config.GlyphMinAdvanceX = 13.0f;
343 std::string solidPath = getAssetPath() +
"font/fa-solid-900.ttf";
344 io.Fonts->AddFontFromFileTTF(solidPath.c_str(), 13.0f, &config, icon_ranges);
347 io.FontGlobalScale = scale;
IMGUI_API bool ImageButtonWithText(ImTextureID texId, const char *label, const ImVec2 &imageSize=ImVec2(0, 0), const ImVec2 &uv0=ImVec2(0, 0), const ImVec2 &uv1=ImVec2(1, 1), int frame_padding=-1, const ImVec4 &bg_col=ImVec4(0, 0, 0, 0), const ImVec4 &tint_col=ImVec4(1, 1, 1, 1))