Linear Gradient

Linear Gradient #

PhpTui\Tui\Color\LinearGradient

Multi-stop linear gradient with optional angle and point of origin.

This color is not supported by all widgets. In the case that the widget does not support gradient fills the first stop color will be used.

Example #

Show code
<?php

declare(strict_types=1);

use PhpTui\Tui\Color\LinearGradient;
use PhpTui\Tui\Color\RgbColor;
use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Widget\GaugeWidget;
use PhpTui\Tui\Style\Style;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    GaugeWidget::default()
        ->ratio(1)
        ->style(
            Style::default()
                ->fg(
                    LinearGradient::from(RgbColor::fromHex('#ffaaaa'))
                        ->addStop(0.5, RgbColor::fromHex('#aaffaa'))
                        ->addStop(1, RgbColor::fromHex('#aaaaff'))
                )
        )
);

Parameters #

Configure the color using the builder methods named as follows:

NameTypeDescription
stopsarray
anglefloat
originPhpTui\Tui\Position\FractionalPosition