kikos500 Posted September 17, 2016 Share Posted September 17, 2016 (edited) well i am trying to create a dx list but im stuck on creating a scroll bar well i tried in a few different ways but none worked. please give me some examples of how to make a scroll function createList(x,y,w,h,parent) local id = #elements_Table.list + 1 elements_Table.list[id] = {} if not x or not y or not w or not h then outputDebugString("Error: Missing some arguments (x,y,w,h)") end elements_Table.list[id].x = x elements_Table.list[id].y = y elements_Table.list[id].w = w elements_Table.list[id].h = h elements_Table.list[id].parent = parent or nil elements_Table.list[id].visible = false elements_Table.list[id].items = {} elements_Table.list[id].selected = 0 elements_Table.list[id].scroll = 0 if parent then table.insert(parent.children,elements_Table.list[id]) elements_Table.list[id].x = elements_Table.list[id].x + parent.px elements_Table.list[id].y = elements_Table.list[id].y + parent.py end return elements_Table.list[id] end function addItem(grid,text) if grid then table.insert(grid.items,{text = text, alpha = 0}) return #grid.items end return false end function onHover() for i,list in pairs(elements_Table.list) do for num,rows in pairs(list.items) do if isCursorHover(list.x,list.y+(num*20)-17,list.w,20) then rows.alpha = 150 else rows.alpha = 0 end end end end addEventHandler( "onClientRender", root, onHover) function onClick() for i,list in pairs(elements_Table.list) do for num,rows in pairs(list.items) do if isCursorHover(list.x,list.y+(num*20)-17,list.w,20) then list.selected = num end end end end addEventHandler( "onClientClick", root, onClick ) function renderList() for i,v in pairs(elements_Table.list) do if v.visible then dxDrawRectangle(v.x,v.y,v.w,v.h + 10,tocolor(0,0,0,150)) for num,row in pairs(v.items) do if (num*20)-v.scroll < v.h then v.showingr = num if v.selected ~= num then dxDrawRectangle( v.x, v.y+(num*20)-17, v.w, 20,tocolor(0,0,0,row.alpha)) else dxDrawRectangle( v.x, v.y+(num*20)-17, v.w, 20,tocolor(0,0,0,255)) end dxDrawText(row.text,v.x + 1,v.y+(num*20)-17,v.w+v.x,v.y+20,tocolor(255,255,255,255),1,"default-bold","left","top") end end end end end addEventHandler( "onClientRender", root, renderList) Edited September 17, 2016 by kikos500 Link to comment
Simple0x47 Posted September 18, 2016 Share Posted September 18, 2016 Use these functions. dxCreateRenderTarget dxSetRenderTarget Link to comment
kikos500 Posted September 18, 2016 Author Share Posted September 18, 2016 mate i want to create a scroll bar i am planning to use render targets after i finish the scrolling :C Link to comment
</Mr.Tn6eL> Posted September 20, 2016 Share Posted September 20, 2016 (edited) progress/100*h h = Your all gridlist rows height Edited September 20, 2016 by </Mr.Tn6eL> Link to comment
kikos500 Posted September 23, 2016 Author Share Posted September 23, 2016 well i tried this but the rows goes out from the gridlist and hovering plus selecting doesn't work when i scroll down function createList(x,y,w,h,parent) local id = #elements_Table.list + 1 elements_Table.list[id] = {} if not x or not y or not w or not h then outputDebugString("Error: Missing some arguments (x,y,w,h)") end elements_Table.list[id].x = x elements_Table.list[id].y = y elements_Table.list[id].w = w elements_Table.list[id].h = h elements_Table.list[id].parent = parent or nil elements_Table.list[id].visible = false elements_Table.list[id].items = {} elements_Table.list[id].selected = 0 elements_Table.list[id].scroll = 0 if parent then table.insert(parent.children,elements_Table.list[id]) elements_Table.list[id].x = elements_Table.list[id].x + parent.px elements_Table.list[id].y = elements_Table.list[id].y + parent.py end return elements_Table.list[id] end function addItem(grid,text) if grid then table.insert(grid.items,{text = text, alpha = 0}) return #grid.items end return false end function onHover() for i,list in pairs(elements_Table.list) do for num,rows in pairs(list.items) do if isCursorHover(list.x,list.y+(num*20)-17,list.w,20) then rows.alpha = 150 else rows.alpha = 0 end end end end addEventHandler( "onClientRender", root, onHover) function onClick() for i,list in pairs(elements_Table.list) do for num,rows in pairs(list.items) do if isCursorHover(list.x,list.y+(num*20)-17,list.w,20) then list.selected = num end end end end addEventHandler( "onClientClick", root, onClick ) function scrollDown() for i,v in pairs(elements_Table.list) do if isCursorHover(v.x,v.y,v.w,v.h) then if v.scroll < (v.h/20) then v.scroll = v.scroll+1 end end end end bindKey("mouse_wheel_down", "down", scrollDown) function scrollUp() for i,v in pairs(elements_Table.list) do if isCursorHover(v.x,v.y,v.w,v.h) then if v.scroll > 0 then v.scroll = v.scroll-1 end end end end bindKey("mouse_wheel_up", "down", scrollUp) function renderList() for i,v in pairs(elements_Table.list) do if v.visible then dxDrawRectangle(v.x,v.y,v.w,v.h + 10,tocolor(0,0,0,150)) local num = v.h/20 for i = v.scroll, num+v.scroll do local posrow = i - v.scroll if v.items[i] then if v.selected ~= i then dxDrawRectangle( v.x, v.y+(posrow*20)-17, v.w, 20,tocolor(0,0,0,v.items[i].alpha)) else dxDrawRectangle( v.x, v.y+(posrow*20)-17, v.w, 20,tocolor(0,0,0,255)) end dxDrawText(v.items[i].text,v.x + 1,v.y+(posrow*20)-17,v.w+v.x,v.y+20,tocolor(255,255,255,255),1,"default-bold","left","top") end end end end end addEventHandler( "onClientRender", root, renderList) 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