diff options
Diffstat (limited to 'option_set/option_set_list.gd')
| -rw-r--r-- | option_set/option_set_list.gd | 27 |
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(): |
