Jump to content

DX Combobox Help


Extinction

Recommended Posts

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 by Patrik91
  • Like 1
Link to comment

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 by Extinction
Link to comment

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

  • Like 1
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...