Resizing main console using Geyser

Post Reply
chrio
Posts: 66
Joined: Mon Aug 22, 2016 11:34 am

Resizing main console using Geyser

Post by chrio » Tue Sep 20, 2016 10:36 am

After I wrote my Console border handler with percentages I realised there was a simpler solution I could use, especially since I was using Geyser for all my other ui elements. Why not just create a geyser container as a place holder for the main console, and resize the borders to match that one when needed?

1. Make a container
2. Make an eventhandler function for the resize event. In the handler, call the function to update borders from a temptimer. You want a timer to give geyser time to update its own elements first.
3. Register the function as an eventhandler for sysWindowResizeEvent.
Code: [show] | [select all] lua
-- interfacescript
--------------------------------
ui = ui or {} -- user interface related stuff goes into this table

-- Container used to get console position
ui.mainconsole_container = Geyser.Container:new({
	name = "mainconsole_container",
	x="20%", y="20.5%",
	width="60%", height="72%",
})

-- function called by the temptimer to do the work
function ui.updateBorderSizes()
	local w,h = getMainWindowSize()
	-- Only update if window size have changed!
	if( w ~= ui.window_width or h ~= ui.window_height ) then
		ui.window_width = w
		ui.window_height = h

		local cx = ui.mainconsole_container:get_x()
		local cy = ui.mainconsole_container:get_y()
		local cw = ui.mainconsole_container:get_width()
		local ch = ui.mainconsole_container:get_height()

		setBorderLeft(tonumber(cx))
		setBorderTop(tonumber(cy))
		setBorderRight(tonumber(w-cx-cw))
		setBorderBottom(tonumber(h-cy-ch))
	end
end

-- sysWindowResizeEvent handler
function ui.updatecontent( event, x, y )
	if( ui.eventtimer ) then killTimer( ui.eventtimer ) end
	ui.eventtimer = tempTimer(0, [[killTimer( "ui.eventtimer" ) ui.updateBorderSizes()]])
end

-- register our function as an event handler
registerAnonymousEventHandler("sysWindowResizeEvent", "ui.updatecontent")

User avatar
Vadi
Posts: 4724
Joined: Sat Mar 14, 2009 3:13 pm

Re: Resizing main console using Geyser

Post by Vadi » Fri Sep 23, 2016 2:44 am

Nice work!

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest