mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Internals: Menus: minor tidying up + renaming in ImGuiMenuColumns + removing extraneous offset field which is always zero + using smaller types.
sizeof() 36 -> 20
This commit is contained in:
parent
baa4caf9e3
commit
3512f2c2c2
@ -6266,7 +6266,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f);
|
window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f);
|
||||||
|
|
||||||
window->DC.MenuBarAppending = false;
|
window->DC.MenuBarAppending = false;
|
||||||
window->DC.MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user);
|
window->DC.MenuColumns.Update(style.ItemSpacing.x, window_just_activated_by_user);
|
||||||
window->DC.TreeDepth = 0;
|
window->DC.TreeDepth = 0;
|
||||||
window->DC.TreeJumpToParentOnPopMask = 0x00;
|
window->DC.TreeJumpToParentOnPopMask = 0x00;
|
||||||
window->DC.ChildWindows.resize(0);
|
window->DC.ChildWindows.resize(0);
|
||||||
|
@ -1168,7 +1168,7 @@ static void ShowDemoWindowWidgets()
|
|||||||
{
|
{
|
||||||
static bool selected[10] = {};
|
static bool selected[10] = {};
|
||||||
|
|
||||||
if (ImGui::BeginTable("split1", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings))
|
if (ImGui::BeginTable("split1", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
@ -1179,8 +1179,8 @@ static void ShowDemoWindowWidgets()
|
|||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
ImGui::Separator();
|
ImGui::Spacing();
|
||||||
if (ImGui::BeginTable("split2", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings))
|
if (ImGui::BeginTable("split2", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
|
@ -1035,14 +1035,15 @@ struct IMGUI_API ImGuiGroupData
|
|||||||
// Simple column measurement, currently used for MenuItem() only.. This is very short-sighted/throw-away code and NOT a generic helper.
|
// Simple column measurement, currently used for MenuItem() only.. This is very short-sighted/throw-away code and NOT a generic helper.
|
||||||
struct IMGUI_API ImGuiMenuColumns
|
struct IMGUI_API ImGuiMenuColumns
|
||||||
{
|
{
|
||||||
float Spacing;
|
ImU32 TotalWidth;
|
||||||
float Width, NextWidth;
|
ImU32 NextTotalWidth;
|
||||||
float Pos[3], NextWidths[3];
|
ImU16 Spacing;
|
||||||
|
ImU16 Offsets[2]; // Offset of: Shortcut, Check mark (locked in Update)
|
||||||
|
ImU16 Widths[3]; // Width of: Label, Shortcut, Check mark (accumulator for current frame)
|
||||||
|
|
||||||
ImGuiMenuColumns() { memset(this, 0, sizeof(*this)); }
|
ImGuiMenuColumns() { memset(this, 0, sizeof(*this)); }
|
||||||
void Update(int count, float spacing, bool clear);
|
void Update(float spacing, bool window_reappearing);
|
||||||
float DeclColumns(float w0, float w1, float w2);
|
float DeclColumns(float w_label, float w_shortcut, float w_checkmark);
|
||||||
float CalcExtraSpace(float avail_w) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internal state of the currently focused/edited text input box
|
// Internal state of the currently focused/edited text input box
|
||||||
|
@ -6591,38 +6591,32 @@ void ImGui::Value(const char* prefix, float v, const char* float_format)
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helpers for internal use
|
// Helpers for internal use
|
||||||
void ImGuiMenuColumns::Update(int count, float spacing, bool clear)
|
void ImGuiMenuColumns::Update(float spacing, bool window_reappearing)
|
||||||
{
|
{
|
||||||
IM_ASSERT(count == IM_ARRAYSIZE(Pos));
|
if (window_reappearing)
|
||||||
IM_UNUSED(count);
|
memset(Widths, 0, sizeof(Widths));
|
||||||
Width = NextWidth = 0.0f;
|
TotalWidth = NextTotalWidth = 0;
|
||||||
Spacing = spacing;
|
Spacing = (ImU16)spacing;
|
||||||
if (clear)
|
for (int i = 0; i < IM_ARRAYSIZE(Widths); i++)
|
||||||
memset(NextWidths, 0, sizeof(NextWidths));
|
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(Pos); i++)
|
|
||||||
{
|
{
|
||||||
if (i > 0 && NextWidths[i] > 0.0f)
|
if (i > 0 && Widths[i] > 0)
|
||||||
Width += Spacing;
|
TotalWidth += Spacing;
|
||||||
Pos[i] = IM_FLOOR(Width);
|
if (i > 0)
|
||||||
Width += NextWidths[i];
|
Offsets[i - 1] = (ImU16)TotalWidth;
|
||||||
NextWidths[i] = 0.0f;
|
TotalWidth += Widths[i];
|
||||||
|
Widths[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ImGuiMenuColumns::DeclColumns(float w0, float w1, float w2) // not using va_arg because they promote float to double
|
float ImGuiMenuColumns::DeclColumns(float w_label, float w_shortcut, float w_checkmark)
|
||||||
{
|
{
|
||||||
NextWidth = 0.0f;
|
Widths[0] = ImMax(Widths[0], (ImU16)w_label);
|
||||||
NextWidths[0] = ImMax(NextWidths[0], w0);
|
Widths[1] = ImMax(Widths[1], (ImU16)w_shortcut);
|
||||||
NextWidths[1] = ImMax(NextWidths[1], w1);
|
Widths[2] = ImMax(Widths[2], (ImU16)w_checkmark);
|
||||||
NextWidths[2] = ImMax(NextWidths[2], w2);
|
NextTotalWidth = 0;
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(Pos); i++)
|
for (int i = 0; i < IM_ARRAYSIZE(Widths); i++)
|
||||||
NextWidth += NextWidths[i] + ((i > 0 && NextWidths[i] > 0.0f) ? Spacing : 0.0f);
|
NextTotalWidth += Widths[i] + ((i > 0 && Widths[i] > 0) ? Spacing : 0);
|
||||||
return ImMax(Width, NextWidth);
|
return (float)ImMax(TotalWidth, NextTotalWidth);
|
||||||
}
|
|
||||||
|
|
||||||
float ImGuiMenuColumns::CalcExtraSpace(float avail_w) const
|
|
||||||
{
|
|
||||||
return ImMax(0.0f, avail_w - Width);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Provided a rectangle perhaps e.g. a BeginMenuBarEx() could be used anywhere..
|
// FIXME: Provided a rectangle perhaps e.g. a BeginMenuBarEx() could be used anywhere..
|
||||||
@ -6835,7 +6829,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
|||||||
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w);
|
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w);
|
||||||
pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_SpanAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(min_w, 0.0f));
|
pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_SpanAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(min_w, 0.0f));
|
||||||
ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
|
ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
|
||||||
RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right);
|
RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Offsets[1] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool hovered = enabled && ItemHoverable(window->DC.LastItemRect, id);
|
const bool hovered = enabled && ItemHoverable(window->DC.LastItemRect, id);
|
||||||
@ -6988,11 +6982,11 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo
|
|||||||
if (shortcut_w > 0.0f)
|
if (shortcut_w > 0.0f)
|
||||||
{
|
{
|
||||||
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
|
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
|
||||||
RenderText(pos + ImVec2(window->DC.MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false);
|
RenderText(pos + ImVec2(window->DC.MenuColumns.Offsets[0] + extra_w, 0.0f), shortcut, NULL, false);
|
||||||
PopStyleColor();
|
PopStyleColor();
|
||||||
}
|
}
|
||||||
if (selected)
|
if (selected)
|
||||||
RenderCheckMark(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f);
|
RenderCheckMark(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Offsets[1] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMGUI_TEST_ENGINE_ITEM_INFO(window->DC.LastItemId, label, window->DC.LastItemStatusFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0));
|
IMGUI_TEST_ENGINE_ITEM_INFO(window->DC.LastItemId, label, window->DC.LastItemStatusFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0));
|
||||||
|
Loading…
Reference in New Issue
Block a user