diff --git a/pkg/base/icegui/widgets.lua b/pkg/base/icegui/widgets.lua index 77948a8..33b46df 100644 --- a/pkg/base/icegui/widgets.lua +++ b/pkg/base/icegui/widgets.lua @@ -74,6 +74,7 @@ function P.widget(options) -- align 0.5 = center -- FIXME: some of the things that are disallowed as setters could be made settable with more effort. + -- FIXME: I don't have swap children methods function setter_keys.x(v) rawset(this, 'x', v) this.dirty = true end function setter_keys.y(v) rawset(this, 'y', v) this.dirty = true end @@ -131,6 +132,34 @@ function P.widget(options) return not (this.l>x or this.ry or this.b line_charwidth -- split if word is larger than a line + then + cur_tok = cur_tok + 1; toks[cur_tok] = {word={idx}} + else + toks[cur_tok].word[#toks[cur_tok].word+1] = idx + end + end + end + + -- 2. render as many words as possible per line + + local begin_x = x + local end_x = x + wp + + local function endline() + x = begin_x; y = y + MINI_HEIGHT + end + + for i=1,#toks do + local tok = toks[i] + if tok.word ~= nil then + if x + #tok.word * MINI_WIDTH > end_x then endline() end + for j=1,#tok.word do + idx = tok.word[j] + client.img_blit(img_font_mini, x, y, MINI_WIDTH, MINI_HEIGHT, idx*MINI_WIDTH, 0, c) + x = x + MINI_WIDTH + end + elseif tok.spaces ~= nil then + x = x + MINI_WIDTH * tok.spaces + elseif tok.newlines ~= nil then + for j=1,tok.newlines do endline() end + end + if x > end_x then endline() end + end + end function gui_get_char(key, modif) @@ -106,11 +179,6 @@ function gui_string_edit(str, maxlen, key, modif) return str end --- &*(^$#($*@&)$&(@)$&@()$&@)($&@)$&@()$&@)$(@&)(@&)@$&()@$&)@$&@()$&)(@$&Y*LHEWIGR*(WRY --- When I come back: --- find out why my rectangle isn't displaying :( --- look into getting a gui scene set up during the loader too - function gui_create_scene(width, height) local scene = {}