aboutsummaryrefslogtreecommitdiff
path: root/option_set/option_set_list.gd
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-03-26 13:03:18 +0000
committerdam <dam@gudinoff>2022-03-26 13:03:18 +0000
commita6d836d53a09c5b2abedccba51ac428fcfc74379 (patch)
tree3528be20950caf281c76fdc4307376abc17a6bae /option_set/option_set_list.gd
parent65c4931e1e23525e2bb6b24aea160e0fd9d0592e (diff)
downloadsurgery-log-a6d836d53a09c5b2abedccba51ac428fcfc74379.tar.zst
surgery-log-a6d836d53a09c5b2abedccba51ac428fcfc74379.zip
WIP of prototype of option set list component: workaround for uninitialized labels.rect_size. Added comments with more to do tasks and ideas.
Diffstat (limited to 'option_set/option_set_list.gd')
-rw-r--r--option_set/option_set_list.gd27
1 files changed, 19 insertions, 8 deletions
diff --git a/option_set/option_set_list.gd b/option_set/option_set_list.gd
index 1be9442..3cff78d 100644
--- a/option_set/option_set_list.gd
+++ b/option_set/option_set_list.gd
@@ -39,11 +39,12 @@ var items: Array = [
"This is the longest item of all, but eventually stops.",
]
+# @DAM List of ideas to implement on this element:
+# - Allow to toggle word-wrap on or off;
+# - Allow to change items;
+# - Only build and process labels when needed;
func _init():
- font = get_font("font")
- connect("resized", self, "build_labels")
-
labels = Control.new()
labels.anchor_right = 1.0
labels.anchor_bottom = 1.0
@@ -55,6 +56,19 @@ func _init():
vscrollbar.grow_horizontal = Control.GROW_DIRECTION_BEGIN
vscrollbar.name = "vscrollbar"
add_child(vscrollbar)
+
+ font = get_font("font")
+ connect("resized", self, "build_labels")
+
+
+# @DAM We connect build_labels to resized during init. This calls build_labels immediately and the
+# labels.rect_size is still not properly set thus, making the max_required_labels to return an
+# incorrect value. To patch this, we are calling build_labels again on the _ready. Maybe we can sort
+# this out in a cleaner way?
+func _ready():
+ build_labels()
+
+
# @DAM This is only used once so, why not inline it?
func max_required_labels() -> int:
@@ -90,9 +104,7 @@ func process_labels():
labels_positions.clear()
labels_sizes.clear()
var position := 0.0
- var limit := rect_size.x
- limit = labels.rect_size.x
-# labels_positions.append(0)
+ var limit := labels.rect_size.x
for it in items:
var size := font.get_wordwrap_string_size(it, limit).y
@@ -127,8 +139,7 @@ func _process(delta):
var bs_value := offset / ratio
var offset_idx := labels_positions.bsearch(bs_value)
-# offset_idx = 0
- var wasted := 0
+ var wasted := 0 # @DAM To be removed.
var idx := 0
for label in labels.get_children():
if idx + offset_idx >= items.size():