Buffer #
PhpTui\Tui\Extension\Core\Widget\BufferWidget
This widget provides access to the Buffer and allows you to mutate it directly in addition to being able to draw widgets.
This is useful if you need to know the context upon which widgets are being drawn (for example the absolute position of the containing area etc).
Example #
Show code
<?php
declare(strict_types=1);
use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Widget\BlockWidget;
use PhpTui\Tui\Extension\Core\Widget\Buffer\BufferContext;
use PhpTui\Tui\Extension\Core\Widget\BufferWidget;
use PhpTui\Tui\Position\Position;
use PhpTui\Tui\Widget\Borders;
require 'vendor/autoload.php';
$display = DisplayBuilder::default()->build();
$display->draw(
BufferWidget::new(function (BufferContext $context): void {
$context->draw(BlockWidget::default()->borders(Borders::ALL));
$context->buffer->putString(Position::at(10, 10), 'Hello World');
})
);
Parameters #
Configure the widget using the builder methods named as follows:
Name | Type | Description |
---|---|---|
widget | Closure(BufferContext $buffer): void | The callback for writing to the buffer. |