Skip to content

Commit

Permalink
fixed bug with listbox
Browse files Browse the repository at this point in the history
Also might fix the font undefined issue on the switch
  • Loading branch information
ajusa committed Mar 25, 2021
1 parent 2b35cba commit f2dde25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/listbox.moon
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
local *
pad = 10
-- can also provide "data" as a part of choices
remove_color = =>
w = ""
if type(@) == "string" then return @
else
for i = 2, #@, 2
w ..= @[i]
return w
create_listbox = =>
@selected = @selected or 1
if @choices[@selected].onchange
@choices[@selected].onchange(@choices[@selected])
for choice in *@choices
choice.text = lg.newText(font, choice.text)
@closable = @closable or false
@allow_menu = @allow_menu or false
@onclose = @onclose or ->
@media = @media or -pad
local *
dispatch "pause"
font_height = (text) ->
return math.max(text\getHeight!, @media)
_, count = string.gsub(remove_color(text), "\n", "\n")
return math.max(font\getHeight! * (1 + count), @media)
close = ->
input_event\remove!
draw_event\remove!
Expand All @@ -41,7 +47,7 @@ create_listbox = =>
if chosen.left then chosen.left(chosen)
return false
draw_event = on "draw_choice", ->
w = 3 * pad + _.max([c.text\getWidth! for c in *@choices]) + @media
w = 3 * pad + _.max([font\getWidth(remove_color(c.text)) for c in *@choices]) + @media
h, y_selected = pad, 0
for i, c in ipairs @choices
h += font_height(c.text) + pad
Expand All @@ -55,7 +61,7 @@ create_listbox = =>
lg.setColor(1, 1, 1)
if c.media then c.media(x+pad, text_y)
if i == @selected then lg.setColor(.506, .631, .757)
lg.draw(c.text, x + 2*pad + @media, text_y)
lg.print(c.text, x + 2*pad + @media, text_y)
text_y += pad + font_height(c.text)
return false
return {:create_listbox}
1 change: 0 additions & 1 deletion src/script.moon
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ find_script = (s, file) ->
read_file = (s, script_file) ->
file = find_script(s, script_file)
data = s.fs("#{s.base_dir}script/#{file}")
print file
if data == nil then error("Cannot read #{script_file}! Please check the scripts folder/zip")
ins = {}
for line in string.gmatch(data, "[^\n]+")
Expand Down
3 changes: 2 additions & 1 deletion src/text/text.moon
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ on "input", =>
dispatch "next_ins", ins
break
else if @ == "up"
choices = [text: t, action: -> for t in *backlog]
choices = {}
-- choices = [text: t, action: -> for t in *backlog]
for line in *backlog
if line.file
table.insert(choices, {
Expand Down

0 comments on commit f2dde25

Please sign in to comment.