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
2020-07-21 10:51:15 +02:00

37 lines
959 B
GDScript

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 event is InputEventMouseButton:
if dragging and not event.pressed:
dragging = false
if resizing and not event.pressed:
resizing = false
func set_title(val):
title = val
$DragHandle/Label.text = title