Good-looking UI
The GUI's widgets work out of the box. A consistent palette, clear type hierarchy and a little motion give a menu its own character.
This example takes inspiration from Material Design: a light surface, purple primary and tonal actions, pill-shaped buttons and subtle state layers. Settings opens a compact card; Play shows a snackbar. It uses Tide's built-in font and widgets, so it is an interpretation rather than a complete Material component library.
Hover the buttons, open Settings, and press Play. Keyboard and gamepad focus have a visible outline.
// A Material-inspired menu: tonal surfaces, pill buttons and soft state layers.
scene Main { }
const Color INK = Color(0.11, 0.10, 0.13);
const Color MUTED = Color(0.29, 0.27, 0.32);
const Color SURFACE = Color(0.99, 0.97, 1);
const Color PRIMARY = Color(0.40, 0.31, 0.64);
const Color TONAL = Color(0.91, 0.87, 0.98);
local singleton Menu
{
bool options;
bool music = true;
float volume = 0.7;
int played;
}
// Flat surfaces and a quiet shadow; custom buttons share this transition time.
const GUITheme LOOK = GUITheme {
text = INK, panel = Color(0.95, 0.92, 0.98), control = TONAL,
hot = Color(0.85, 0.80, 0.94), pressed = Color(0.79, 0.73, 0.88), accent = PRIMARY,
radius = 20, shading = 0, borderWidth = 0,
shadow = Color(0.11, 0.10, 0.13, 0.10), shadowSize = 8,
textSize = 16, padding = 20, spacing = 10, transition = 0.15 };
// Material-style state layers keep the button still as hover and press ease in.
bool MaterialButton(Rect rect, string text, bool filled)
{
var button = GUI.Control(rect);
var base = filled ? PRIMARY : TONAL;
var foreground = filled ? Color.white : PRIMARY;
GUI.Draw()
{
Draw.Rect(rect, 24, base);
Draw.Rect(rect, 24, foreground.WithAlpha(button.hover * 0.08 + button.press * 0.12));
if (button.focus > 0)
Draw.WireRoundRect(float2(rect.x + rect.width * 0.5, rect.y + rect.height * 0.5),
float2(rect.width + 8, rect.height + 8), 28, 2, PRIMARY.WithAlpha(button.focus));
Draw.Text(text, float2(rect.x + rect.width * 0.5, rect.y + rect.height * 0.5),
16, foreground, Anchor.MiddleCenter, Font.Bold);
}
return button.clicked;
}
view MainMenu(mut Menu menu)
{
Draw.SetScreen();
GUI.SetTheme(LOOK);
Draw.Rect(Screen.rect, SURFACE);
var middle = Screen.width * 0.5;
var width = Math.Min(312.0, Screen.width - 48);
var left = middle - width * 0.5;
var top = Math.Max(24.0, (Screen.height - 360) * 0.5);
// A small brand mark leaves the title and actions room to breathe.
Draw.Rect(Rect(middle - 24, top, 48, 48), 16, TONAL);
Draw.Text("S", float2(middle, top + 24), 28, PRIMARY, Anchor.MiddleCenter, Font.Bold);
Draw.Text("Skyward", float2(middle, top + 84), 36, INK, Anchor.MiddleCenter);
Draw.Text("A little room for adventure.", float2(middle, top + 120), 16, MUTED, Anchor.MiddleCenter);
// Settings replaces the actions, keeping a narrow embedded demo uncluttered.
var shown = GUI.Animate(menu.options ? 1.0 : 0.0, 0.22);
if (!menu.options && shown < 0.01)
{
if (MaterialButton(Rect(left, top + 164, width, 48), "Play", true)) menu.played++;
if (MaterialButton(Rect(left, top + 224, width, 48), "Settings", false)) menu.options = true;
Draw.Text("MAKE YOURSELF AT HOME", float2(middle, top + 308), 11, MUTED, Anchor.MiddleCenter);
}
if (shown > 0.001)
{
// One compact card, eased up into place, with ordinary themed widgets.
GUILayout.Area(Rect(left, top + 140 + (1 - shown) * 24, width, 188))
{
GUILayout.Label("Sound & music", 20);
GUILayout.Toggle("Music", menu.music);
GUILayout.Slider("Volume", menu.volume, 0, 1);
if (GUILayout.Button("Done")) menu.options = false;
}
}
// The snackbar acknowledges this example's Play action.
if (menu.played > 0 && !menu.options && shown < 0.01)
{
GUI.Key(menu.played)
{
var fade = GUI.Animate(1, 0.25, 0);
GUI.Draw()
{
var at = Rect(left, Screen.height - 88 + (1 - fade) * 8, width, 40);
Draw.Rect(at, 8, INK.WithAlpha(fade));
Draw.Text("Ready for takeoff.", float2(middle, at.y + 20), 14,
SURFACE.WithAlpha(fade), Anchor.MiddleCenter);
}
}
}
}A theme
Set one theme for the menu's widgets, rather than a color here and there. A few numbers change the most:
const GUITheme LOOK = GUITheme {
text = INK, panel = Color(0.95, 0.92, 0.98), control = TONAL,
hot = Color(0.85, 0.80, 0.94), pressed = Color(0.79, 0.73, 0.88), accent = PRIMARY,
radius = 20, shading = 0, borderWidth = 0,
shadow = Color(0.11, 0.10, 0.13, 0.10), shadowSize = 8,
textSize = 16, padding = 20, spacing = 10, transition = 0.15 };Wrap widgets in GUI.Theme(LOOK) { ... }, or call GUI.SetTheme(LOOK) at the start of the view. The example uses flat tonal surfaces (shading = 0) and a quiet panel shadow. Give primary actions a strong fill, secondary actions a softer tone, and text enough contrast against both. textSize, padding and spacing establish a consistent scale.
Gradients and shadows
Never build a gradient from strips of rectangles: give the shape a fill. A fill is a function the GPU runs for each pixel, and Gradient's functions are the common ones:
// The screen's background, lighter at the top
Draw.Rect(Rect(0, 0, Screen.width, Screen.height), 0, Gradient.Vertical(Color(0.1, 0.12, 0.24), Color(0.04, 0.05, 0.1)));
// A raised button
Draw.Rect(rect, 14, Gradient.Vertical(Color(0.35, 0.55, 1), Color(0.25, 0.4, 0.85)));
// A glow behind a title, fading to nothing
Draw.Rect(Rect(x - 220, y - 100, 440, 200), 100, Gradient.Radial(Color(0.35, 0.45, 1, 0.35), Color.clear));A shadow goes under a box, drawn first: Draw.Shadow(rect, radius, size) is a soft dark shape the box's size, fading out over size pixels and a little lower. A light color, Draw.Shadow(rect, radius, size, Color(1, 0.8, 0.3, 0.5)), is a glow.
Draw.Shadow(card, 14, 12);
Draw.Rect(card, 14, Gradient.Vertical(Color(0.17, 0.15, 0.25), Color(0.09, 0.08, 0.14)));A heading is a label at a size of its own, GUILayout.Label("Settings", 24), and color.WithAlpha(a) fades any color, like a glow of an item's rarity color: glow.WithAlpha(0.6 * chosen).
Fills drawn one after another are drawn together, so a screen of gradient buttons costs no more than one.
Controls that ease
A control says how hovered, pressed and focused it is as amounts from 0 to 1, hover, press and focus, which ease over the theme's transition. Blend by them rather than switching on hovered:
bool MaterialButton(Rect rect, string text)
{
var button = GUI.Control(rect);
GUI.Draw()
{
Draw.Rect(rect, 24, PRIMARY);
Draw.Rect(rect, 24, Color.white.WithAlpha(button.hover * 0.08 + button.press * 0.12));
Draw.Text(text, float2(rect.x + rect.width * 0.5, rect.y + rect.height * 0.5),
16, Color.white, Anchor.MiddleCenter, Font.Bold);
}
return button.clicked;
}A translucent state layer makes interaction visible while keeping the button's position stable. The complete example also draws focus as an outline so players on a gamepad or keyboard see where they are.
Panels that move
GUI.Animate(target, seconds) eases a value toward its target from frame to frame. Give it what the panel should be, open or closed, and draw the panel by what it gives:
var shown = GUI.Animate(menu.options ? 1.0 : 0.0, 0.3);
if (shown > 0)
{
GUILayout.Area(Rect(Screen.width - 340 * shown, 180, 320, 220)) // In from the right
{
// ...
}
}It settles exactly on its target, so shown > 0 stops drawing the panel once it has slid out. Something that should come in as it first appears starts from a value of its own: GUI.Animate(1, 0.4, 0) goes from 0 to 1 the first time it's called. Keyed with GUI.Key, a new key starts again, as the snackbar above does each time Play is pressed.
A panel at an anchor needs none of this to change size smoothly: GUILayout.Area(Anchor.MiddleCenter) grows and shrinks to its content by itself, as the tabs of a dialog change. For a tooltip, keep what it shows while it fades, and keep it on the screen with rect.MoveInside(Screen.rect) (see Animation).
For a fixed-length animation, a slide that eases in and out or a pop that overshoots, GUI.Tween gives a progress that takes exactly its time, and Math.EaseInOut, Math.EaseOutBack and the rest shape it. A panel that's warped or bent as a whole draws its widgets into a render target with GUI.Target.
An animated value goes to GPU code like any other: a fill's lambda reads it, and a frag is given it in its draw's values. Animate on the CPU and shape on the GPU: a wipe whose edge eases, a glow that pulses with a button's hover. See Animated values in GPU code.
Animate positions, sizes, colors and alpha; keep times short, a tenth to a third of a second, so the menu feels quick.