Text #
PhpTui\Tui\Extension\Bdf\Shape\TextShape
Renders text on the canvas.
This widget requires a bitmap font in the BDF format.
You can use the PhpTui\Tui\Adapter\Bdf\FontRegistry
to
load and manage fonts. It has a default font built in.
Example #
Show code
<?php
declare(strict_types=1);
use PhpTui\Tui\Canvas\Marker;
use PhpTui\Tui\Color\AnsiColor;
use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Bdf\BdfExtension;
use PhpTui\Tui\Extension\Bdf\FontRegistry;
use PhpTui\Tui\Extension\Bdf\Shape\TextShape;
use PhpTui\Tui\Extension\Core\Widget\CanvasWidget;
use PhpTui\Tui\Position\FloatPosition;
require 'vendor/autoload.php';
// create the font registry
// this is EXPENSIVE to create, only do it once!
$registry = FontRegistry::default();
$display = DisplayBuilder::default()
->addExtension(new BdfExtension())
->build();
$display->draw(
CanvasWidget::fromIntBounds(0, 50, 0, 20)
->marker(Marker::Block)
->draw(
new TextShape(
font: 'default',
text: 'Hello!',
color: AnsiColor::Green,
position: FloatPosition::at(10, 7),
),
)
);
Parameters #
Configure the shape using the builder methods named as follows:
Name | Type | Description |
---|---|---|
font | string | Font name as it is known in the font registry |
text | string | Text to render |
color | PhpTui\Tui\Color\Color | Color of the text |
position | PhpTui\Tui\Position\FloatPosition | Position of the text (bottom left corner) |
scaleX | float | Horizontal scale of the font |
scaleY | float | Verttical scale of the font |