To present list of people and some of their attributes I need to create a table. As there is no table node in Godot and by reading suggestions here on forums I decided to create my own but it comes with several problems that I couldnt solve by myself.
At first I tried to use only Scrollcontainer, Grid and buttons. It worked but as I wanted to have headers in my columns I separated them in HBoxContainer but after I add list of people to grid the first row is behind the headers row. Not sure how to do that.
After that I wanted to add some kind of border around the table and after reading here I opted to use panel and custom styleboxtexture, but that created another set of problems. First I couldnt see the panel at all after a lot of changes and tries I succeded but it doesnt expand with its content, its just painted under it.
onready var poz = preload("res://Prozor.tscn")
func create_table(name, Obj):
var pozadina = poz.instance()
add_child(pozadina)
pozadina.set_owner(self)
pozadina.rect_position.x = 100
pozadina.rect_position.y = 100
pozadina.rect_size.x = 150
pozadina.rect_size.y = 150
var table = ScrollContainer.new()
pozadina.add_child(table)
table.name = name
table.rect_position.x = 20
table.rect_position.y = 20
table.rect_size.x = 300
table.rect_size.y = 200
var Grid = GridContainer.new()
Grid.set_columns(4)
#Grid.rect_position.y=250
#This doesnt work?!
table.add_child(Grid)
#Creating headers
if HeadsOfFamilies.size()>0:
var Z = HBoxContainer.new()
Z.name = "Zaglav"
Z.rect_min_size.x = 200
Z.rect_min_size.y = 20
table.add_child(Z)
var A = Button.new()
A.text = "Name"
Z.add_child(A)
var B = Button.new()
B.text = "Surname"
Z.add_child(B)
var C = Button.new()
C.text = "Age"
Z.add_child(C)
var D = Button.new()
D.text = "Health"
Z.add_child(D)
#Creating content
for i in HeadsOfFamilies.size():
var Y = HBoxContainer.new()
Y.name = "Content"
Y.rect_min_size.x = 200
Y.rect_min_size.y = 20
var oneMan = HeadsOfFamilies[i]
var But = Button.new()
But.text = oneMan.get("Name")
Grid.add_child(But)
var But2 = Button.new()
But2.text = oneMan.get("Surname")
Grid.add_child(But2)
var But3 = Button.new()
But3.text = str(oneMan.get("Age"))
Grid.add_child(But3)
var But4 = Button.new()
But4.text = str(oneMan.get("Health"))
Grid.add_child(But4)
Another thing I couldnt solve is how to do macro substitution its common thing in VFP where I am coming from to build a command as a string and then execute that command. For example I could read the objects properties (one person in above code) and use name of the property to name headers programaticaly, and use values of these properties to fill content buttons in grid.
