mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

commit fc03b528f85e86e937e46897242f5868b199d7d5
parent bbcb95f99d070a2b58d8566ef1bbb203fb205eb2
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun,  3 May 2020 16:23:18 +0300

Span for textbox lines

Diffstat:
Msrc/textbox.cc | 5+++--
Msrc/textbox.h | 2+-
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/textbox.cc b/src/textbox.cc @@ -38,13 +38,14 @@ void textbox_init( TextBox * tb, size_t scrollback ) { // TODO: this is kinda crap *tb = { }; - tb->lines = ( TextBox::Line * ) calloc( sizeof( TextBox::Line ), scrollback ); + tb->lines = alloc_span< TextBox::Line >( scrollback ); + memset( tb->lines.ptr, 0, tb->lines.num_bytes() ); tb->num_lines = 1; tb->max_lines = scrollback; } void textbox_destroy( TextBox * tb ) { - free( tb->lines ); + free( tb->lines.ptr ); } void textbox_add( TextBox * tb, const char * str, size_t len, Colour fg, Colour bg, bool bold ) { diff --git a/src/textbox.h b/src/textbox.h @@ -16,7 +16,7 @@ struct TextBox { size_t len = 0; }; - Line * lines; + Span< Line > lines; size_t head; size_t num_lines; size_t max_lines;