#92: shrink the confirm popup to the window it is in
The card is authored at a fixed 704x1200 around a portrait phone. On a window wider than it is tall the stretched canvas is about 1080 units high, so the card sat at y=-60 and hung over both edges - and the confirm and cancel buttons are anchored to its own bottom edge, so they went off screen with it. The popup was not merely ugly on a desktop, it was a dead end: nothing on it could be pressed. NeonPanel now fits itself to the viewport and re-fits when the window changes. It only ever shrinks; growing the card would stretch proportions that are tuned rather than fluid. The fitting adjusts offsets around a fixed centre, so it applies only to a card pinned to a point - a panel stretched between different anchors already follows its parent and is left alone. Verified across portrait, 16:9, ultrawide and small-laptop shapes, on the card and on both buttons. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
4883197ef3
commit
01f053e01a
3 changed files with 163 additions and 0 deletions
|
|
@ -7,6 +7,17 @@ extends Control
|
|||
# hard-edged neon of the buttons and HUD.
|
||||
#
|
||||
# Draws itself from its own rect, so it can be sized freely in the scene.
|
||||
#
|
||||
# #92: it also SHRINKS itself to whatever window it is in. The card is
|
||||
# authored at a fixed size around a portrait phone, and on a landscape
|
||||
# window - where the canvas is far wider than it is tall - a card taller
|
||||
# than the screen simply ran off the top and the bottom, taking the confirm
|
||||
# and cancel buttons with it. The buttons are anchored to the panel's own
|
||||
# bottom edge, so bringing the edge back on screen brings them back too.
|
||||
#
|
||||
# Only ever shrinks. Growing the card on a big screen would blow the
|
||||
# authored proportions up with it, and the layout inside is tuned, not
|
||||
# fluid.
|
||||
|
||||
@export var glow_color: Color = Color(0.25, 0.85, 1.0)
|
||||
@export var core_color: Color = Color(1.0, 1.0, 1.0)
|
||||
|
|
@ -15,6 +26,47 @@ extends Control
|
|||
@export var fill_color: Color = Color(0.02, 0.03, 0.07, 1.0)
|
||||
@export var corner_cut: float = 26.0
|
||||
@export var bracket_length: float = 46.0
|
||||
# Breathing room kept between the card and the edge of the screen, so a
|
||||
# fitted panel reads as a card on a backdrop rather than as a full-bleed
|
||||
# page that happens to have a border.
|
||||
@export var screen_margin: float = 24.0
|
||||
|
||||
# The size the card was authored at, and the point it is centred on. Read
|
||||
# once, before any fitting has happened - re-reading them later would
|
||||
# measure a previous fit and let the card ratchet smaller on every resize.
|
||||
var design_size: Vector2 = Vector2.ZERO
|
||||
var design_centre: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Fitting adjusts the four offsets around a fixed centre, which is only
|
||||
# meaningful for a card pinned to a point - both anchor pairs collapsed,
|
||||
# as a centred dialog's are. A panel stretched between different anchors
|
||||
# already follows its parent and is left alone.
|
||||
if not (is_equal_approx(anchor_left, anchor_right) \
|
||||
and is_equal_approx(anchor_top, anchor_bottom)):
|
||||
return
|
||||
design_size = Vector2(offset_right - offset_left, offset_bottom - offset_top)
|
||||
design_centre = Vector2(offset_left + offset_right, offset_top + offset_bottom) * 0.5
|
||||
get_viewport().size_changed.connect(_fit_to_screen)
|
||||
_fit_to_screen()
|
||||
|
||||
|
||||
func _fit_to_screen() -> void:
|
||||
if design_size == Vector2.ZERO:
|
||||
return
|
||||
# The viewport rect, not the window: with stretch/mode "canvas_items" the
|
||||
# UI is laid out in stretched canvas units, and those are the units these
|
||||
# offsets are in.
|
||||
var available: Vector2 = get_viewport_rect().size - Vector2(screen_margin, screen_margin) * 2.0
|
||||
var fitted: Vector2 = Vector2(
|
||||
minf(design_size.x, maxf(available.x, 0.0)),
|
||||
minf(design_size.y, maxf(available.y, 0.0)))
|
||||
offset_left = design_centre.x - fitted.x * 0.5
|
||||
offset_right = design_centre.x + fitted.x * 0.5
|
||||
offset_top = design_centre.y - fitted.y * 0.5
|
||||
offset_bottom = design_centre.y + fitted.y * 0.5
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
|
|
|
|||
Loading…
Reference in a new issue