diff options
| author | dam <dam@gudinoff> | 2022-03-26 12:47:21 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-03-26 12:47:21 +0000 |
| commit | 65c4931e1e23525e2bb6b24aea160e0fd9d0592e (patch) | |
| tree | c7e1dcf5b770852270959e6e6e8dcd26eae5ebd3 | |
| parent | 9ddd8d9774b60528b30b867f32cecfa03ca3a49c (diff) | |
| download | surgery-log-65c4931e1e23525e2bb6b24aea160e0fd9d0592e.tar.zst surgery-log-65c4931e1e23525e2bb6b24aea160e0fd9d0592e.zip | |
WIP of prototype of option set list component: fixed max_required_labels calculation.
| -rw-r--r-- | option_set/option_set_list.gd | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/option_set/option_set_list.gd b/option_set/option_set_list.gd index 7efb162..1be9442 100644 --- a/option_set/option_set_list.gd +++ b/option_set/option_set_list.gd @@ -58,10 +58,14 @@ func _init(): # @DAM This is only used once so, why not inline it? func max_required_labels() -> int: - var max_labels := ceil(rect_size.y / font.get_height()) + 1 + var max_labels := ceil(labels.rect_size.y / get_line_height()) + 1 return int(min(items.size(), max_labels)) +func get_line_height() -> float: + return font.get_height() + font.get_descent() + + func build_labels(): var new_max_required_labels := max_required_labels() var delta := new_max_required_labels - labels.get_child_count() @@ -91,12 +95,20 @@ func process_labels(): # labels_positions.append(0) for it in items: var size := font.get_wordwrap_string_size(it, limit).y - var lines = size / font.get_height() - var height = size + font.get_descent() * lines + + # The get_wordwrap_string_size does not include the vertical spacing for the last line, thus + # we need to include it manually. + # Method 1 +# var lines = size / font.get_height() +# var height = size + font.get_descent() * lines + # Method 2 + var height = get_line_height() * ceil(size / get_line_height()) + # Method 3 - not correct +# var height = size + font.get_descent() + position += height labels_positions.append(position) labels_sizes.append(height) - vscrollbar.raise() func _process(delta): @@ -116,17 +128,20 @@ func _process(delta): var offset_idx := labels_positions.bsearch(bs_value) # offset_idx = 0 + var wasted := 0 var idx := 0 for label in labels.get_children(): if idx + offset_idx >= items.size(): label.text = "" - break # @DAM Or should we use continue? + wasted += 1 + continue +# break # @DAM Or should we use continue? label.text = items[idx + offset_idx] label.rect_position.y = labels_positions[idx + offset_idx] - labels_sizes[idx + offset_idx] - bs_value idx += 1 -# if Engine.get_idle_frames() % 30 == 1: -# print_debug("> %s | %5.3f > %s > %d | lastPos: %s" % [labels.size(), offset, bs_value, offset_idx, labels_positions[-1]]) + if Engine.get_idle_frames() % 30 == 1: + print_debug("Wasted: %s" % wasted) labels.margin_right = -vscrollbar.rect_size.x if vscrollbar.visible else 0.0 |
