WiBox Posted September 20, 2021 Share Posted September 20, 2021 (edited) 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: 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") 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") 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") 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") 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 September 20, 2021 by WiBox Link to comment
Spakye Posted September 20, 2021 Share Posted September 20, 2021 (edited) Hello, after some research i think there is a property to add a close btn to your window, I have no idea if it works and how it looks i never tried it. try this : guiSetProperty ( guiElement, "CloseButtonEnabled", "True") https://wiki.multitheftauto.com/wiki/GuiSetProperty http://static.cegui.org.uk/static/WindowsLookProperties.html Edited September 20, 2021 by Spakye Link to comment
WiBox Posted September 20, 2021 Author Share Posted September 20, 2021 I've actually tried it, I didn't see a close button.. I appreciate your help. Link to comment
Spakye Posted September 20, 2021 Share Posted September 20, 2021 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
Spakye Posted September 20, 2021 Share Posted September 20, 2021 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
WiBox Posted September 21, 2021 Author Share Posted September 21, 2021 It's close to what I need, I'll remove "AlwaysOnTop" once the focused window isn't the close button window. Thanks a lot mate! 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now