2026-11-09 10:01:10 -06:00
|
|
|
class_name PanelSplitter
|
|
|
|
|
extends Control
|
|
|
|
|
## A drag handle between the board and a docked panel: above the result tray
|
|
|
|
|
## (dragged up and down) or left of the inspector (dragged left and right).
|
|
|
|
|
## Dragging toward the board makes the panel bigger. A double-click puts back
|
|
|
|
|
## the default size. The panel's size is kept in local settings under
|
|
|
|
|
## `setting` when the drag ends.
|
|
|
|
|
|
|
|
|
|
signal size_changed(px: float)
|
|
|
|
|
|
|
|
|
|
const THICK := 7.0
|
|
|
|
|
const GRIP := 36.0
|
|
|
|
|
|
|
|
|
|
var main: Main
|
|
|
|
|
## True for a handle dragged up and down (it sizes a panel's height).
|
|
|
|
|
var vertical := true
|
2026-11-10 18:50:32 -06:00
|
|
|
## The panel sits before the handle (the List on the left): moving away from it
|
|
|
|
|
## grows it.
|
|
|
|
|
var before := false
|
2026-11-09 10:01:10 -06:00
|
|
|
var setting := ""
|
|
|
|
|
var size_px := 0.0
|
|
|
|
|
var default_px := 0.0
|
|
|
|
|
var min_px := 0.0
|
|
|
|
|
## The panel never takes more than this share of the window.
|
|
|
|
|
var max_share := 0.7
|
|
|
|
|
|
|
|
|
|
var _dragging := false
|
|
|
|
|
var _hover := false
|
|
|
|
|
var _from := 0.0
|
|
|
|
|
var _start := 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init(p_main: Main, p_vertical: bool, p_setting: String, p_default: float, p_min: float) -> void:
|
|
|
|
|
main = p_main
|
|
|
|
|
vertical = p_vertical
|
|
|
|
|
setting = p_setting
|
|
|
|
|
default_px = p_default
|
|
|
|
|
min_px = p_min
|
|
|
|
|
size_px = p_default
|
|
|
|
|
if main and main.state:
|
|
|
|
|
size_px = float(main.state.get_setting(setting, p_default))
|
|
|
|
|
custom_minimum_size = Vector2(0, THICK) if vertical else Vector2(THICK, 0)
|
|
|
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
|
|
|
mouse_default_cursor_shape = Control.CURSOR_VSIZE if vertical else Control.CURSOR_HSIZE
|
|
|
|
|
tooltip_text = "Drag to resize · double-click for the default size"
|
|
|
|
|
mouse_entered.connect(func() -> void:
|
|
|
|
|
_hover = true
|
|
|
|
|
queue_redraw()
|
|
|
|
|
)
|
|
|
|
|
mouse_exited.connect(func() -> void:
|
|
|
|
|
_hover = false
|
|
|
|
|
queue_redraw()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
# A smaller window shrinks a panel that no longer fits.
|
|
|
|
|
get_viewport().size_changed.connect(func() -> void:
|
|
|
|
|
if size_px > max_px():
|
|
|
|
|
set_size_px(size_px)
|
|
|
|
|
)
|
|
|
|
|
if size_px > max_px():
|
|
|
|
|
set_size_px.call_deferred(size_px)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The largest size allowed now: a share of the area the handle divides
|
|
|
|
|
## (its parent container), or of the window.
|
|
|
|
|
func max_px() -> float:
|
|
|
|
|
var area := Vector2(1600, 1000)
|
|
|
|
|
if get_parent() is Control and (get_parent() as Control).size != Vector2.ZERO:
|
|
|
|
|
area = (get_parent() as Control).size
|
|
|
|
|
elif is_inside_tree():
|
|
|
|
|
area = get_viewport_rect().size
|
|
|
|
|
return maxf(min_px, (area.y if vertical else area.x) * max_share)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Sets the panel's size (clamped) and tells the panel. `save` stores it.
|
|
|
|
|
func set_size_px(px: float, save: bool = false) -> void:
|
|
|
|
|
size_px = clampf(px, min_px, max_px())
|
|
|
|
|
size_changed.emit(size_px)
|
|
|
|
|
if save and main and main.state:
|
|
|
|
|
main.state.set_setting(setting, roundi(size_px))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _gui_input(ev: InputEvent) -> void:
|
|
|
|
|
if ev is InputEventMouseButton and (ev as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT:
|
|
|
|
|
var mb := ev as InputEventMouseButton
|
|
|
|
|
if mb.double_click:
|
|
|
|
|
_dragging = false
|
|
|
|
|
set_size_px(default_px, true)
|
|
|
|
|
elif mb.pressed:
|
|
|
|
|
_dragging = true
|
|
|
|
|
_from = _axis(mb.global_position)
|
|
|
|
|
_start = size_px
|
|
|
|
|
elif _dragging:
|
|
|
|
|
_dragging = false
|
|
|
|
|
set_size_px(size_px, true)
|
|
|
|
|
accept_event()
|
|
|
|
|
queue_redraw()
|
|
|
|
|
elif ev is InputEventMouseMotion and _dragging:
|
2026-11-10 18:50:32 -06:00
|
|
|
# Moving toward the board grows the panel.
|
|
|
|
|
var moved := _axis((ev as InputEventMouseMotion).global_position) - _from
|
|
|
|
|
set_size_px(_start + moved if before else _start - moved)
|
2026-11-09 10:01:10 -06:00
|
|
|
accept_event()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _axis(p: Vector2) -> float:
|
|
|
|
|
return p.y if vertical else p.x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _draw() -> void:
|
Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.
ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00
|
|
|
draw_rect(Rect2(Vector2.ZERO, size), Style.PANEL)
|
2026-11-09 10:01:10 -06:00
|
|
|
var lit := _hover or _dragging
|
Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.
ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00
|
|
|
var c := Style.ACCENT if lit else Color(1, 1, 1, 0.18)
|
2026-11-09 10:01:10 -06:00
|
|
|
var mid := size / 2.0
|
|
|
|
|
var r := Rect2(mid - Vector2(GRIP / 2.0, 1.5), Vector2(GRIP, 3)) if vertical \
|
|
|
|
|
else Rect2(mid - Vector2(1.5, GRIP / 2.0), Vector2(3, GRIP))
|
|
|
|
|
draw_rect(r, c)
|