This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Oestlie94's profile picture

Button background and text color

Started by Oestlie94, 12 July 2013 - 03:31 PM
Oestlie94 #1
Posted 12 July 2013 - 05:31 PM
Hi, I have been using DireWolfs Button API to make some touch screen buttons,
but I want to be able to change the Button background and text color in the setTable() function,
so i can have different colors on the buttons on the screen.

Have been trying for two days to figure it out myself. Have been watching all DireWolfs tutorials + some other tutorials but still cant figure it out (probably because im new to coding).

Pastebin code to the Button API is:
[left]www.pastebin.com/HRbMF1Eg[/left]

[left]Would be awesome if someone can either guide me, or just rewrite the code and post the new pastebin code here :)/>/>[/left]


[left]Oestlie94[/left]
Lyqyd #2
Posted 15 July 2013 - 12:32 PM
Split into new topic.
Grim Reaper #3
Posted 15 July 2013 - 05:36 PM
You could substitute these two functions in for screen and setTable:


function setTable(name, func, xmin, xmax, ymin, ymax, textColor, onBackgroundColor, offBackgroundColor)
   button[name] = {}
   button[name]["func"] = func
   button[name]["active"] = false
   button[name]["xmin"] = xmin
   button[name]["ymin"] = ymin
   button[name]["xmax"] = xmax
   button[name]["ymax"] = ymax

   button.name.textColor		  = textColor
   button.name.onBackgroundColor  = onBackgroundColor
   button.name.offBackgroundColor = offBackgroundColor
end


function screen()
	local currColor

	for name,data in pairs(button) do
		if data.active then
			currColor = data.onBackgroundColor or colors.lime
		else
			currColor = data.offBackgroundColor or colors.red
		end

		fill (name, currColor, data)
	end
end

Please, ask any questions about what confuses you or you don't understand about the changes in the code that I made. I didn't really want to go over every tiny detail in this post, but feel free to PM me or respond to this topic with your questions. :)/>