- Add UiStyles with explicit normal, hover, pressed, focus and disabled styles and apply it to every action button. - Disable timeline Previous/Next at the first/last event and keep Close always available. - Style settings reset-dialog buttons and cover the button-state audit in docs/ui-copy.md. - Add shared-state and timeline-boundary regression tests.
59 lines
2.4 KiB
GDScript
59 lines
2.4 KiB
GDScript
class_name UiStyles
|
|
extends RefCounted
|
|
## Shared button states for the dark session/UI shell.
|
|
##
|
|
## Keeping one style table means every normal/hover/pressed/focused/disabled
|
|
## state is explicit. Buttons that use the Godot default theme otherwise look
|
|
## different from the custom start-menu, pause and review rows as soon as they
|
|
## are disabled or receive keyboard focus.
|
|
|
|
const TEXT := Color(0.94, 0.94, 0.92)
|
|
const TEXT_HOVER := Color.WHITE
|
|
const TEXT_DISABLED := Color(0.48, 0.50, 0.56)
|
|
const SURFACE := Color(0.115, 0.125, 0.15, 0.96)
|
|
const SURFACE_HOVER := Color(0.16, 0.175, 0.21, 0.98)
|
|
const SURFACE_PRESSED := Color(0.075, 0.085, 0.105, 0.98)
|
|
const SURFACE_DISABLED := Color(0.075, 0.08, 0.095, 0.72)
|
|
const ACCENT := Color(0.78, 0.82, 0.88, 0.9)
|
|
|
|
static func apply_button(button: Button, font_size: int = 0, compact: bool = false) -> void:
|
|
if button == null:
|
|
return
|
|
if font_size > 0:
|
|
button.add_theme_font_size_override("font_size", font_size)
|
|
var margin_h := 12 if compact else 18
|
|
var margin_v := 7 if compact else 10
|
|
var normal := _box(SURFACE, margin_h, margin_v)
|
|
var hover := _box(SURFACE_HOVER, margin_h, margin_v)
|
|
var pressed := _box(SURFACE_PRESSED, margin_h, margin_v)
|
|
var disabled := _box(SURFACE_DISABLED, margin_h, margin_v)
|
|
var focus := _box(Color(0, 0, 0, 0), margin_h, margin_v)
|
|
focus.border_color = ACCENT
|
|
focus.border_width_left = 2
|
|
focus.border_width_top = 2
|
|
focus.border_width_right = 2
|
|
focus.border_width_bottom = 2
|
|
button.add_theme_stylebox_override("normal", normal)
|
|
button.add_theme_stylebox_override("hover", hover)
|
|
button.add_theme_stylebox_override("pressed", pressed)
|
|
button.add_theme_stylebox_override("focus", focus)
|
|
button.add_theme_stylebox_override("disabled", disabled)
|
|
button.add_theme_color_override("font_color", TEXT)
|
|
button.add_theme_color_override("font_hover_color", TEXT_HOVER)
|
|
button.add_theme_color_override("font_pressed_color", TEXT_HOVER)
|
|
button.add_theme_color_override("font_focus_color", TEXT_HOVER)
|
|
button.add_theme_color_override("font_disabled_color", TEXT_DISABLED)
|
|
|
|
static func _box(color: Color, margin_h: int, margin_v: int) -> StyleBoxFlat:
|
|
var box := StyleBoxFlat.new()
|
|
box.bg_color = color
|
|
box.corner_radius_top_left = 10
|
|
box.corner_radius_top_right = 10
|
|
box.corner_radius_bottom_left = 10
|
|
box.corner_radius_bottom_right = 10
|
|
box.content_margin_left = margin_h
|
|
box.content_margin_right = margin_h
|
|
box.content_margin_top = margin_v
|
|
box.content_margin_bottom = margin_v
|
|
return box
|