Skip to content

Container's content margins not taken into account #75

@SamiLaakso

Description

@SamiLaakso

When content margins are applied to the ScrollContainer using a StyleBox, the smooth scrolling no longer works properly. Here are the edits I added to make them work. I didn't make a push request as I'm still very new to Git. Feel free to implement these to help everyone using the plugin! :)

New variables:

var content_margin_top:= 0.0
var content_margin_bottom:= 0.0
var content_margin_left:= 0.0
var content_margin_right:= 0.0

_ready() (this might need some way to check if there is a style box set or not):

var style_box = get_theme_stylebox("panel")
content_margin_top = style_box.content_margin_top
content_margin_bottom = style_box.content_margin_bottom
content_margin_left = style_box.content_margin_left
content_margin_right = style_box.content_margin_right

scroll(), under 'if vertical':

content_node.position.y += content_margin_top

scroll(), under 'else' (horizontal):

content_node.position.x += content_margin_left

get_child_size_x_diff():

child_size_x += content_margin_left + content_margin_right

get_child_size_y_diff():

child_size_y += content_margin_top + content_margin_bottom

ensure_control_visible() (this replaces the last part):

if boundary_dist.x < 0 + follow_focus_margin + content_margin_left:
	# Scroll left
	scroll_x_to(content_node_position.x - boundary_dist.x + follow_focus_margin)
elif boundary_dist.y > 0 - follow_focus_margin - content_margin_right:
	# Scroll right
	scroll_x_to(content_node_position.x - boundary_dist.y - follow_focus_margin - content_margin_left - content_margin_right)
if boundary_dist.z < 0 + follow_focus_margin + content_margin_top:
	# Scroll up
	scroll_y_to(content_node_position.y - boundary_dist.z + follow_focus_margin)
elif boundary_dist.w > 0 - follow_focus_margin - content_margin_bottom:
	# Scroll down
	scroll_y_to(content_node_position.y - boundary_dist.w - follow_focus_margin - content_margin_top - content_margin_bottom)

PS. Thanks for the plugin, it is great!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions