Files
2026-08-29 11:42:54 +02:00

57 lines
1.8 KiB
GDScript

class_name UiKit
extends RefCounted
## Kleine Helfer für die primitiven UI-Bausteine.
static func flat(bg: Color, border: Color = Color(0, 0, 0, 0), radius: int = 6) -> StyleBoxFlat:
var sb := StyleBoxFlat.new()
sb.bg_color = bg
sb.corner_radius_top_left = radius
sb.corner_radius_top_right = radius
sb.corner_radius_bottom_left = radius
sb.corner_radius_bottom_right = radius
if border.a > 0.0:
sb.border_color = border
sb.set_border_width_all(2)
sb.content_margin_left = 6
sb.content_margin_right = 6
sb.content_margin_top = 4
sb.content_margin_bottom = 4
return sb
static func panel(bg: Color) -> PanelContainer:
var p := PanelContainer.new()
p.add_theme_stylebox_override("panel", flat(bg))
return p
static func label(text: String, size: int = 14, col: Color = Color(0.9, 0.9, 0.95)) -> Label:
var l := Label.new()
l.text = text
l.add_theme_font_size_override("font_size", size)
l.add_theme_color_override("font_color", col)
return l
static func button(text: String, bg: Color, fg: Color = Color(1, 1, 1)) -> Button:
var b := Button.new()
b.text = text
b.add_theme_stylebox_override("normal", flat(bg))
b.add_theme_stylebox_override("hover", flat(bg.lightened(0.12)))
b.add_theme_stylebox_override("pressed", flat(bg.darkened(0.15)))
b.add_theme_stylebox_override("disabled", flat(bg.darkened(0.45)))
b.add_theme_color_override("font_color", fg)
b.add_theme_color_override("font_hover_color", fg)
b.add_theme_color_override("font_disabled_color", Color(fg, 0.45))
b.add_theme_font_size_override("font_size", 14)
b.clip_text = true
# Ohne das würde der zuletzt geklickte Knopf die Leertaste abfangen.
b.focus_mode = Control.FOCUS_NONE
return b
## Lesbare Textfarbe zu einem Hintergrund.
static func ink(bg: Color) -> Color:
return Color(0.06, 0.06, 0.08) if bg.get_luminance() > 0.5 else Color(0.96, 0.96, 1.0)