From e5ed27180fcde244b027a04a609bee33c373672f Mon Sep 17 00:00:00 2001 From: Bruno Date: Sun, 24 Jan 2021 10:54:25 +0100 Subject: [PATCH] New buttons and icon modes --- ImGuiToolkit.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++- ImGuiToolkit.h | 14 +++++++----- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 9846f63..6562567 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -124,7 +124,10 @@ void ImGuiToolkit::Icon(int i, int j, bool enabled) ImVec2 uv0( static_cast(i) * 0.05, static_cast(j) * 0.05 ); ImVec2 uv1( uv0.x + 0.05, uv0.y + 0.05 ); - ImVec4 tint_color = ImVec4(1.f,1.f,1.f, enabled ? 1.f : 0.6f); + + ImVec4 tint_color = ImGui::GetStyle().Colors[ImGuiCol_Text]; + if (!enabled) + tint_color.w = 0.6f; ImGui::Image((void*)(intptr_t)textureicons, ImVec2(ImGui::GetTextLineHeightWithSpacing(), ImGui::GetTextLineHeightWithSpacing()), uv0, uv1, tint_color); } @@ -262,6 +265,42 @@ bool ImGuiToolkit::ButtonIconMultistate(std::vector > icons, return ret; } +bool ImGuiToolkit::ComboIcon (std::vector > icons, int* state) +{ + bool ret = false; + Sum id = std::for_each(icons.begin(), icons.end(), Sum()); + ImGui::PushID( id.sum ); + + ImVec2 draw_pos = ImGui::GetCursorScreenPos(); + float w = ImGui::GetTextLineHeight(); + ImGui::SetNextItemWidth(w * 2.8f); + if (ImGui::BeginCombo("##ComboIcon", " ") ) + { + std::vector >::iterator it = icons.begin(); + for(int i = 0 ; it != icons.end(); i++, it++) { + ImGui::PushID( id.sum + i + 1); + ImVec2 pos = ImGui::GetCursorScreenPos(); + // combo selectable item + if ( ImGui::Selectable(" ", i == *state )){ + *state = i; + ret = true; + } + // draw item icon + ImGui::SetCursorScreenPos( pos + ImVec2(w/6.f,0) ); + Icon( (*it).first, (*it).second ); + ImGui::PopID(); + } + ImGui::EndCombo(); + } + + // redraw current ad preview value + ImGui::SetCursorScreenPos(draw_pos + ImVec2(w/9.f,w/9.f)); + Icon(icons[*state].first, icons[*state].second ); + + ImGui::PopID(); + return ret; +} + void ImGuiToolkit::ShowIconsWindow(bool* p_open) { @@ -328,6 +367,21 @@ void ImGuiToolkit::HelpMarker(const char* desc, const char* icon) } } +void ImGuiToolkit::HelpIcon(const char* desc, int i, int j) +{ + ImGuiToolkit::Icon(i, j, false); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGuiToolkit::PushFont(ImGuiToolkit::FONT_DEFAULT); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(desc); + ImGui::PopTextWrapPos(); + ImGui::PopFont(); + ImGui::EndTooltip(); + } +} + // Draws a timeline showing // 1) a cursor at position *time in the range [0 duration] // 2) a line of tick marks indicating time, every step if possible diff --git a/ImGuiToolkit.h b/ImGuiToolkit.h index d42b655..b49a8a6 100644 --- a/ImGuiToolkit.h +++ b/ImGuiToolkit.h @@ -11,21 +11,25 @@ namespace ImGuiToolkit { // Icons from resource icon.dds - void Icon(int i, int j, bool enabled = true); - bool IconButton(int i, int j, const char *tooltips = nullptr); + void Icon (int i, int j, bool enabled = true); + bool IconButton (int i, int j, const char *tooltips = nullptr); bool IconToggle (int i, int j, int i_toggle, int j_toggle, bool* toggle, const char *tooltips[] = nullptr); void ShowIconsWindow(bool* p_open); - // utility buttons + // icon buttons bool ButtonIcon (int i, int j, const char* tooltip = nullptr); bool ButtonIconToggle (int i, int j, int i_toggle, int j_toggle, bool* toggle); bool ButtonIconMultistate (std::vector > icons, int* state); - bool ButtonToggle(const char* label, bool* toggle); + bool ComboIcon (std::vector > icons, int* state); + + // utility buttons + bool ButtonToggle (const char* label, bool* toggle); void ButtonSwitch (const char* label, bool* toggle , const char *help = nullptr); void ButtonOpenUrl (const char* url, const ImVec2& size_arg = ImVec2(0,0)); - void ToolTip (const char* desc); + void ToolTip (const char* desc); void HelpMarker (const char* desc, const char* icon = ICON_FA_QUESTION_CIRCLE); + void HelpIcon (const char* desc, int i, int j); // utility sliders bool TimelineSlider (const char* label, guint64 *time, guint64 start, guint64 end, guint64 step, const float width);