Added RenderCheckMark() helper following the font size

Pretty ugly, not sure what's the right way to solve that automatically,
better shown as an "icon" so it doesn't have to necessarily look like
the font.
This commit is contained in:
ocornut 2015-05-07 17:06:07 +01:00
parent 13c3f11c66
commit 85b8967291
2 changed files with 21 additions and 1 deletions

View File

@ -501,6 +501,7 @@ static void RenderTextWrapped(ImVec2 pos, const char* text, const char*
static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max);
static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
static void RenderCheckMark(ImVec2 pos);
static void SetFont(ImFont* font);
static bool ItemAdd(const ImRect& bb, const ImGuiID* id);
@ -2528,6 +2529,22 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool
window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text));
}
static void RenderCheckMark(ImVec2 pos)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
float ax = (float)(int)(g.FontSize * 0.307f + 0.5f); // Spacing
float rem_third = (float)(int)((g.FontSize - ax) / 3.0f);
float bx = ax + rem_third;
float cx = ax + rem_third * 3.0f;
float by = (float)(int)(g.Font->BaseLine * (g.FontSize / g.Font->FontSize) + 0.5f) + (float)(int)(g.Font->DisplayOffset.y);
float ay = by - rem_third;
float cy = by - rem_third * 2.0f;
window->DrawList->AddLine(ImVec2(pos.x + ax, pos.y + ay), ImVec2(pos.x + bx, pos.y + by), window->Color(ImGuiCol_Text));
window->DrawList->AddLine(ImVec2(pos.x + bx, pos.y + by), ImVec2(pos.x + cx, pos.y + cy), window->Color(ImGuiCol_Text));
}
// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
// CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize)
ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
@ -8595,6 +8612,7 @@ bool ImFontAtlas::Build()
const float font_scale = stbtt_ScaleForPixelHeight(&data.FontInfo, data.SizePixels);
int font_ascent, font_descent, font_line_gap;
stbtt_GetFontVMetrics(&data.FontInfo, &font_ascent, &font_descent, &font_line_gap);
data.OutFont->BaseLine = (font_ascent * font_scale);
const float uv_scale_x = 1.0f / TexWidth;
const float uv_scale_y = 1.0f / TexHeight;
@ -8754,6 +8772,7 @@ void ImFont::Clear()
{
FontSize = 0.0f;
DisplayOffset = ImVec2(-0.5f, 0.5f);
BaseLine = 0.0f;
ContainerAtlas = NULL;
Glyphs.clear();
FallbackGlyph = NULL;

View File

@ -1018,6 +1018,7 @@ struct ImFont
signed short XOffset, YOffset;
float U0, V0, U1, V1; // Texture coordinates
};
float BaseLine; // Distance from top to bottom of e.g. 'A' [0..FontSize]
ImFontAtlas* ContainerAtlas; // What we has been loaded into
ImVector<Glyph> Glyphs;
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)