Skip to content

Commit

Permalink
Prevent input text from overflowing the text field
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Nov 28, 2020
1 parent 84e92d8 commit c3716e1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gooey/internal/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ function INPUT.set_text(input, text)
input.marked_text_width = get_text_width(input.node, marked_text)
input.total_width = input.text_width + input.marked_text_width

gui.set_text(input.node, text .. marked_text)
-- prevent text from overflowing the input field
local visible_text_width = input.total_width
local visible_text = text .. marked_text
local field_width = gui.get_size(input.node).x * gui.get_scale(input.node).x
while visible_text_width > field_width do
visible_text = visible_text:sub(2)
visible_text_width = get_text_width(input.node, visible_text)
end

gui.set_text(input.node, visible_text)
end
end
function INPUT.set_long_pressed_time(input, time)
Expand Down

0 comments on commit c3716e1

Please sign in to comment.