Jump to content

Close button on top-right of the window.


WiBox

Recommended Posts

So first I tried on top-left:

window = guiCreateWindow(800, 290, 500, 500, "Testing", false)
closeBut = guiCreateButton(0, 0, 22, 19, "X", false, window)
guiSetProperty(closeBut, "ClippedByParent", "False")
guiSetProperty(closeBut, "AlwaysOnTop", "True")

It looks like this:
XdqZzbT.png

Now, I'm used to it on the right just like most operating systems, it just doesn't look right to me, so I tried taking it to the top right of the window..

window = guiCreateWindow(800, 290, 500, 500, "Testing", false)
closeBut = guiCreateButton(800-22-5, 0, 22, 19, "X", false, window)--X position set to 800-button width
guiSetProperty(closeBut, "ClippedByParent", "False")
guiSetProperty(closeBut, "AlwaysOnTop", "True")

x4DlNzC.png

It took me an hour to figure out that the button is that far above ?

Now, I tried to see how I could make it go lower:

window = guiCreateWindow(800, 290, 500, 500, "Testing", false)
closeBut = guiCreateButton(160-19, 0, 22, 19, "X", false, window) --Here I tried to make it on one-quarter 1/4
guiSetProperty(closeBut, "ClippedByParent", "False")
guiSetProperty(closeBut, "AlwaysOnTop", "True")

QxR0wNl.png

Of course, I tried changing its 'Y' position, to end up between 2 numbers that were the reason I'm asking for aid:

window = guiCreateWindow(800, 290, 500, 500, "Testing", false)
closeBut = guiCreateButton(160-19, 8, 22, 19, "X", false, window)--Kept on one-quarter but with 'Y' position as 8
guiSetProperty(closeBut, "ClippedByParent", "False")
guiSetProperty(closeBut, "AlwaysOnTop", "True")

bLjHbEE.png

window = guiCreateWindow(800, 290, 500, 500, "Testing", false)
closeBut = guiCreateButton(160-19, 9, 22, 19, "X", false, window)--Kept on one-quarter but with 'Y' position as 9
guiSetProperty(closeBut, "ClippedByParent", "False")
guiSetProperty(closeBut, "AlwaysOnTop", "True")

ReigNqk.png

I don't want to use onClientRender for CPU usage and a button without parent means its on top of the guiRoot and if you open more than 1 window, those buttons will be on top of everything..

I tried using labels, worked perfectly. And the rest? Static images, edits, combo box, checkbox, radio button, grid list, memo, progress bar, scroll bar and tab panel have the same problem as the button takes the same position as all these pictures..

Anyone knows what should I do? I don't want to place the button on top-left neither use a label as button..

Edited by WiBox
Link to comment

I did some tests, the button isn't showing cause he's hidden by the title bar.

local test = guiCreateWindow( 0.3, 0.1, 0.2, 0.2, "test", true )
guiSetProperty ( test,  "CloseButtonEnabled", "True")
guiSetProperty ( test,  "TitlebarEnabled", "False")

Now the button will show, but it doesnt close the window when you clic on it and the onGuiClickEvent register it as the window when you clic on it.

But have a look at this page : https://wiki.multitheftauto.com/wiki/IsMouseOnGUICloseButton

Link to comment

Hey i came up with something, i think its close to what you need.

It creates a button in the corner to close the window, kind of attach it to the window so it will update the position whenever the window is moved or resized.

It needs some more testing but you can probably make a resource out of it and export the functions createWdwCloseBtn(wdw), showWdwCloseBtn(wdw), hideWdwCloseBtn(wdw) so you can use it anytime you need.

 

local windows = {}

function createWdwCloseBtn(wdw)
	local wx, wy = guiGetPosition( wdw, false )
	local ww, wh = guiGetSize( wdw, false )
	local cb = guiCreateButton ( wx + ww -20, wy, 20, 20, "x", false)
	guiSetProperty ( cb,  "AlwaysOnTop", "True")
	windows[wdw] = cb
	addEventHandler ( "onClientGUIClick", cb, closeTheWindow, false )
	addEventHandler("onClientGUISize", wdw, updateCloseBtnPosition )
	addEventHandler ( "onClientGUIMove", wdw, updateCloseBtnPosition )
end

function updateCloseBtnPosition()
	local wx, wy = guiGetPosition( source, false )
	local ww, wh = guiGetSize( source, false )
	guiSetPosition( windows[source], wx + ww -20, wy, false )
	guiSetVisible( windows[source], true )
end

function closeTheWindow()
	guiSetVisible( source, false )
	for w, b in pairs(windows) do
		if b == source then
			guiSetVisible( w, false )
		end
	end
end

function showWdwCloseBtn(wdw)
	guiSetVisible( windows[wdw], true )
end

function hideWdwCloseBtn(wdw)
	guiSetVisible( windows[wdw], false )
end

local w = guiCreateWindow( 0.3, 0.1, 0.4, 0.4, "A Title", true)
createWdwCloseBtn(w)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...