View Single Post
06/20/17, 02:09 AM   #1
Lum1on
AddOn Author - Click to view addons
Join Date: Aug 2016
Posts: 18
ZO_ScrollList's individual rowHeight

Hey,

Is it possible to change the rowHeight individually for every data you push into it?

For example:

Code:
local LibScroll = LibStub:GetLibrary ( "LibScroll" )

Test = { }
Test.name = "Test"

local function _setupCallback ( _control, _data, _list )
	_control:SetText ( _data.text )
	_control:SetFont ( "ZoFontWinH4" )
	
	_control:SetHandler ( "OnMouseDown", function ( _control, _mouseButton )
		if _mouseButton == MOUSE_BUTTON_INDEX_LEFT then
			_list.controlHeight = _control:GetHeight ( )
			
			d ( "DEBUG / _list.controlHeight has been changed" )
		elseif _mouseButton == MOUSE_BUTTON_INDEX_RIGHT then
			d (
				zo_strformat ( "DEBUG / _list.controlHeight: <<1>>, _control:GetHeight ( ): <<2>>",
				_list.controlHeight, _control:GetHeight ( ))
			)
		elseif _mouseButton == MOUSE_BUTTON_INDEX_MIDDLE then
			local _table = {
				{ text = "Short text" },
				{ text = "A little bit longer text" },
				{ text = "Long text to push it to the second row" },
				{ text = "Short text again" }
			}

			ScrollList:Update ( _table )
		end
	end )
end

local function _createWindow ( )
	local _window = WINDOW_MANAGER:CreateTopLevelWindow ( "ScrollListExampleWindow" )

	_window:SetAnchor ( CENTER, GuiRoot, CENTER )
	_window:SetDimensions ( 250, 250 )

	_window.Background = WINDOW_MANAGER:CreateControlFromVirtual ( "ScrollListExampleBackground", _window, "ZO_DefaultBackdrop" )
	_window.Background:SetAnchorFill ( )

	return _window
end

local function _createScrollList ( )
	local _window = _createWindow ( )
	
	local _scrollData = {
		name = "ScrollListExample",
		parent = _window,
		
		width = 230,
		height = 230,
		rowHeight = 24,
		
		setupCallback = _setupCallback
	}
	
	local _scrollList = LibScroll:CreateScrollList ( _scrollData )

	_scrollList:SetAnchor ( TOPLEFT, _window, TOPLEFT, 10, 10 )
	
	return _scrollList
end

local function _initializeScrollList ( )
	local _table = {
		{ text = "Short text" },
		{ text = "A little bit longer text" },
		{ text = "Long text to push it to the second row" },
		{ text = "Short text again" }
	}

	ScrollList = _createScrollList ( )
	ScrollList:Update ( _table )
end

local function AddOnLoaded ( event, addonName )
	if addonName == Test.name then
		_initializeScrollList ( )
		
		EVENT_MANAGER:UnregisterForEvent ( Test.name, EVENT_ADD_ON_LOADED )
	end
end

EVENT_MANAGER:RegisterForEvent ( Test.name, EVENT_ADD_ON_LOADED, AddOnLoaded )
If you right click one of the controls you can see the _list.controlHeight should be 24 (rowHeight) and _control:GetHeight ( ) should be 24 or 48 depending on how many rows it holds.

Now, if you left click the one control that expands to a second row and you right click it you can see that the value of _list.controlHeight changed to be the same than _control:GetHeight ( ) but nothing happens. And the reason why nothing happens is it changes the rowHeight but only for the next items you're going to place in the ZO_ScrollList.

So if you click the middle mouse now it pushes three new texts replacing the previous ones. And those have the new rowHeight you set by left clicking one of the contents.

So how I'm able to change the rowHeight as I'm placing new data in the ZO_ScrollList?

Last edited by Lum1on : 06/20/17 at 02:29 AM.
  Reply With Quote