The Text component renders text content in your Glixy application. It provides full control over typography including font family, size, weight, style, and color. Text elements can be positioned, rotated, scaled, and styled just like other Glixy elements.
<script>
import { Stage, Text } from 'glixy';
let host: HTMLElement | null = $state(null);
</script>
<div bind:this={host} class="w-full h-96">
{#if host}
<Stage {host}>
<Text
text="Hello, Glixy!"
x={100}
y={100}
style={{
font: 'Arial',
size: 24,
color: 0x333333
}}
/>
</Stage>
{:else}
<div>Loading stage...</div>
{/if}
</div>The Text component accepts the following properties:
text (string, required)The text content to display.
style (object, required)Text styling configuration with the following properties:
x (number, default: 0)X position of the text in pixels.
y (number, default: 0)Y position of the text in pixels.
z (number, default: 0)Z-index for layering. Higher values appear on top.
width (number, default: 0)Width constraint for the text. If 0, text uses natural width.
height (number, default: 0)Height constraint for the text. If 0, text uses natural height.
rotation (number, default: 0)Rotation angle in radians.
opacity (number, default: 1)Opacity value between 0 (transparent) and 1 (opaque).
scale (object, default: {x: 1, y: 1})Scale factor for the text.
anchor (object, default: {x: 0, y: 0})Anchor point for transformations. {x: 0.5, y: 0.5} centers the anchor.
Important considerations when using the Text component: