Skip to content

Commit

Permalink
update to latest menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pa1n-dev committed May 6, 2024
1 parent 297121a commit 242ef2e
Show file tree
Hide file tree
Showing 10 changed files with 24,966 additions and 59 deletions.
2 changes: 1 addition & 1 deletion showcase/imgui.js

Large diffs are not rendered by default.

Binary file modified showcase/imgui.wasm
Binary file not shown.
22 changes: 17 additions & 5 deletions showcase/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3219,7 +3219,7 @@ const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end)
// Internal ImGui functions to render text
// RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash)
{
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;

Expand Down Expand Up @@ -5340,11 +5340,23 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
float space_sz = 5.f;
ImVec2 label_size = CalcTextSize(name);

RenderFrame(parent_window->DC.CursorPos + ImVec2(0.f, space_sz), parent_window->DC.CursorPos + size, GetColorU32(ImGuiCol_ChildBg), false, 0.f);
RenderText(parent_window->DC.CursorPos + ImVec2(20.f, space_sz - (label_size.y / 2)), name);
if (name)
{
PushStyleVar(ImGuiStyleVar_Alpha, 1.f);
RenderFrame(parent_window->DC.CursorPos + ImVec2(0.f, space_sz), parent_window->DC.CursorPos + size, GetColorU32(ImGuiCol_ChildBg), false, 0.f);
PopStyleVar();

RenderText(parent_window->DC.CursorPos + ImVec2(20.f, space_sz - (label_size.y / 2)), name);
SetCursorPosY(GetCursorPosY() + space_sz + (label_size.y / 2) + g.Style.ItemSpacing.y + g.Style.FramePadding.y * 2);
Indent(10.f);
}
else
{
PushStyleVar(ImGuiStyleVar_Alpha, 1.f);
RenderFrame(parent_window->DC.CursorPos, parent_window->DC.CursorPos + size, GetColorU32(ImGuiCol_ChildBg), false, 0.f);
PopStyleVar();
}

ImGui::SetCursorPosY(ImGui::GetCursorPosY() + space_sz + (label_size.y / 2) + g.Style.ItemSpacing.y + g.Style.FramePadding.y * 2);
ImGui::Indent(10.f);

return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions showcase/imgui/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,8 @@ enum ImGuiBackendFlags_
enum ImGuiCol_
{
ImGuiCol_Text,
ImGuiCol_TextHovered,
ImGuiCol_TextActive,
ImGuiCol_TextDisabled,
ImGuiCol_WindowBg, // Background of normal windows
ImGuiCol_ChildBg, // Background of child windows
Expand Down
4 changes: 2 additions & 2 deletions showcase/imgui/imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ struct IMGUI_API ImRect
};

// Helper: ImBitArray
#define IM_BITARRAY_TESTBIT(_ARRAY, _N) ((_ARRAY[(_N) >> 5] & ((ImU32)1 << ((_N) & 31))) != 0) // Macro version of ImBitArrayTestBit(): ensure args have side-effect or are costly!
#define IM_BITARRAY_CLEARBIT(_ARRAY, _N) ((_ARRAY[(_N) >> 5] &= ~((ImU32)1 << ((_N) & 31)))) // Macro version of ImBitArrayClearBit(): ensure args have side-effect or are costly!
#define IM_BITARRAY_TESTBIT(_ARRAY, _N) ((_ARRAY[(_N) >> 5] & ((ImU32)1 << ((_N) & 31))) != 0) // Macro version of ImBitArrayTestBit(): ensure args have side-effect or are costly!
#define IM_BITARRAY_CLEARBIT(_ARRAY, _N) ((_ARRAY[(_N) >> 5] &= ~((ImU32)1 << ((_N) & 31)))) // Macro version of ImBitArrayClearBit(): ensure args have side-effect or are costly!
inline size_t ImBitArrayGetStorageSizeInBytes(int bitcount) { return (size_t)((bitcount + 31) >> 5) << 2; }
inline void ImBitArrayClearAllBits(ImU32* arr, int bitcount){ memset(arr, 0, ImBitArrayGetStorageSizeInBytes(bitcount)); }
inline bool ImBitArrayTestBit(const ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); return (arr[n >> 5] & mask) != 0; }
Expand Down
27 changes: 17 additions & 10 deletions showcase/imgui/imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ bool ImGui::Checkbox(const char* label, bool* v)
tab_map_item->second.frame = ImLerp(tab_map_item->second.frame, *v ? (ImVec4)(ImColor)GetColorU32(ImGuiCol_FrameBgActive) : hovered ? (ImVec4)(ImColor)GetColorU32(ImGuiCol_FrameBgHovered) : (ImVec4)(ImColor)GetColorU32(ImGuiCol_FrameBg), std::min(1.0f, g.IO.DeltaTime * 8.f));

RenderFrame(check_bb.Min, check_bb.Max, GetColorU32(tab_map_item->second.frame.Value), false, 0.f);
//window->DrawList->AddRect(check_bb.Min, check_bb.Max, tab_map_item->second.frame, 0.f, 0, 1.f);

if (label_size.x > 0.0f)
RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + (square_sz / 2) - (label_size.y / 2)), label);
Expand Down Expand Up @@ -1720,8 +1721,9 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF
IM_ASSERT((flags & (ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_NoPreview)) != (ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_NoPreview)); // Can't use both flags together

