mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-24 00:26:36 +00:00
Fonts: Fixed crash if FontGlobalScale is zero. Correctly debug naming default font if not 13 px. Demo: Moved PopupRounding along with other rounding values. Metrics: Displaying indexes with idx to be correct / less misleading.
This commit is contained in:
parent
c23a19c26f
commit
8e44aacc8e
14
imgui.cpp
14
imgui.cpp
@ -1124,7 +1124,6 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
|
||||
PopupRounding = ImFloor(PopupRounding * scale_factor);
|
||||
FramePadding = ImFloor(FramePadding * scale_factor);
|
||||
FrameRounding = ImFloor(FrameRounding * scale_factor);
|
||||
TabRounding = ImFloor(TabRounding * scale_factor);
|
||||
ItemSpacing = ImFloor(ItemSpacing * scale_factor);
|
||||
ItemInnerSpacing = ImFloor(ItemInnerSpacing * scale_factor);
|
||||
TouchExtraPadding = ImFloor(TouchExtraPadding * scale_factor);
|
||||
@ -1134,6 +1133,7 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
|
||||
ScrollbarRounding = ImFloor(ScrollbarRounding * scale_factor);
|
||||
GrabMinSize = ImFloor(GrabMinSize * scale_factor);
|
||||
GrabRounding = ImFloor(GrabRounding * scale_factor);
|
||||
TabRounding = ImFloor(TabRounding * scale_factor);
|
||||
DisplayWindowPadding = ImFloor(DisplayWindowPadding * scale_factor);
|
||||
DisplaySafeAreaPadding = ImFloor(DisplaySafeAreaPadding * scale_factor);
|
||||
MouseCursorScale = ImFloor(MouseCursorScale * scale_factor);
|
||||
@ -5661,7 +5661,7 @@ void ImGui::SetCurrentFont(ImFont* font)
|
||||
IM_ASSERT(font && font->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
|
||||
IM_ASSERT(font->Scale > 0.0f);
|
||||
g.Font = font;
|
||||
g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
|
||||
g.FontBaseSize = ImMax(1.0f, g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale);
|
||||
g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f;
|
||||
|
||||
ImFontAtlas* atlas = g.Font->ContainerAtlas;
|
||||
@ -9329,16 +9329,18 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
// Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted.
|
||||
ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible.
|
||||
while (clipper.Step())
|
||||
for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
|
||||
for (int prim = clipper.DisplayStart, idx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
|
||||
{
|
||||
char buf[300];
|
||||
char *buf_p = buf, *buf_end = buf + IM_ARRAYSIZE(buf);
|
||||
ImVec2 triangles_pos[3];
|
||||
for (int n = 0; n < 3; n++, vtx_i++)
|
||||
for (int n = 0; n < 3; n++, idx_i++)
|
||||
{
|
||||
ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i];
|
||||
int vtx_i = idx_buffer ? idx_buffer[idx_i] : idx_i;
|
||||
ImDrawVert& v = draw_list->VtxBuffer[vtx_i];
|
||||
triangles_pos[n] = v.pos;
|
||||
buf_p += ImFormatString(buf_p, buf_end - buf_p, "%s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X\n", (n == 0) ? "vtx" : " ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
|
||||
buf_p += ImFormatString(buf_p, buf_end - buf_p, "%s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X\n",
|
||||
(n == 0) ? "idx" : " ", idx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
|
||||
}
|
||||
ImGui::Selectable(buf, false);
|
||||
if (ImGui::IsItemHovered())
|
||||
|
@ -2793,7 +2793,6 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
{
|
||||
ImGui::Text("Main");
|
||||
ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
|
||||
ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 16.0f, "%.0f");
|
||||
ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
|
||||
ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
|
||||
ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
|
||||
@ -2811,6 +2810,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f");
|
||||
@ -2882,7 +2882,8 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
|
||||
if (ImGui::BeginTabItem("Fonts"))
|
||||
{
|
||||
ImFontAtlas* atlas = ImGui::GetIO().Fonts;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImFontAtlas* atlas = io.Fonts;
|
||||
ShowHelpMarker("Read FAQ and misc/fonts/README.txt for details on font loading.");
|
||||
ImGui::PushItemWidth(120);
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
@ -2890,7 +2891,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
ImFont* font = atlas->Fonts[i];
|
||||
ImGui::PushID(font);
|
||||
bool font_details_opened = ImGui::TreeNode(font, "Font %d: \"%s\"\n%.2f px, %d glyphs, %d file(s)", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size, font->ConfigDataCount);
|
||||
ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font;
|
||||
ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) { io.FontDefault = font; }
|
||||
if (font_details_opened)
|
||||
{
|
||||
ImGui::PushFont(font);
|
||||
@ -2955,9 +2956,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
}
|
||||
|
||||
static float window_scale = 1.0f;
|
||||
if (ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f")) // scale only this window
|
||||
if (ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.2f")) // scale only this window
|
||||
ImGui::SetWindowFontScale(window_scale);
|
||||
ImGui::DragFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale everything
|
||||
ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, 0.3f, 2.0f, "%.2f"); // scale everything
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::EndTabItem();
|
||||
|
@ -1592,8 +1592,10 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
|
||||
font_cfg.OversampleH = font_cfg.OversampleV = 1;
|
||||
font_cfg.PixelSnapH = true;
|
||||
}
|
||||
if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, "ProggyClean.ttf, 13px");
|
||||
if (font_cfg.SizePixels <= 0.0f) font_cfg.SizePixels = 13.0f;
|
||||
if (font_cfg.SizePixels <= 0.0f)
|
||||
font_cfg.SizePixels = 13.0f * 1.0f;
|
||||
if (font_cfg.Name[0] == '\0')
|
||||
ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "ProggyClean.ttf, %dpx", (int)font_cfg.SizePixels);
|
||||
|
||||
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
|
||||
const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault();
|
||||
|
Loading…
Reference in New Issue
Block a user