Browse Source

Internals: Replace unsigned short with ImWchar when dealing with character storage (missing cases) + in imgui_impl_ file keep using neutral type everywhere, added missing explicit cast in three bindings. (#2078)

pull/2078/merge
omar 6 years ago
parent
commit
9cc63ba279
  1. 2
      examples/imgui_impl_freeglut.cpp
  2. 2
      examples/imgui_impl_osx.mm
  3. 4
      imgui_widgets.cpp
  4. 2
      misc/freetype/imgui_freetype.cpp

2
examples/imgui_impl_freeglut.cpp

@ -97,7 +97,7 @@ void ImGui_ImplFreeGLUT_KeyboardFunc(unsigned char c, int x, int y)
//printf("char_down_func %d '%c'\n", c, c); //printf("char_down_func %d '%c'\n", c, c);
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
if (c >= 32) if (c >= 32)
io.AddInputCharacter(c); io.AddInputCharacter((unsigned short)c);
// Store letters in KeysDown[] array as both uppercase and lowercase + Handle GLUT translating CTRL+A..CTRL+Z as 1..26. // Store letters in KeysDown[] array as both uppercase and lowercase + Handle GLUT translating CTRL+A..CTRL+Z as 1..26.
// This is a hacky mess but GLUT is unable to distinguish e.g. a TAB key from CTRL+I so this is probably the best we can do here. // This is a hacky mess but GLUT is unable to distinguish e.g. a TAB key from CTRL+I so this is probably the best we can do here.

2
examples/imgui_impl_osx.mm

@ -188,7 +188,7 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view)
{ {
int c = [str characterAtIndex:i]; int c = [str characterAtIndex:i];
if (c < 0xF700 && !io.KeyCtrl) if (c < 0xF700 && !io.KeyCtrl)
io.AddInputCharacter(c); io.AddInputCharacter((unsigned short)c);
// We must reset in case we're pressing a sequence of special keys while keeping the command pressed // We must reset in case we're pressing a sequence of special keys while keeping the command pressed
int key = mapCharacterToKey(c); int key = mapCharacterToKey(c);

4
imgui_widgets.cpp

@ -2844,7 +2844,7 @@ static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* t
if (c == '\r') if (c == '\r')
continue; continue;
const float char_width = font->GetCharAdvance((unsigned short)c) * scale; const float char_width = font->GetCharAdvance((ImWchar)c) * scale;
line_width += char_width; line_width += char_width;
} }
@ -3697,7 +3697,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
else else
{ {
ImVec2 rect_size = InputTextCalcTextSizeW(p, text_selected_end, &p, NULL, true); ImVec2 rect_size = InputTextCalcTextSizeW(p, text_selected_end, &p, NULL, true);
if (rect_size.x <= 0.0f) rect_size.x = (float)(int)(g.Font->GetCharAdvance((unsigned short)' ') * 0.50f); // So we can see selected empty lines if (rect_size.x <= 0.0f) rect_size.x = (float)(int)(g.Font->GetCharAdvance((ImWchar)' ') * 0.50f); // So we can see selected empty lines
ImRect rect(rect_pos + ImVec2(0.0f, bg_offy_up - g.FontSize), rect_pos +ImVec2(rect_size.x, bg_offy_dn)); ImRect rect(rect_pos + ImVec2(0.0f, bg_offy_up - g.FontSize), rect_pos +ImVec2(rect_size.x, bg_offy_dn));
rect.ClipWith(clip_rect); rect.ClipWith(clip_rect);
if (rect.Overlaps(clip_rect)) if (rect.Overlaps(clip_rect))

2
misc/freetype/imgui_freetype.cpp

@ -337,7 +337,7 @@ bool ImGuiFreeType::BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags)
{ {
for (uint32_t codepoint = in_range[0]; codepoint <= in_range[1]; ++codepoint) for (uint32_t codepoint = in_range[0]; codepoint <= in_range[1]; ++codepoint)
{ {
if (cfg.MergeMode && dst_font->FindGlyphNoFallback((unsigned short)codepoint)) if (cfg.MergeMode && dst_font->FindGlyphNoFallback((ImWchar)codepoint))
continue; continue;
FT_Glyph ft_glyph = NULL; FT_Glyph ft_glyph = NULL;

Loading…
Cancel
Save