Compare commits
2 Commits
c5328cb9ed
...
3fb220ff54
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fb220ff54 | |||
| 7a3bde6321 |
@@ -119,7 +119,7 @@ i32 main(void) {
|
||||
// draw every 10 ms
|
||||
while (tim_run(60)) {
|
||||
TimCell bg = tim_cell(" ", 0, BG);
|
||||
tim_draw_lot(bg, 0, 0, tim->w, tim->h);
|
||||
tim_fill(bg, 0, 0, tim->w, tim->h);
|
||||
|
||||
if (snek.state == RUN) {
|
||||
game();
|
||||
|
||||
@@ -301,14 +301,10 @@ bool tim_radiobutton(cstr txt, i32* state, i32 v, i32 x, i32 y, i32 w, TimStyle
|
||||
TimKey tim_edit(TimEditState* e, i32 x, i32 y, i32 w, TimStyle style);
|
||||
|
||||
/// @param e uninitialized state
|
||||
/// @param capacity in bytes
|
||||
/// @param buffer an array
|
||||
/// @param capacity buffer size in bytes
|
||||
/// @param initial_content may be NULL
|
||||
void TimEditState_construct(TimEditState* e, i32 capacity, cstr initial_content);
|
||||
|
||||
static inline void TimEditState_destroy(TimEditState* e) {
|
||||
if(!e) return;
|
||||
free(e->s);
|
||||
}
|
||||
void TimEditState_construct(TimEditState* e, char* buffer, i32 capacity, cstr initial_content);
|
||||
|
||||
void TimEditState_insert(TimEditState* e, cstr s);
|
||||
void TimEditState_delete(TimEditState* e);
|
||||
@@ -364,8 +360,8 @@ void tim_draw_row(TimCell cell, i32 x, i32 y, i32 w);
|
||||
// draw column of cells
|
||||
void tim_draw_col(TimCell cell, i32 x, i32 y, i32 h);
|
||||
|
||||
// fill lot (area) of cells
|
||||
void tim_draw_lot(TimCell cell, i32 x, i32 y, i32 w, i32 h);
|
||||
// fill area with cells
|
||||
void tim_fill(TimCell cell, i32 x, i32 y, i32 w, i32 h);
|
||||
|
||||
// draw string to line, tags potential wide characters
|
||||
void tim_draw_str(cstr s, i32 x, i32 y, i32 w, u8 fg, u8 bg);
|
||||
|
||||
@@ -36,7 +36,7 @@ void tim_draw_col(TimCell cell, i32 x, i32 y, i32 h) {
|
||||
}
|
||||
}
|
||||
|
||||
void tim_draw_lot(TimCell cell, i32 x, i32 y, i32 w, i32 h) {
|
||||
void tim_fill(TimCell cell, i32 x, i32 y, i32 w, i32 h) {
|
||||
if (w > 0 && h > 0) {
|
||||
for (i32 iy = MAX(y, 0); iy < MIN(y + h, tim->h); iy++) {
|
||||
for (i32 ix = MAX(x, 0); ix < MIN(x + w, tim->w); ix++) {
|
||||
@@ -71,7 +71,7 @@ void tim_draw_box(i32 x, i32 y, i32 w, i32 h, u8 fg, u8 bg) {
|
||||
tim_draw_row(tim_cell("─", fg, bg), x + 1 , y + h - 1, w - 2);
|
||||
tim_draw_col(tim_cell("│", fg, bg), x , y + 1 , h - 2);
|
||||
tim_draw_col(tim_cell("│", fg, bg), x + w - 1, y + 1 , h - 2);
|
||||
tim_draw_lot(tim_cell(" ", fg, bg), x + 1 , y + 1 , w - 2, h - 2);
|
||||
tim_fill(tim_cell(" ", fg, bg), x + 1 , y + 1 , w - 2, h - 2);
|
||||
}
|
||||
|
||||
void tim_draw_invert(i32 x, i32 y, i32 w) {
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#include "tim.h"
|
||||
|
||||
void TimEditState_construct(TimEditState* e, i32 capacity, cstr initial_content){
|
||||
void TimEditState_construct(TimEditState* e, char* buf, i32 capacity, cstr initial_content){
|
||||
e->masked = false;
|
||||
e->length = initial_content ? tim_utf8_len(initial_content) : 0;
|
||||
e->cursor = e->length;
|
||||
e->capacity = capacity;
|
||||
e->s = (char*)malloc(capacity + 1);
|
||||
i32 byte_len = strlen(initial_content);
|
||||
e->s = buf;
|
||||
i32 byte_len = 0;
|
||||
if(e->length > 0){
|
||||
byte_len = strlen(initial_content);
|
||||
memcpy(e->s, initial_content, byte_len);
|
||||
}
|
||||
e->s[byte_len] = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ void tim_label(cstr s, i32 x, i32 y, i32 w, i32 h, TimStyle style) {
|
||||
h = (h == A) ? t.lines : h;
|
||||
TimRect r = tim_scope_rect_to_absolute(x, y, w, h);
|
||||
TimCell c = tim_cell(" ", style.fg, style.bg);
|
||||
tim_draw_lot(c, r.x, r.y, r.w, r.h);
|
||||
tim_fill(c, r.x, r.y, r.w, r.h);
|
||||
TimLine l = {.s = s, .line = ""};
|
||||
for (i32 i = 0; tim_next_line(&l); i++) {
|
||||
tim_draw_str(l.line, r.x, r.y + i, l.width, c.fg, c.bg);
|
||||
|
||||
@@ -126,8 +126,10 @@ static inline void test_screen(TimEvent* e) {
|
||||
}
|
||||
|
||||
i32 main(void) {
|
||||
TimEditState_construct(&ed1, 32, "Edit 1");
|
||||
TimEditState_construct(&ed2, 32, "");
|
||||
char ed1_buf[32];
|
||||
char ed2_buf[32];
|
||||
TimEditState_construct(&ed1, ed1_buf, ARRAY_SIZE(ed1_buf), "Edit 1");
|
||||
TimEditState_construct(&ed2, ed2_buf, ARRAY_SIZE(ed2_buf), NULL);
|
||||
|
||||
while (tim_run(1.5)) {
|
||||
test_screen(&tim->event);
|
||||
@@ -136,8 +138,5 @@ i32 main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
TimEditState_destroy(&ed1);
|
||||
TimEditState_destroy(&ed2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user