46 lines
1.4 KiB
GDScript
46 lines
1.4 KiB
GDScript
# CustomWindow.gd
|
|
extends VBoxContainer
|
|
class_name UiWindow
|
|
|
|
## Emitted when the custom "Flip" button is pressed.
|
|
signal flip_button_pressed
|
|
signal close_requested(c: Control)
|
|
|
|
@onready var title_bar: PanelContainer = $TitleBar
|
|
@onready var title_label: Label = %TitleLabel
|
|
@onready var flip_button: Button = %FlipButton
|
|
@onready var close_button: Button = %CloseButton
|
|
@onready var content_container: MarginContainer = %ContentContainer
|
|
|
|
var is_dragging: bool = false
|
|
var title: String = ""
|
|
|
|
func _ready():
|
|
# Connect the buttons to their functions
|
|
close_button.pressed.connect(_close) # Or emit_signal("close_requested")
|
|
flip_button.pressed.connect(flip_button_pressed.emit)
|
|
|
|
# Connect the title bar's input signal to handle dragging
|
|
title_bar.gui_input.connect(_on_title_bar_gui_input)
|
|
|
|
# Set the window title from the property
|
|
title_label.text = title
|
|
|
|
func _close():
|
|
close_requested.emit(self)
|
|
|
|
# This function adds your main content (like the PanelFrame) into the window.
|
|
func set_content(content_node: Node):
|
|
for child in content_container.get_children():
|
|
content_container.remove_child(child)
|
|
|
|
content_container.add_child(content_node)
|
|
|
|
func _on_title_bar_gui_input(event: InputEvent):
|
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
|
is_dragging = event.is_pressed()
|
|
|
|
if event is InputEventMouseMotion and is_dragging:
|
|
# When dragging, move the entire window by the mouse's relative motion.
|
|
self.position += event.relative
|