瀏覽代碼

Fixed Clang -Weverything warnings + TODO list entries

ocornut 10 年之前
父節點
當前提交
a31e44b99a
共有 3 個文件被更改,包括 30 次插入27 次删除
  1. 23 19
      imgui.cpp
  2. 3 4
      imgui.h
  3. 4 4
      stb_textedit.h

+ 23 - 19
imgui.cpp

@@ -198,6 +198,7 @@
  - text edit: add multi-line text edit
  - settings: write more decent code to allow saving/loading new fields
  - settings: api for per-tool simple persistent data (bool,int,float) in .ini file
+ - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  - log: be able to right-click and log a window or tree-node into tty/file/clipboard?
  - filters: set a current filter that tree node can automatically query to hide themselves
  - filters: handle wildcards (with implicit leading/trailing *), regexps
@@ -212,6 +213,7 @@
  - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL
  - misc: not thread-safe
  - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
+ - misc: CalcTextSize() could benefit from having 'hide_text_after_double_hash' false by default for external use?
  - style editor: add a button to output C code.
  - examples: integrate dx11 example.
  - examples: integrate opengl 3/4 programmable pipeline example.
@@ -438,7 +440,7 @@ static int ImStricmp(const char* str1, const char* str2)
 
 static int ImStrnicmp(const char* str1, const char* str2, int count)
 {
-    int d;
+    int d = 0;
     while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
     return (count == 0) ? 0 : d;
 }
@@ -725,7 +727,7 @@ struct ImGuiState
     bool                    Initialized;
     ImGuiIO                 IO;
     ImGuiStyle              Style;
-    float                   FontSize;                           // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->GetFontSize(). Vertical distance between two lines of text, aka == CalcTextSize(" ").y
+    float                   FontSize;                           // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->Info->FontSize. Vertical distance between two lines of text, aka == CalcTextSize(" ").y
     ImVec2                  FontTexUvForWhite;                  // == IO.Font->FontTexUvForWhite (cached copy)
 
     float                   Time;
@@ -1369,7 +1371,7 @@ void ImGui::NewFrame()
 
     IM_ASSERT(g.IO.Font && g.IO.Font->IsLoaded());  // Font not loaded
     IM_ASSERT(g.IO.Font->Scale > 0.0f);
-    g.FontSize = g.IO.FontGlobalScale * g.IO.Font->GetFontSize() * g.IO.Font->Scale;
+    g.FontSize = g.IO.FontGlobalScale * (float)g.IO.Font->Info->FontSize * g.IO.Font->Scale;
     g.FontTexUvForWhite = g.IO.Font->TexUvForWhite;
     g.IO.Font->FallbackGlyph = g.IO.Font->FindGlyph(g.IO.Font->FallbackChar);
 
@@ -1803,12 +1805,12 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool sh
 
 // 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_hash, float wrap_width)
+ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
 {
     ImGuiWindow* window = GetCurrentWindow();
 
     const char* text_display_end;
-    if (hide_text_after_hash)
+    if (hide_text_after_double_hash)
         text_display_end = FindTextDisplayEnd(text, text_end);      // Hide anything after a '##' string
     else
         text_display_end = text_end;
@@ -4128,10 +4130,10 @@ static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
 static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
 {
     const size_t text_len = ImStrlenW(obj->Text);
-    if (new_text_len + text_len + 1 >= obj->BufSize)
+    if ((size_t)new_text_len + text_len + 1 >= obj->BufSize)
         return false;
 
-    if (pos != text_len)
+    if (pos != (int)text_len)
         memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
     memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
     obj->Text[text_len + (size_t)new_text_len] = '\0';
@@ -4304,7 +4306,7 @@ bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiIn
 
 // Public API to manipulate UTF-8 text
 // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
-void ImGuiTextEditCallbackData::DeleteChars(size_t pos, size_t bytes_count)
+void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
 {
     char* dst = Buf + pos;
     const char* src = Buf + pos + bytes_count;
@@ -4313,31 +4315,32 @@ void ImGuiTextEditCallbackData::DeleteChars(size_t pos, size_t bytes_count)
     *dst = '\0';
 
     BufDirty = true;
-    if ((size_t)CursorPos + bytes_count >= pos)
+    if (CursorPos + bytes_count >= pos)
         CursorPos -= bytes_count;
-    else if ((size_t)CursorPos >= pos)
+    else if (CursorPos >= pos)
         CursorPos = pos;
     SelectionStart = SelectionEnd = CursorPos;
 }
 
-void ImGuiTextEditCallbackData::InsertChars(size_t pos, const char* new_text, const char* new_text_end)
+void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
 {
     const size_t text_len = strlen(Buf);
     if (!new_text_end)
         new_text_end = new_text + strlen(new_text);
-    const size_t new_text_len = new_text_end - new_text;
+    const size_t new_text_len = (size_t)(new_text_end - new_text);
 
     if (new_text_len + text_len + 1 >= BufSize)
         return;
 
-    if (text_len != pos)
-        memmove(Buf + pos + new_text_len, Buf + pos, text_len - pos);
-    memcpy(Buf + pos, new_text, new_text_len * sizeof(char));
+	size_t upos = (size_t)pos;
+    if (text_len != upos)
+        memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
+    memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
     Buf[text_len + new_text_len] = '\0';
 
     BufDirty = true;
-    if ((size_t)CursorPos >= pos)
-        CursorPos += new_text_len;
+    if (CursorPos >= pos)
+        CursorPos += (int)new_text_len;
     SelectionStart = SelectionEnd = CursorPos;
 }
 
@@ -5796,6 +5799,7 @@ bool    ImFont::LoadFromMemory(const void* data, size_t data_size)
             IM_ASSERT(Kerning == NULL && KerningCount == 0);
             Kerning = (FntKerning*)p;
             KerningCount = block_size / sizeof(FntKerning);
+			break;
         default:
             break;
         }
@@ -7152,7 +7156,7 @@ struct ExampleAppConsole
                 else if (candidates.size() == 1)
                 {
                     // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
-                    data->DeleteChars(word_start - data->Buf, word_end-word_start);
+                    data->DeleteChars(word_start-data->Buf, word_end-word_start);
                     data->InsertChars(data->CursorPos, candidates[0]);
                     data->InsertChars(data->CursorPos, " ");
                 }
@@ -7162,7 +7166,7 @@ struct ExampleAppConsole
                     int match_len = word_end - word_start;
                     while (true)
                     {
-                        char c;
+                        int c = 0;
                         bool all_candidates_matches = true;
                         for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
                         {

+ 3 - 4
imgui.h

@@ -295,7 +295,7 @@ namespace ImGui
     IMGUI_API int           GetFrameCount();
     IMGUI_API const char*   GetStyleColorName(ImGuiCol idx);
     IMGUI_API void          GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
-    IMGUI_API ImVec2        CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_hash = true, float wrap_width = -1.0f);
+    IMGUI_API ImVec2        CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
 
 } // namespace ImGui
 
@@ -619,8 +619,8 @@ struct ImGuiTextEditCallbackData
     void*               UserData;		// What user passed to InputText()
 
     // NB: calling those function loses selection.
-    void DeleteChars(size_t pos, size_t bytes_count);
-    void InsertChars(size_t pos, const char* text, const char* text_end = NULL);
+    void DeleteChars(int pos, int bytes_count);
+    void InsertChars(int pos, const char* text, const char* text_end = NULL);
 };
 
 //-----------------------------------------------------------------------------
@@ -727,7 +727,6 @@ struct ImFont
     IMGUI_API void              Clear();
     IMGUI_API void              BuildLookupTable();
     IMGUI_API const FntGlyph*   FindGlyph(unsigned short c) const;
-    IMGUI_API float             GetFontSize() const { return (float)Info->FontSize; } // before scale!
     IMGUI_API bool              IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
 
     // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.

+ 4 - 4
stb_textedit.h

@@ -1008,13 +1008,13 @@ static void stb_textedit_discard_undo(StbUndoState *state)
          int n = state->undo_rec[0].insert_length, i;
          // delete n characters from all other records
          state->undo_char_point = state->undo_char_point - (short) n;  // vsnet05
-         memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE)));
+         memmove(state->undo_char, state->undo_char + n, (size_t) ((size_t)state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE)));
          for (i=0; i < state->undo_point; ++i)
             if (state->undo_rec[i].char_storage >= 0)
                state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it
       }
       --state->undo_point;
-      memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0])));
+      memmove(state->undo_rec, state->undo_rec+1, (size_t) ((size_t)state->undo_point*sizeof(state->undo_rec[0])));
    }
 }
 
@@ -1032,13 +1032,13 @@ static void stb_textedit_discard_redo(StbUndoState *state)
          int n = state->undo_rec[k].insert_length, i;
          // delete n characters from all other records
          state->redo_char_point = state->redo_char_point + (short) n; // vsnet05
-         memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE)));
+         memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((size_t)(STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE)));
          for (i=state->redo_point; i < k; ++i)
             if (state->undo_rec[i].char_storage >= 0)
                state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05
       }
       ++state->redo_point;
-      memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])));
+      memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((size_t)(STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])));
    }
 }