Jump to content

[HELP] dx list


kikos500

Recommended Posts

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

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

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...