This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/UI/Widgets/ResizablePanel.gd

37 lines
989 B
GDScript3
Raw Permalink Normal View History

2020-07-10 10:37:17 +00:00
tool
extends Panel
export var title = "Unnamed panel" setget set_title
var dragging = false
var resizing = false
var last_origin = Vector2.ZERO
var last_mouse = Vector2.ZERO
func _handle_drag(event):
if event is InputEventMouseButton:
dragging = event.pressed
last_origin = rect_position
last_mouse = event.global_position
if dragging and event is InputEventMouseMotion:
rect_position = last_origin + (event.global_position - last_mouse)
func _handle_resize(event):
if event is InputEventMouseButton:
resizing = event.pressed
last_origin = rect_size
last_mouse = event.global_position
if resizing and event is InputEventMouseMotion:
rect_size = last_origin + (event.global_position - last_mouse)
func _input(event):
if dragging and event is InputEventMouseButton and not event.pressed:
dragging = false
if resizing and event is InputEventMouseButton and not event.pressed:
2020-07-10 10:43:17 +00:00
resizing = false
2020-07-10 10:37:17 +00:00
func set_title(val):
title = val
$DragHandle/Label.text = title