Updated ImGui.

This commit is contained in:
Branimir Karadžić 2017-10-22 17:53:32 -07:00
parent dd6d503195
commit 16726de640
4 changed files with 37 additions and 23 deletions

View File

@ -9083,23 +9083,38 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo
return false;
ImGuiContext& g = *GImGui;
ImGuiStyle& style = g.Style;
ImVec2 pos = window->DC.CursorPos;
ImVec2 label_size = CalcTextSize(label, NULL, true);
ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f);
float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w);
bool pressed = Selectable(label, false, ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DrawFillAvailWidth | (enabled ? 0 : ImGuiSelectableFlags_Disabled), ImVec2(w, 0.0f));
if (shortcut_size.x > 0.0f)
ImGuiSelectableFlags flags = ImGuiSelectableFlags_MenuItem | (enabled ? 0 : ImGuiSelectableFlags_Disabled);
bool pressed;
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
{
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false);
PopStyleColor();
// Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful
// Note that in this situation we render neither the shortcut neither the selected tick mark
float w = label_size.x;
window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f);
PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f);
pressed = Selectable(label, false, flags, ImVec2(w, 0.0f));
PopStyleVar();
window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar().
}
else
{
ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f);
float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w);
pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(w, 0.0f));
if (shortcut_size.x > 0.0f)
{
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false);
PopStyleColor();
}
if (selected)
RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * (0.20f+0.200f), g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f);
}
if (selected)
RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * (0.20f+0.200f), g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f);
return pressed;
}

View File

@ -1503,7 +1503,7 @@ struct ImFont
// Methods
IMGUI_API ImFont();
IMGUI_API ~ImFont();
IMGUI_API void Clear();
IMGUI_API void ClearOutputData();
IMGUI_API void BuildLookupTable();
IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const;
IMGUI_API void SetFallbackChar(ImWchar c);

View File

@ -1951,6 +1951,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
for (int i = 0; i < atlas->Fonts.Size; i++)
{
ImFont* font = atlas->Fonts[i];
ImGui::PushID(font);
bool font_details_opened = ImGui::TreeNode(font, "Font %d: \'%s\', %.2f px, %d glyphs", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size);
ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font;
if (font_details_opened)
@ -2011,6 +2012,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
}
ImGui::TreePop();
}
ImGui::PopID();
}
static float window_scale = 1.0f;
ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this window

View File

@ -1579,7 +1579,6 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
const float off_x = cfg.GlyphOffset.x;
const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f);
dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable()
for (int i = 0; i < tmp.RangesCount; i++)
{
stbtt_pack_range& range = tmp.Ranges[i];
@ -1621,14 +1620,12 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f
{
if (!font_config->MergeMode)
{
font->ContainerAtlas = atlas;
font->ConfigData = font_config;
font->ConfigDataCount = 0;
font->ClearOutputData();
font->FontSize = font_config->SizePixels;
font->ConfigData = font_config;
font->ContainerAtlas = atlas;
font->Ascent = ascent;
font->Descent = descent;
font->Glyphs.resize(0);
font->MetricsTotalSurface = 0;
}
font->ConfigDataCount++;
}
@ -1905,7 +1902,8 @@ ImFont::ImFont()
{
Scale = 1.0f;
FallbackChar = (ImWchar)'?';
Clear();
DisplayOffset = ImVec2(0.0f, 1.0f);
ClearOutputData();
}
ImFont::~ImFont()
@ -1918,13 +1916,12 @@ ImFont::~ImFont()
if (g.Font == this)
g.Font = NULL;
*/
Clear();
ClearOutputData();
}
void ImFont::Clear()
void ImFont::ClearOutputData()
{
FontSize = 0.0f;
DisplayOffset = ImVec2(0.0f, 1.0f);
Glyphs.clear();
IndexAdvanceX.clear();
IndexLookup.clear();