Jump to content

clip text/image in scrollpane


Fist

Recommended Posts

You should just calculate the X and Y positions of the elements.

 

local scrollPane = guiCreateScrollPane(500, 200, 500, 300, false)
local things = {
	{"Test Test Test Test", "text"},
	{"test.png", "image", 100, 50} 
}

function drawThings()
	local x, y = 0, 0
	local nextY = 0
	for i, k in ipairs(things) do
		if k[2] == "text" then
			if x + dxGetTextWidth(k[1]) > 300 then
				x = 0
				y = nextY
			end
			guiCreateLabel(x, y, dxGetTextWidth(k[1]), 15, false, scrollPane)
			if nextY < y + 15 then
				nextY = nextY + 15
			end
		elseif k[2] == "image" then
			if x + k[3] > 300 then
				x = 0
				y = nextY
			end
			guiCreateStaticImage(x, y, k[3], k[4], k[1], false, scrollPane)
			if nextY < y + k[4] then
				nextY = y + k[4]
			end
		end
	end
end

Should work, not tested tho.

Link to comment
10 minutes ago, NeXuS™ said:

You should just calculate the X and Y positions of the elements.

 


local scrollPane = guiCreateScrollPane(500, 200, 500, 300, false)
local things = {
	{"Test Test Test Test", "text"},
	{"test.png", "image", 100, 50} 
}

function drawThings()
	local x, y = 0, 0
	local nextY = 0
	for i, k in ipairs(things) do
		if k[2] == "text" then
			if x + dxGetTextWidth(k[1]) > 300 then
				x = 0
				y = nextY
			end
			guiCreateLabel(x, y, dxGetTextWidth(k[1]), 15, false, scrollPane)
			if nextY < y + 15 then
				nextY = nextY + 15
			end
		elseif k[2] == "image" then
			if x + k[3] > 300 then
				x = 0
				y = nextY
			end
			guiCreateStaticImage(x, y, k[3], k[4], k[1], false, scrollPane)
			if nextY < y + k[4] then
				nextY = y + k[4]
			end
		end
	end
end

Should work, not tested tho.

doesn't work

Link to comment
local guiWindow = guiCreateWindow(500, 200, 500, 300, "Test panel", false) 
local scrollPane = guiCreateScrollPane(0, 20, 500, 300, false, guiWindow)
local things = {
	{"Test Test Test Test", "text"},
	{"Test2 Test2 Test2 Test2", "text"},
	{"Test3 Test3 Test3 Test3", "text"},
	{"Test4 Test4 Test4 Test4", "text"}
}

function drawThings()
	local x, y = 0, 0
	local nextY = 0
	for i, k in ipairs(things) do
		if k[2] == "text" then
			if x + dxGetTextWidth(k[1]) > 500 then
				x = 0
				y = nextY
			end
			guiCreateLabel(x, y, dxGetTextWidth(k[1]), 15, k[1], false, scrollPane)
			if nextY < y + 15 then
				nextY = nextY + 15
			end
			x = x + dxGetTextWidth(k[1]) + 10
		elseif k[2] == "image" then
			if x + k[3] > 500 then
				x = 0
				y = nextY
			end
			guiCreateStaticImage(x, y, k[3], k[4], k[1], false, scrollPane)
			if nextY < y + k[4] then
				nextY = y + k[4]
			end
			x = x + k[3] + 10
		end
	end
end
drawThings()

This one is tested with texts, and worked. Can ya test it with pictures?

  • Like 1
Link to comment
3 minutes ago, NeXuS™ said:

local guiWindow = guiCreateWindow(500, 200, 500, 300, "Test panel", false) 
local scrollPane = guiCreateScrollPane(0, 20, 500, 300, false, guiWindow)
local things = {
	{"Test Test Test Test", "text"},
	{"Test2 Test2 Test2 Test2", "text"},
	{"Test3 Test3 Test3 Test3", "text"},
	{"Test4 Test4 Test4 Test4", "text"}
}

function drawThings()
	local x, y = 0, 0
	local nextY = 0
	for i, k in ipairs(things) do
		if k[2] == "text" then
			if x + dxGetTextWidth(k[1]) > 500 then
				x = 0
				y = nextY
			end
			guiCreateLabel(x, y, dxGetTextWidth(k[1]), 15, k[1], false, scrollPane)
			if nextY < y + 15 then
				nextY = nextY + 15
			end
			x = x + dxGetTextWidth(k[1]) + 10
		elseif k[2] == "image" then
			if x + k[3] > 500 then
				x = 0
				y = nextY
			end
			guiCreateStaticImage(x, y, k[3], k[4], k[1], false, scrollPane)
			if nextY < y + k[4] then
				nextY = y + k[4]
			end
			x = x + k[3] + 10
		end
	end
end
drawThings()

This one is tested with texts, and worked. Can ya test it with pictures?

Yup works!!! Thank you man alot.

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