mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	stb_textedit 1.4 fix signed/unsigned warnings
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
// stb_textedit.h - v1.3  - public domain - Sean Barrett
 | 
					// stb_textedit.h - v1.4  - public domain - Sean Barrett
 | 
				
			||||||
// Development of this library was sponsored by RAD Game Tools
 | 
					// Development of this library was sponsored by RAD Game Tools
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// This C header file implements the guts of a multi-line text-editing
 | 
					// This C header file implements the guts of a multi-line text-editing
 | 
				
			||||||
@@ -30,8 +30,9 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
// VERSION HISTORY
 | 
					// VERSION HISTORY
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//   1.3  (2013-06-19) fix mouse clicking to round to nearest char boundary
 | 
					//   1.4  (2014-08-17) fix signed/unsigned warnings
 | 
				
			||||||
//   1.2  (2013-05-27) fix some RAD types that had crept into the new code
 | 
					//   1.3  (2014-06-19) fix mouse clicking to round to nearest char boundary
 | 
				
			||||||
 | 
					//   1.2  (2014-05-27) fix some RAD types that had crept into the new code
 | 
				
			||||||
//   1.1  (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE )
 | 
					//   1.1  (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE )
 | 
				
			||||||
//   1.0  (2012-07-26) improve documentation, initial public release
 | 
					//   1.0  (2012-07-26) improve documentation, initial public release
 | 
				
			||||||
//   0.3  (2012-02-24) bugfixes, single-line mode; insert mode
 | 
					//   0.3  (2012-02-24) bugfixes, single-line mode; insert mode
 | 
				
			||||||
@@ -41,7 +42,7 @@
 | 
				
			|||||||
// ADDITIONAL CONTRIBUTORS
 | 
					// ADDITIONAL CONTRIBUTORS
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//   Ulf Winklemann: move-by-word in 1.1
 | 
					//   Ulf Winklemann: move-by-word in 1.1
 | 
				
			||||||
//   Scott Graham: mouse selectiom bugfix in 1.3
 | 
					//   Scott Graham: mouse selection bugfix in 1.3
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// USAGE
 | 
					// USAGE
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
@@ -445,7 +446,7 @@ static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state
 | 
				
			|||||||
static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
 | 
					static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
 | 
				
			||||||
static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
 | 
					static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
 | 
				
			||||||
static void stb_text_makeundo_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length);
 | 
					static void stb_text_makeundo_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length);
 | 
				
			||||||
static void stb_text_makeundo_insert(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length);
 | 
					static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length);
 | 
				
			||||||
static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length);
 | 
					static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct
 | 
					typedef struct
 | 
				
			||||||
@@ -649,7 +650,7 @@ static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state
 | 
				
			|||||||
   stb_textedit_delete_selection(str,state);
 | 
					   stb_textedit_delete_selection(str,state);
 | 
				
			||||||
   // try to insert the characters
 | 
					   // try to insert the characters
 | 
				
			||||||
   if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) {
 | 
					   if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) {
 | 
				
			||||||
      stb_text_makeundo_insert(str, state, state->cursor, len);
 | 
					      stb_text_makeundo_insert(state, state->cursor, len);
 | 
				
			||||||
      state->cursor += len;
 | 
					      state->cursor += len;
 | 
				
			||||||
      state->has_preferred_x = 0;
 | 
					      state->has_preferred_x = 0;
 | 
				
			||||||
      return 1;
 | 
					      return 1;
 | 
				
			||||||
@@ -684,7 +685,7 @@ retry:
 | 
				
			|||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
               stb_textedit_delete_selection(str,state); // implicity clamps
 | 
					               stb_textedit_delete_selection(str,state); // implicity clamps
 | 
				
			||||||
               if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
 | 
					               if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
 | 
				
			||||||
                  stb_text_makeundo_insert(str, state, state->cursor, 1);
 | 
					                  stb_text_makeundo_insert(state, state->cursor, 1);
 | 
				
			||||||
                  ++state->cursor;
 | 
					                  ++state->cursor;
 | 
				
			||||||
                  state->has_preferred_x = 0;
 | 
					                  state->has_preferred_x = 0;
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
@@ -1007,13 +1008,13 @@ static void stb_textedit_discard_undo(StbUndoState *state)
 | 
				
			|||||||
         int n = state->undo_rec[0].insert_length, i;
 | 
					         int n = state->undo_rec[0].insert_length, i;
 | 
				
			||||||
         // delete n characters from all other records
 | 
					         // delete n characters from all other records
 | 
				
			||||||
         state->undo_char_point = state->undo_char_point - (short) n;  // vsnet05
 | 
					         state->undo_char_point = state->undo_char_point - (short) n;  // vsnet05
 | 
				
			||||||
         memmove(state->undo_char, state->undo_char + n, state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE));
 | 
					         memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE)));
 | 
				
			||||||
         for (i=0; i < state->undo_point; ++i)
 | 
					         for (i=0; i < state->undo_point; ++i)
 | 
				
			||||||
            if (state->undo_rec[i].char_storage >= 0)
 | 
					            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_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;
 | 
					      --state->undo_point;
 | 
				
			||||||
      memmove(state->undo_rec, state->undo_rec+1, state->undo_point*sizeof(state->undo_rec[0]));
 | 
					      memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0])));
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1031,13 +1032,13 @@ static void stb_textedit_discard_redo(StbUndoState *state)
 | 
				
			|||||||
         int n = state->undo_rec[k].insert_length, i;
 | 
					         int n = state->undo_rec[k].insert_length, i;
 | 
				
			||||||
         // delete n characters from all other records
 | 
					         // delete n characters from all other records
 | 
				
			||||||
         state->redo_char_point = state->redo_char_point + (short) n; // vsnet05
 | 
					         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, (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) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE)));
 | 
				
			||||||
         for (i=state->redo_point; i < k; ++i)
 | 
					         for (i=state->redo_point; i < k; ++i)
 | 
				
			||||||
            if (state->undo_rec[i].char_storage >= 0)
 | 
					            if (state->undo_rec[i].char_storage >= 0)
 | 
				
			||||||
               state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05
 | 
					               state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      ++state->redo_point;
 | 
					      ++state->redo_point;
 | 
				
			||||||
      memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (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) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])));
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1203,7 +1204,7 @@ static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
 | 
				
			|||||||
   s->redo_point++;
 | 
					   s->redo_point++;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void stb_text_makeundo_insert(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length)
 | 
					static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
   stb_text_createundo(&state->undostate, where, 0, length);
 | 
					   stb_text_createundo(&state->undostate, where, 0, length);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user