mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-11 14:33:04 +00:00
Fix iconic button sizes on widgets (paint modes and gcode viewer buttons) (#13365)
* init * update
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user