public static void nk_textedit_click(nk_text_edit state, float x, float y, nk_font font, float row_height) { state.Cursor = (int)(nk_textedit_locate_coord(state, (float)(x), (float)(y), font, (float)(row_height))); state.SelectionStart = (int)(state.Cursor); state.SelectionEnd = (int)(state.Cursor); state.HasPreferredX = (byte)(0); }
public static void nk_textedit_clamp(nk_text_edit state) { int n = (int)(state._string_.Len); if (((state).select_start != (state).select_end)) { if ((state.select_start) > (n)) { state.select_start = (int)(n); } if ((state.select_end) > (n)) { state.select_end = (int)(n); } if ((state.select_start) == (state.select_end)) { state.cursor = (int)(state.select_start); } } if ((state.cursor) > (n)) { state.cursor = (int)(n); } }
public static void nk_textedit_text(nk_text_edit state, string text, int total_len) { fixed(char *p = text) { nk_textedit_text(state, text, total_len); } }
public static int nk_textedit_paste(nk_text_edit state, char *ctext, int len) { int glyphs; char *text = ctext; if ((state.mode) == (NkTextEditMode.VIEW)) { return((int)(0)); } nk_textedit_clamp(state); nk_textedit_delete_selection(state); glyphs = (int)(nk_utf_len(ctext, (int)(len))); if ((state._string_.insert_at((int)(state.cursor), text, (int)(len))) != 0) { nk_textedit_makeundo_insert(state, (int)(state.cursor), (int)(glyphs)); state.cursor += (int)(len); state.has_preferred_x = (byte)(0); return((int)(1)); } if ((state.undo.UndoPoint) != 0) { --state.undo.UndoPoint; } return((int)(0)); }
public static void nk_textedit_clamp(nk_text_edit state) { int n = (int)(state.Text.len); if (((state).SelectionStart != (state).SelectionEnd)) { if ((state.SelectionStart) > (n)) { state.SelectionStart = (int)(n); } if ((state.SelectionEnd) > (n)) { state.SelectionEnd = (int)(n); } if ((state.SelectionStart) == (state.SelectionEnd)) { state.Cursor = (int)(state.SelectionStart); } } if ((state.Cursor) > (n)) { state.Cursor = (int)(n); } }
public static float nk_textedit_get_width(nk_text_edit edit, int line_start, int char_id, nk_font font) { StringSegment str = edit.Text.str; str += line_start + char_id; return((float)(font.width(str.CreateSingleCharSegment()))); }
public static void nk_textedit_layout_row(nk_text_edit_row *r, nk_text_edit edit, int line_start_id, float row_height, NkUserFont font) { int glyphs = (int)(0); char *remaining; int len = (int)(edit._string_.Len); fixed(char *str2 = edit._string_.Str) { char *end = str2 + len; char * text = str2 + line_start_id; NkVec2 size = (NkVec2) (nk_text_calculate_text_bounds(font, text, (int)(end - text), (float)(row_height), &remaining, null, &glyphs, true)); r->x0 = (float)(0.0f); r->x1 = (float)(size.x); r->baseline_y_delta = (float)(size.y); r->ymin = (float)(0.0f); r->ymax = (float)(size.y); r->num_chars = (int)(glyphs); } }
public static int nk_textedit_paste(nk_text_edit state, StringSegment ctext) { int glyphs; if ((state.Mode) == (NK_TEXT_EDIT_MODE_VIEW)) { return((int)(0)); } nk_textedit_clamp(state); nk_textedit_delete_selection(state); glyphs = (int)(nk_utf_len(ctext)); if ((state.Text.insert_at((int)(state.Cursor), ctext)) != 0) { nk_textedit_makeundo_insert(state, (int)(state.Cursor), (int)(glyphs)); state.Cursor += ctext.Length; state.HasPreferredX = (byte)(0); return((int)(1)); } if ((state.Undo.undo_point) != 0) { --state.Undo.undo_point; } return((int)(0)); }
public static void nk_textedit_click(nk_text_edit state, float x, float y, NkUserFont font, float row_height) { state.cursor = (int)(nk_textedit_locate_coord(state, (float)(x), (float)(y), font, (float)(row_height))); state.select_start = (int)(state.cursor); state.select_end = (int)(state.cursor); state.has_preferred_x = (byte)(0); }
public static void nk_textedit_free(nk_text_edit state) { if (state == null) { return; } state._string_.Str = string.Empty; }
public static void nk_textedit_find_charpos(nk_text_find *find, nk_text_edit state, int n, int single_line, NkUserFont font, float row_height) { nk_text_edit_row r = new nk_text_edit_row(); int prev_start = (int)(0); int z = (int)(state._string_.Len); int i = (int)(0); int first; nk_zero(&r, (ulong)(sizeof(nk_text_edit_row))); if ((n) == (z)) { nk_textedit_layout_row(&r, state, (int)(0), (float)(row_height), font); if ((single_line) != 0) { find->first_char = (int)(0); find->length = (int)(z); } else { while ((i) < (z)) { prev_start = (int)(i); i += (int)(r.num_chars); nk_textedit_layout_row(&r, state, (int)(i), (float)(row_height), font); } find->first_char = (int)(i); find->length = (int)(r.num_chars); } find->x = (float)(r.x1); find->y = (float)(r.ymin); find->height = (float)(r.ymax - r.ymin); find->prev_first = (int)(prev_start); return; } find->y = (float)(0); for (; ;) { nk_textedit_layout_row(&r, state, (int)(i), (float)(row_height), font); if ((n) < (i + r.num_chars)) { break; } prev_start = (int)(i); i += (int)(r.num_chars); find->y += (float)(r.baseline_y_delta); } find->first_char = (int)(first = (int)(i)); find->length = (int)(r.num_chars); find->height = (float)(r.ymax - r.ymin); find->prev_first = (int)(prev_start); find->x = (float)(r.x0); for (i = (int)(0); (first + i) < (n); ++i) { find->x += (float)(nk_textedit_get_width(state, (int)(first), (int)(i), font)); } }
public static void nk_textedit_undo(nk_text_edit state) { nk_text_undo_state s = state.Undo; nk_text_undo_record u = new nk_text_undo_record(); if ((s.undo_point) == (0)) { return; } u = (nk_text_undo_record)(s.undo_rec[s.undo_point - 1]); fixed(nk_text_undo_record *r2 = s.undo_rec) { var r = r2 + s.redo_point - 1; r->char_storage = (short)(-1); r->insert_length = (short)(u.delete_length); r->delete_length = (short)(u.insert_length); r->where = (int)(u.where); if ((u.delete_length) != 0) { if ((s.undo_char_point + u.delete_length) >= (999)) { r->insert_length = (short)(0); } else { int i; while ((s.undo_char_point + u.delete_length) > (s.redo_char_point)) { nk_textedit_discard_redo(s); if ((s.redo_point) == (99)) { return; } } r = r2 + s.redo_point - 1; r->char_storage = ((short)(s.redo_char_point - u.delete_length)); s.redo_char_point = ((short)(s.redo_char_point - u.delete_length)); for (i = (int)(0); (i) < (u.delete_length); ++i) { s.undo_char[r->char_storage + i] = (char)(state.Text[(int)(u.where + i)]); } } state.Text.remove_at((int)(u.where), (int)(u.delete_length)); } } if ((u.insert_length) != 0) { state.Text.insert_at((int)(u.where), s.undo_char, u.char_storage, (int)(u.insert_length)); s.undo_char_point = ((short)(s.undo_char_point - u.insert_length)); } state.Cursor = (int)((short)(u.where + u.insert_length)); s.undo_point--; s.redo_point--; }
public static float nk_textedit_get_width(nk_text_edit edit, int line_start, int char_id, NkUserFont font) { fixed(char *str2 = edit._string_.Str) { char *str = str2 + line_start + char_id; return((float)(font.Width((NkHandle)(font.Userdata), (float)(font.Height), str, 1))); } }
public static void nk_textedit_sortselection(nk_text_edit state) { if ((state.select_end) < (state.select_start)) { int temp = (int)(state.select_end); state.select_end = (int)(state.select_start); state.select_start = (int)(temp); } }
public static float nk_textedit_get_width(nk_text_edit edit, int line_start, int char_id, nk_user_font font) { fixed(char *str2 = edit._string_.str) { char *str = str2 + line_start + char_id; return((float)(font.width((nk_handle)(font.userdata), (float)(font.height), str, 1))); } }
public static void nk_textedit_init_default(nk_text_edit state) { if (state == null) { return; } nk_textedit_clear_state(state, (int)(NK_TEXT_EDIT_SINGLE_LINE), null); }
public static void nk_textedit_init_default(nk_text_edit state) { if (state == null) { return; } nk_textedit_clear_state(state, (int)(NkTextEditType.SINGLE_LINE), null); }
public static void nk_textedit_init_fixed(nk_text_edit state, void *memory, ulong size) { if (((memory == null)) || (size == 0)) { return; } nk_textedit_clear_state(state, (int)(NkTextEditType.SINGLE_LINE), null); }
public static void nk_textedit_drag(nk_text_edit state, float x, float y, nk_font font, float row_height) { int p = (int)(nk_textedit_locate_coord(state, (float)(x), (float)(y), font, (float)(row_height))); if ((state.SelectionStart) == (state.SelectionEnd)) { state.SelectionStart = (int)(state.Cursor); } state.Cursor = (int)(state.SelectionEnd = (int)(p)); }
public static void nk_textedit_drag(nk_text_edit state, float x, float y, NkUserFont font, float row_height) { int p = (int)(nk_textedit_locate_coord(state, (float)(x), (float)(y), font, (float)(row_height))); if ((state.select_start) == (state.select_end)) { state.select_start = (int)(state.cursor); } state.cursor = (int)(state.select_end = (int)(p)); }
public static void nk_textedit_move_to_first(nk_text_edit state) { if (((state).SelectionStart != (state).SelectionEnd)) { nk_textedit_sortselection(state); state.Cursor = (int)(state.SelectionStart); state.SelectionEnd = (int)(state.SelectionStart); state.HasPreferredX = (byte)(0); } }
public static void nk_textedit_move_to_first(nk_text_edit state) { if (((state).select_start != (state).select_end)) { nk_textedit_sortselection(state); state.cursor = (int)(state.select_start); state.select_end = (int)(state.select_start); state.has_preferred_x = (byte)(0); } }
public static void nk_textedit_undo(nk_text_edit state) { NkTextUndoState s = state.undo; nk_text_undo_record u = new nk_text_undo_record(); nk_text_undo_record *r; if ((s.UndoPoint) == (0)) { return; } u = (nk_text_undo_record)(s.UndoRec[s.UndoPoint - 1]); r = (nk_text_undo_record *)s.UndoRec + s.RedoPoint - 1; r->char_storage = (short)(-1); r->insert_length = (short)(u.delete_length); r->delete_length = (short)(u.insert_length); r->where = (int)(u.where); if ((u.delete_length) != 0) { if ((s.UndoCharPoint + u.delete_length) >= (999)) { r->insert_length = (short)(0); } else { int i; while ((s.UndoCharPoint + u.delete_length) > (s.RedoCharPoint)) { nk_textedit_discard_redo(s); if ((s.RedoPoint) == (99)) { return; } } r = (nk_text_undo_record *)s.UndoRec + s.RedoPoint - 1; r->char_storage = ((short)(s.RedoCharPoint - u.delete_length)); s.RedoCharPoint = ((short)(s.RedoCharPoint - u.delete_length)); for (i = (int)(0); (i) < (u.delete_length); ++i) { s.UndoChar[r->char_storage + i] = (char)(state._string_[(int)(u.where + i)]); } } state._string_.remove_at((int)(u.where), (int)(u.delete_length)); } if ((u.insert_length) != 0) { state._string_.insert_at((int)(u.where), (char *)s.UndoChar + u.char_storage, (int)(u.insert_length)); s.UndoCharPoint = ((short)(s.UndoCharPoint - u.insert_length)); } state.cursor = (int)((short)(u.where + u.insert_length)); s.UndoPoint--; s.RedoPoint--; }
public static void nk_textedit_text(nk_text_edit state, StringSegment text) { int unicode; int glyph_len; int text_len = (int)(0); if (((text.IsNullOrEmpty) || ((state.Mode) == (NK_TEXT_EDIT_MODE_VIEW)))) { return; } glyph_len = (int)(nk_utf_decode(text, &unicode)); while (((text_len) < (text.Length)) && ((glyph_len) != 0)) { if ((unicode) == (127)) { goto next; } if (((unicode) == ('\n')) && ((state.SingleLine) != 0)) { goto next; } if (((state.Filter) != null) && (state.Filter(state, unicode) == 0)) { goto next; } if ((!((state).SelectionStart != (state).SelectionEnd)) && ((state.Cursor) < (state.Text.len))) { if ((state.Mode) == (NK_TEXT_EDIT_MODE_REPLACE)) { nk_textedit_makeundo_replace(state, (int)(state.Cursor), (int)(1), (int)(1)); state.Text.remove_at((int)(state.Cursor), (int)(1)); } if ((state.Text.insert_at((int)(state.Cursor), (text + text_len).CreateSingleCharSegment())) != 0) { ++state.Cursor; state.HasPreferredX = (byte)(0); } } else { nk_textedit_delete_selection(state); if ((state.Text.insert_at((int)(state.Cursor), (text + text_len).CreateSingleCharSegment())) != 0) { nk_textedit_makeundo_insert(state, (int)(state.Cursor), (int)(1)); ++state.Cursor; state.HasPreferredX = (byte)(0); } } next: ; text_len += (int)(glyph_len); glyph_len = (int)(nk_utf_decode(text + text_len, &unicode)); } }
public static int nk_filter_decimal(nk_text_edit box, char unicode) { if ((((unicode) < ('0')) || ((unicode) > ('9'))) && (unicode != '-')) { return((int)(nk_false)); } else { return((int)(nk_true)); } }
public static int nk_filter_ascii(nk_text_edit box, char unicode) { if ((unicode) > (128)) { return((int)(nk_false)); } else { return((int)(nk_true)); } }
public static void nk_textedit_text(nk_text_edit state, char *text, int total_len) { char unicode; int glyph_len; int text_len = (int)(0); if (((text == null) || (total_len == 0)) || ((state.mode) == (NkTextEditMode.VIEW))) { return; } glyph_len = (int)(nk_utf_decode(text, &unicode, (int)(total_len))); while (((text_len) < (total_len)) && ((glyph_len) != 0)) { if ((unicode) == (127)) { goto next; } if (((unicode) == ('\n')) && ((state.single_line) != 0)) { goto next; } if (((state.filter) != null) && (state.filter(state, unicode) == 0)) { goto next; } if ((!((state).select_start != (state).select_end)) && ((state.cursor) < (state._string_.Len))) { if ((state.mode) == (NkTextEditMode.REPLACE)) { nk_textedit_makeundo_replace(state, (int)(state.cursor), (int)(1), (int)(1)); state._string_.remove_at((int)(state.cursor), (int)(1)); } if ((state._string_.insert_at((int)(state.cursor), text + text_len, (int)(1))) != 0) { ++state.cursor; state.has_preferred_x = (byte)(0); } } else { nk_textedit_delete_selection(state); if ((state._string_.insert_at((int)(state.cursor), text + text_len, (int)(1))) != 0) { nk_textedit_makeundo_insert(state, (int)(state.cursor), (int)(1)); ++state.cursor; state.has_preferred_x = (byte)(0); } } next: ; text_len += (int)(glyph_len); glyph_len = (int)(nk_utf_decode(text + text_len, &unicode, (int)(total_len - text_len))); } }
public static int nk_filter_oct(nk_text_edit box, char unicode) { if (((unicode) < ('0')) || ((unicode) > ('7'))) { return((int)(nk_false)); } else { return((int)(nk_true)); } }
public static void nk_textedit_prep_selection_at_cursor(nk_text_edit state) { if (!((state).select_start != (state).select_end)) { state.select_start = (int)(state.select_end = (int)(state.cursor)); } else { state.cursor = (int)(state.select_end); } }
public static int nk_filter_binary(nk_text_edit box, char unicode) { if ((unicode != '0') && (unicode != '1')) { return((int)(nk_false)); } else { return((int)(nk_true)); } }