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
Provenance
- Commit
2452f00- Tree
908e456- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent 1
b5336df- Parent 2
d4d046b
3 files changed+14 added−7 removed
modified:tests/textedit_sample.c+2 added-1 removed
46 unmodified lines47 }48 49 // define all the #defines needed 50 51-#define KEYDOWN_BIT 0x8000000051+#define KEYDOWN_BIT 0x8000000052+53 #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 linesmodified:README.md+1 added-1 removed
8 unmodified lines910111213131415161766 unmodified lines8 unmodified lines**stb_image.h** | 1.39 | graphics | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC**stb_truetype.h** | 0.8 | graphics | parse, decode, and rasterize characters from truetype fonts**stb_image_write.h** | 0.94 | graphics | image writing to disk: PNG, TGA, BMP**stretchy_buffer.h** | 1.01 | utility | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++**stb_textedit.h** | 1.2 | UI | guts of a text editor for games etc implementing them from scratch**stb_textedit.h** | 1.3 | UI | guts of a text editor for games etc implementing them from scratch**stb_dxt.h** | 1.04 | 3D graphics | Fabian "ryg" Giesen's real-time DXT compressor**stb_perlin.h** | 0.2 | 3D graphics | revised Perlin noise (3D input, 1D output)**stb_c_lexer.h** | 0.06 | parsing | simplify writing parsers for C-like languages**stb_divide.h** | 0.91 | math | more useful 32-bit modulus e.g. "euclidean divide"66 unmodified linesmodified: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 string23 unmodified lines29 //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 mode2 unmodified lines40 //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 define57 unmodified lines106 //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 lines401 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