Skip to content
Myr

Merge branch 'textedit'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parents b5336df, d4d046b · Browse files · 3 files+14 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+14 added−7 removed

  • tests:+2 added−1 removed
  • other:+12 added−6 removed

3 files+14 added−7 removed

modified:tests/textedit_sample.c+2 added-1 removed
46 unmodified lines
47}4849// define all the #defines needed 5051#define KEYDOWN_BIT 0x8000000051#define KEYDOWN_BIT 0x800000005253#define STB_TEXTEDIT_STRINGLEN(tc) ((tc)->stringlen)54#define STB_TEXTEDIT_LAYOUTROW layout_func55#define STB_TEXTEDIT_GETWIDTH(tc,n,i) (1) // quick hack for monospaced56#define STB_TEXTEDIT_KEYTOTEXT(key) (((key) & KEYDOWN_BIT) ? 0 : (key))
28 unmodified lines
modified:README.md+1 added-1 removed
modified:stb_textedit.h+11 added-5 removed
1// stb_textedit.h - v1.2 - public domain - Sean Barrett1// stb_textedit.h - v1.3 - public domain - Sean Barrett2// Development of this library was sponsored by RAD Game Tools3//4// This C header file implements the guts of a multi-line text-editing5// widget; you implement display, word-wrapping, and low-level string
23 unmodified lines
29//30//31// VERSION HISTORY32//33// 1.3 (2013-06-19) fix mouse clicking to round to nearest char boundary34// 1.2 (2013-05-27) fix some RAD types that had crept into the new code35// 1.1 (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE )36// 1.0 (2012-07-26) improve documentation, initial public release37// 0.3 (2012-02-24) bugfixes, single-line mode; insert mode
2 unmodified lines
40//41// ADDITIONAL CONTRIBUTORS42//43// Ulf Winklemann: move-by-word in 1.144// Scott Graham: mouse selectiom bugfix in 1.345//46// USAGE47//48// This file behaves differently depending on what symbols you define
57 unmodified lines
106//107// STB_TEXTEDIT_STRINGLEN(obj) the length of the string (ideally O(1))108// STB_TEXTEDIT_LAYOUTROW(&r,obj,n) returns the results of laying out a line of characters109// starting from character #n (see discussion below)108// STB_TEXTEDIT_GETWIDTH(obj,n,i) returns the pixel delta from the xpos of the i-1'th109// character to the i'th char for a line of characters110// STB_TEXTEDIT_GETWIDTH(obj,n,i) returns the pixel delta from the xpos of the i'th character111// to the xpos of the i+1'th char for a line of characters112// starting at character #n (i.e. accounts for kerning113// with previous char)114// STB_TEXTEDIT_KEYTOTEXT(k) maps a keyboard input to an insertable character115// (return type is int, -1 means not valid to insert)
285 unmodified lines
401 k = i;402 prev_x = r.x0;403 for (i=0; i < r.num_chars; ++i) {404 float w = STB_TEXTEDIT_GETWIDTH(str, k, i);403 if (x < prev_x+w)404 return k+i;405 if (x < prev_x+w) {406 if (x < prev_x+w/2)407 return k+i;408 else409 return k+i+1;410 }411 prev_x += w;412 }413 // shouldn't happen, but if it does, fall through to end-of-line case414 }
839 unmodified lines