const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImVec2 preview_label_size = CalcTextSize(label, NULL, true);
const float w = GetColumnWidth();
const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w - 10.f, style.ItemInnerSpacing.y * 2 + label_size.y * 2 + style.FramePadding.y));
const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w - 10.f, style.ItemInnerSpacing.y * 3 + preview_label_size.y + (label_size.x > 0 ? label_size.y + style.FramePadding.y : 0)));

ItemSize(total_bb, style.FramePadding.y);
if (!ItemAdd(total_bb, id))
Expand Down Expand Up @@ -1761,7 +1763,7 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF
if (label_size.x > 0)
RenderText(total_bb.Min, label);

ImRect frame = ImRect(ImVec2(total_bb.Min.x, total_bb.Min.y + style.ItemInnerSpacing.y + label_size.y), total_bb.Max);
ImRect frame = ImRect(ImVec2(total_bb.Min.x, total_bb.Min.y + (label_size.x > 0 ? label_size.y + style.FramePadding.y : 0)), ImVec2(total_bb.Max.x, total_bb.Max.y - style.FramePadding.y));

if (!(flags & ImGuiComboFlags_NoPreview))
window->DrawList->AddRectFilled(frame.Min, frame.Max, tab_map_item->second.frame, style.FrameRounding);
Expand Down Expand Up @@ -5049,7 +5051,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
}

if (label_size.x > 0)
RenderText(ImVec2(total_bb.Min.x, total_bb.Min.y + style.FramePadding.y), label);
RenderText(total_bb.Min, label);

if (value_changed && !(flags & ImGuiInputTextFlags_NoMarkEdited))
MarkItemEdited(id);
Expand Down Expand Up @@ -8306,11 +8308,11 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
}
IM_ASSERT(!(flags & ImGuiTabItemFlags_Button)); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead!

ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0));
PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0));

bool ret = TabItemEx(tab_bar, label, p_open, flags, NULL);

ImGui::PopStyleVar();
PopStyleVar();

if (ret)
{
Expand All @@ -8325,7 +8327,7 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
for (auto& tab_map_item : tab_map)
{
if (tab_map_item.first != tab_bar->SelectedTabId)
tab_map_item.second.frame = 0.f;
tab_map_item.second.frame = 0.5f;
}

auto tab_map_item = tab_map.find(tab->ID);
Expand All @@ -8335,9 +8337,10 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
tab_map_item = tab_map.find(tab->ID);
}

tab_map_item->second.frame = ImLerp(tab_map_item->second.frame, tab_bar->SelectedTabId == tab->ID ? 1.f : 0.f, std::min(1.0f, g.IO.DeltaTime * 8.f));
tab_map_item->second.frame = ImLerp(tab_map_item->second.frame, tab_bar->SelectedTabId == tab->ID ? 1.f : 0.f, std::min(1.0f, g.IO.DeltaTime * 3.5f));

ImGui::PushStyleVar(ImGuiStyleVar_Alpha, tab_map_item->second.frame);
PushStyleVar(ImGuiStyleVar_Alpha, tab_map_item->second.frame);
PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_TextActive));

if (!(flags & ImGuiTabItemFlags_NoPushId))
PushOverrideID(tab->ID);
Expand All @@ -8364,7 +8367,8 @@ void ImGui::EndTabItem()
if (!(tab->Flags & ImGuiTabItemFlags_NoPushId))
PopID();

ImGui::PopStyleVar();
PopStyleVar();
PopStyleColor();
}

bool ImGui::TabItemButton(const char* label, ImGuiTabItemFlags flags)
Expand Down Expand Up @@ -8567,6 +8571,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
struct tab_animation
{
ImColor frame;
ImColor text;
};

static std::map<ImGuiID, tab_animation> tab_map;
Expand All @@ -8577,11 +8582,13 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
tab_map_item = tab_map.find(id);

tab_map_item->second.frame = (ImColor)GetColorU32(ImGuiCol_FrameBg);
tab_map_item->second.text = (ImColor)GetColorU32(ImGuiCol_Text);
}

tab_map_item->second.frame = ImLerp(tab_map_item->second.frame.Value, tab_bar->SelectedTabId == id ? (ImVec4)(ImColor)GetColorU32(ImGuiCol_FrameBgActive) : held || hovered ? (ImVec4)(ImColor)GetColorU32(ImGuiCol_FrameBgHovered) : (ImVec4)(ImColor)GetColorU32(ImGuiCol_FrameBg), std::min(1.0f, g.IO.DeltaTime * 8.f));
tab_map_item->second.text = ImLerp(tab_map_item->second.text.Value, tab_bar->SelectedTabId == id ? (ImVec4)(ImColor)GetColorU32(ImGuiCol_TextActive) : held || hovered ? (ImVec4)(ImColor)GetColorU32(ImGuiCol_TextHovered) : (ImVec4)(ImColor)GetColorU32(ImGuiCol_Text), std::min(1.0f, g.IO.DeltaTime * 8.f));

window->DrawList->AddText(ImVec2(bb.GetCenter().x - (label_size.x / 2), bb.GetCenter().y - (label_size.y / 2) - 2.f), GetColorU32(ImGuiCol_Text), label);
window->DrawList->AddText(ImVec2(bb.GetCenter().x - (label_size.x / 2), bb.GetCenter().y - (label_size.y / 2) - 2.f), tab_map_item->second.text, label);
window->DrawList->AddRectFilled(ImVec2(bb.Min.x, bb.Max.y - 2.f), bb.Max, tab_map_item->second.frame, 0.f);

// Select with right mouse button. This is so the common idiom for context menu automatically highlight the current widget.
Expand Down
Loading

0 comments on commit 242ef2e

Please sign in to comment.