Custom UIListLayout

  1. What do you want to achieve? Hello, i am making a notification system and i need to make a custom list layout system like the UIListLayout to tween the objects postitions inside it.

  2. What is the issue? I can’t manage to do it

  3. What solutions have you tried so far? I tried myself and looked on forums

You mean like this? It’s pretty simple.

The basic idea is that you have an array (a table) that stores all of the objects chronologically. New objects are inserted at the front which pushes everything up and old objects are removed. Every time the array changes, you update all of the objects and animate them to their new spot.

Below are some code samples pulled out of that project to give you a general idea. Note that master is the array that will store the objects.

--spawn in a new notification object
local function newMsg(t: string, s: string, d: number?)
	assert(_c.instances[t], 'invalid message type: "', t, '"')
	d = d or _c.defaultDuration
	
	local obj: _c.msgObj = _c.instances[t]:Clone()
	local tx = obj.Text
	local msg: msg = {
		obj = obj,
		text = s,
		pos = 1,
	}
	table.insert(master, 1, msg) --insert new notification at the front of the array
	tx.Text = s
	obj.Parent = container
	updateAll() --update everything, including this new object
--update the objects to move them to the right spot
function updateAll()
	for pos: number, msg: msg in master do
		msg.pos = pos --internally update the position
		if pos > _c.maxMessages and not msg.removing then --remove objects that are out of range
			task.spawn(removeMsg, msg)
		end		
		tws:Create(msg.obj, _c.twis.def, {Position = getMsgPos(pos)}):Play() --tween the objects to their new position
	end
end
--remove notification objects
function removeMsg(msg: msg)
	if not msg.removing then 
		msg.removing = true
		_c.actions.disappear(msg.obj).Completed:Wait() --remove the object via an animation because yes
		msg.obj:Destroy()
		table.remove(master, msg.pos) --remove the object from the table
		updateAll() --update everything again
	end
end
9 Likes

Hey, stumbled across this reply while digging around for a similar system, could you tell me what some variables are? (_c, msg, all that good stuff.)

1 Like

Nevermind, gave up anyway. Thanks for giving me hope i guess.

1 Like