Skip to content

Commit ea0da0b

Browse files
committed
Extracted PushPasswordFont() out of InputText code.
1 parent 9c4948a commit ea0da0b

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

imgui_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,6 +3018,7 @@ namespace ImGui
30183018
// Fonts, drawing
30193019
IMGUI_API void SetCurrentFont(ImFont* font);
30203020
inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; }
3021+
IMGUI_API void PushPasswordFont();
30213022
inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { IM_UNUSED(window); return GetForegroundDrawList(); } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches.
30223023
IMGUI_API ImDrawList* GetBackgroundDrawList(ImGuiViewport* viewport); // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
30233024
IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.

imgui_widgets.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,6 +4246,23 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, cons
42464246
BufTextLen += new_text_len;
42474247
}
42484248

4249+
void ImGui::PushPasswordFont()
4250+
{
4251+
ImGuiContext& g = *GImGui;
4252+
ImFont* in_font = g.Font;
4253+
ImFont* out_font = &g.InputTextPasswordFont;
4254+
const ImFontGlyph* glyph = in_font->FindGlyph('*');
4255+
out_font->FontSize = in_font->FontSize;
4256+
out_font->Scale = in_font->Scale;
4257+
out_font->Ascent = in_font->Ascent;
4258+
out_font->Descent = in_font->Descent;
4259+
out_font->ContainerAtlas = in_font->ContainerAtlas;
4260+
out_font->FallbackGlyph = glyph;
4261+
out_font->FallbackAdvanceX = glyph->AdvanceX;
4262+
IM_ASSERT(out_font->Glyphs.Size == 0 && out_font->IndexAdvanceX.Size == 0 && out_font->IndexLookup.Size == 0);
4263+
PushFont(out_font);
4264+
}
4265+
42494266
// Return false to discard a character.
42504267
static bool InputTextFilterCharacter(ImGuiContext* ctx, unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, bool input_source_is_clipboard)
42514268
{
@@ -4656,19 +4673,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
46564673

46574674
// Password pushes a temporary font with only a fallback glyph
46584675
if (is_password && !is_displaying_hint)
4659-
{
4660-
const ImFontGlyph* glyph = g.Font->FindGlyph('*');
4661-
ImFont* password_font = &g.InputTextPasswordFont;
4662-
password_font->FontSize = g.Font->FontSize;
4663-
password_font->Scale = g.Font->Scale;
4664-
password_font->Ascent = g.Font->Ascent;
4665-
password_font->Descent = g.Font->Descent;
4666-
password_font->ContainerAtlas = g.Font->ContainerAtlas;
4667-
password_font->FallbackGlyph = glyph;
4668-
password_font->FallbackAdvanceX = glyph->AdvanceX;
4669-
IM_ASSERT(password_font->Glyphs.empty() && password_font->IndexAdvanceX.empty() && password_font->IndexLookup.empty());
4670-
PushFont(password_font);
4671-
}
4676+
PushPasswordFont();
46724677

46734678
// Process mouse inputs and character inputs
46744679
if (g.ActiveId == id)

0 commit comments

Comments
 (0)