User scrollable text example? (SOLVED)

#1

Maybe my search terms are wrong but I can’t find an example in the Defold manuals, api or forum on how to create user scrollable text.
Does anyone know of an example with this behavior using a text label or gui text they can point me to?

0 Likes

#2
local offsety_help = 0
local previous_y_help = nil
function update(self, dt)
    if offsety_help ~= 0 then
	local help_screen_text_box = gui.get_node("help_screen_text_box")
	gui.set_position(help_screen_text_box, gui.get_position(help_screen_text_box)
	+ vmath.vector3(0,offsety_help * dt,0))
	offsety_help = offsety_help - offsety_help * dt
    end
end
function on_input(self, action_id, action)
    local help_screen_text_box = gui.get_node("help_screen_text_box")
	if action.repeated or action.pressed then
		local current_mouse_y = action.y
		offsety_help =  offsety_help + current_mouse_y - (previous_y_help or current_mouse_y)
		if offsety_help + gui.get_position(help_screen_text_box).y < 5 then
			offsety_help = -5 - gui.get_position(help_screen_text_box).y
			print("less")
		end
		if offsety_help + gui.get_position(help_screen_text_box).y > 1000 then
			offsety_help = 1000 - gui.get_position(help_screen_text_box).y
			print("more")
		end
		previous_y_help = current_mouse_y
	end
	if action.released then
		previous_y_help = nil
	end
end
1 Like

#3

I created something similar. I have no way to check. But it should work. I also have where the scroll works only if a certain box is pressed. But I think if you take this as an example, you can do it as you need.
Magic numbers are limitations.

0 Likes

#4

@Denis_Makhortov Thanks for the code! It works perfectly when I combined it with a stencil mask.

3 Likes