Extinction Posted March 16, 2017 Share Posted March 16, 2017 How can I make my own DX Combobox, with a working scroll/scrollbar? If there any explained examples it'll help, thank you. Link to comment
NeXuS™ Posted March 16, 2017 Share Posted March 16, 2017 (edited) You'll have to do some calculations about it. local testItems = {} local drawFrom = 1 local drawItems = 5 for i = 1, 20 do table.insert(testItems, i) end function dxDrawComboBox() dxDrawRectangle(100, 100, 100, testItems > drawItems and drawItems*15 or #testItems*15) for i, k in pairs(testItems) do if i >= drawFrom and i <= drawFrom+drawItems then dxDrawText(k, 100, 100+(i-1)*15) end end end bindKey("mouse_wheel_down", "down", function() if #testItems > drawItems and drawFrom < #testItems then drawFrom = drawFrom+1 end end) bindKey("mouse_wheel_up", "down", function() if drawItems > 1 then drawFrom = drawFrom - 1 end end) Didn't test, but should work. If you need further help, feel free to ask here. Edited March 16, 2017 by Patrik91 1 Link to comment
Extinction Posted March 16, 2017 Author Share Posted March 16, 2017 dxDrawRectangle(100, 100, 100, testItems > drawItems and drawItems*15 or #testItems*15) Attempt to compare number with table Link to comment
NeXuS™ Posted March 16, 2017 Share Posted March 16, 2017 (edited) You are right. dxDrawRectangle(100, 100, 100, #testItems > drawItems and #testItems*15 or drawItems*15) Edited March 16, 2017 by Patrik91 1 Link to comment
Extinction Posted March 16, 2017 Author Share Posted March 16, 2017 (edited) Just displays a white rectangle, even though I've entered things into the table. Edit: Needed to change text color How can I click something on the combo box, and then it outputs the message in outputchatbox e.g. click number 1 = outputChatBox("Clicked 1") Edited March 16, 2017 by Extinction Link to comment
NeXuS™ Posted March 16, 2017 Share Posted March 16, 2017 You'll have to do some calculations again. local sX, sY = guiGetScreenSize() _getCursorPosition = getCursorPosition function getCursorPosition() local cX, cY = _getCursorPosition() if cX and cY then return cX*sX, cY*sY end return -1, -1 end function inBox(x, y, w, h) local cX, cY = getCursorPosition() if cX > x and cX < x + w and cY > y and cY < y + h then return true end return false end function onClick(cButton, cState) if cButton == "left" and cState == "down" then for i = 0, 4 do if inBox(100, 100+i*15, 100, 15) then clickedElement = i+1+drawFrom end end end end Again, not tested, but should work. @Extinction 1 Link to comment
Extinction Posted March 16, 2017 Author Share Posted March 16, 2017 it outputs number 1 as 2 Link to comment
NeXuS™ Posted March 16, 2017 Share Posted March 16, 2017 Change clickedElement = i+1+drawFrom to clickedElement = i+drawFrom 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