Line

Line #

PhpTui\Tui\Extension\Core\Shape\LineShape

Draw a straight line from one point to another.

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\Core\Shape\LineShape;
use PhpTui\Tui\Extension\Core\Widget\CanvasWidget;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    CanvasWidget::fromIntBounds(0, 20, 0, 20)
        ->marker(Marker::Dot)
        ->draw(LineShape::fromScalars(
            0,  // x1
            0,  // y1
            20, // x2
            20, // y2
        )->color(AnsiColor::Green))
);

Parameters #

Configure the shape using the builder methods named as follows:

NameTypeDescription
point1PhpTui\Tui\Position\FloatPositionDraw from this point
point2PhpTui\Tui\Position\FloatPositionDraw to this point
colorPhpTui\Tui\Color\ColorColor of the line