aboutsummaryrefslogtreecommitdiff
path: root/option_set
diff options
context:
space:
mode:
Diffstat (limited to 'option_set')
-rw-r--r--option_set/option_set_list.gd111
-rw-r--r--option_set/option_set_list.tscn8
2 files changed, 119 insertions, 0 deletions
diff --git a/option_set/option_set_list.gd b/option_set/option_set_list.gd
new file mode 100644
index 0000000..dc6b29a
--- /dev/null
+++ b/option_set/option_set_list.gd
@@ -0,0 +1,111 @@
+extends Control
+
+onready var font: Font = get_font("font")
+var labels: Array
+var items: Array = [
+ "item 1",
+ "item 22",
+ "item 333",
+ "item 4444",
+ "item 55555",
+ "item 666666",
+ "item 7777777",
+ "item 88888888",
+ "item 999999999",
+ "This is the longest item of all, but eventually stops.",
+ "item 1",
+ "item 22",
+ "item 333",
+ "item 4444",
+ "item 55555",
+ "item 666666",
+ "item 7777777",
+ "item 88888888",
+ "item 999999999",
+ "This is the longest item of all, but eventually stops.",
+ "item 1",
+ "item 22",
+ "item 333",
+ "item 4444",
+ "item 55555",
+ "item 666666",
+ "item 7777777",
+ "item 88888888",
+ "item 999999999",
+ "This is the longest item of all, but eventually stops.",
+]
+
+var limit := 60
+var labels_pool: Array
+
+func _ready():
+ var num_labels := max_required_labels()
+ var labels_pool_size = int(ceil(num_labels * 1.10))
+ for idx in range(labels_pool_size):
+ var label := Label.new()
+ label.autowrap = true
+ label.anchor_left = 0.0
+ label.anchor_right = 1.0
+ label.valign = Label.VALIGN_CENTER
+ labels_pool.push_back(label)
+
+ for idx in range(min(num_labels, items.size())):
+ var label = labels_pool.pop_back()
+ label.text = items[idx]
+ labels.append(label)
+ add_child(label)
+
+# for it in items:
+# var label := Label.new()
+# label.text = it
+# label.autowrap = true
+# label.anchor_left = 0.0
+# label.anchor_right = 1.0
+# label.valign = Label.VALIGN_CENTER
+# labels.push_back(label)
+# add_child(label)
+
+
+
+func _process(delta):
+
+ var num_labels = max_required_labels()
+ var difference = num_labels - labels.size()
+ if difference > 0:
+ for idx in range(difference):
+ var label = labels_pool.pop_back()
+ labels.append(label)
+ add_child(label)
+ elif difference < 0:
+ for idx in range(abs(difference)):
+ var label = labels.pop_back()
+ labels_pool.append(label)
+ remove_child(label)
+
+ if difference != 0:
+ for idx in range(min(num_labels, items.size())):
+ labels[idx].text = items[idx]
+
+ print_debug("> %s" % labels.size())
+
+ var position := Vector2.ZERO
+ for it in labels:
+ it.rect_position = position
+ it.rect_size.y = 0
+# var rect_size = font.get_wordwrap_string_size((it as Label).text, it.rect_size.x)
+# it.rect_size.y = rect_size.y
+ position.y += it.rect_size.y
+
+func max_required_labels() -> int:
+ var max_labels := ceil(rect_size.y / font.get_height()) + 1
+ return int(min(items.size(), max_labels))
+
+#func _draw():
+# var position := Vector2(0.0, font.get_height())
+# for it in items:
+# var p = font.get_wordwrap_string_size(it, limit)
+# print_debug("> %s : %s" % [p, it])
+# draw_string(font, position, it, Color.white, limit)
+# font.get_string_size(it)
+# position.y += p.y
+
diff --git a/option_set/option_set_list.tscn b/option_set/option_set_list.tscn
new file mode 100644
index 0000000..f8361fa
--- /dev/null
+++ b/option_set/option_set_list.tscn
@@ -0,0 +1,8 @@
+[gd_scene load_steps=2 format=2]
+
+[ext_resource path="res://option_set/option_set_list.gd" type="Script" id=1]
+
+[node name="option_set_list" type="Control"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+script = ExtResource( 1 )