Fix iconic button sizes on widgets (paint modes and gcode viewer buttons) (#13365)

* init

* update
This commit is contained in:
yw4z
2026-05-05 19:07:15 +03:00
committed by GitHub
parent 1433521f98
commit c2ac0baa05
7 changed files with 145 additions and 98 deletions

View File

@@ -908,6 +908,54 @@ bool ImGuiWrapper::button(const wxString& label, const ImVec2 &size, bool enable
return (enable) ? res : false;
}
// ORCA Glyph based button for correctly rendering icon size based Glyph
// excludes spacings after Glyph and centers icon properly
// compared to image_button this supports styling
bool ImGuiWrapper::glyph_button(wchar_t icon_char, ImVec2 icon_size)
{
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImFont* font = ImGui::GetFont();
ImGuiStyle& style = ImGui::GetStyle();
ImVec2 padding = style.FramePadding;
float border_w = style.FrameBorderSize;
float rounding = style.FrameRounding;
std::string icon_str = into_u8(icon_char);
const char* icon = icon_str.c_str();
float width = icon_size.x + (padding.x + border_w) * 2.f;
float height = icon_size.y + (padding.y + border_w) * 2.f;
ImVec2 rc_min = ImGui::GetCursorScreenPos();
ImVec2 rc_max = ImVec2(rc_min.x + width, rc_min.y + height);
ImGui::Dummy(ImVec2(width, height));
ImGuiCol bg_color = ImGuiCol_Button;
ImGuiCol border_color = ImGuiCol_Border;
bool clicked = false;
if (ImGui::IsMouseHoveringRect(rc_min, rc_max)) {
bg_color = ImGuiCol_ButtonHovered;
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
bg_color = ImGuiCol_ButtonActive;
border_color = ImGuiCol_BorderShadow;
clicked = true;
}
}
draw_list->AddRectFilled(rc_min, rc_max, ImGui::GetColorU32(bg_color), rounding);
if (border_w > 0.f)
draw_list->AddRect(rc_min, rc_max, ImGui::GetColorU32(border_color), rounding, 0, border_w);
ImVec2 text_pos = ImVec2(
rc_min.x + (width - font->FontSize) * .5f,
rc_min.y + (height - font->FontSize) * .5f
);
draw_list->AddText(font, font->FontSize, text_pos, ImGui::GetColorU32(ImGuiCol_Text), icon);
return clicked;
}
bool ImGuiWrapper::radio_button(const wxString &label, bool active)
{
auto label_utf8 = into_u8(label);