local druid = require("druid.druid")


local function create_element(self, data)
	local nodes = gui.clone_tree(self.prefab)
	local root = nodes["button_prefab/button"]
	gui.set_text(nodes["button_prefab/text"], "Element " .. data)
	gui.set_enabled(root, true)

	local button = self.druid:new_button(root, function()end)
	button:set_click_zone(self.scroll.view_node)
	return root, button
end


local function on_fill(self)
	self.data_list:set_data(self.data)
end


local function on_clear(self)
	self.data_list:set_data()
end


function init(self)
	self.druid = druid.new(self)

	self.prefab = gui.get_node("button_prefab/button")
	gui.set_enabled(self.prefab, false)

	self.scroll = self.druid:new_scroll("data_list_view", "data_list_content")
	self.scroll:set_horizontal_scroll(false)
	self.grid = self.druid:new_static_grid("data_list_content", self.prefab, 2)
	self.data_list = self.druid:new_data_list(self.scroll, self.grid, create_element)
	self.data_list:set_debug(true)

	self.data = {}
	for i = 1, 30 do
		table.insert(self.data, i)
	end

	self.druid:new_button("button_fill/button", on_fill)
	self.druid:new_button("button_clear/button", on_clear)
end


function final(self)
	self.druid:final()
end


function update(self, dt)
	self.druid:update(dt)
end


function on_message(self, message_id, message, sender)
	self.druid:on_message(message_id, message, sender)
end


function on_input(self, action_id, action)
	return self.druid:on_input(action_id, action)
end
