Added Label
This commit is contained in:
parent
949cd47c96
commit
82cfa6c80d
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PHPNative\Ui\Widget\Label;
|
||||||
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
// Check PHP version
|
// Check PHP version
|
||||||
@ -10,6 +12,11 @@ if (PHP_VERSION_ID < 80100) {
|
|||||||
$app = new \PHPNative\Framework\Application('ToDo Demo', 700, 500);
|
$app = new \PHPNative\Framework\Application('ToDo Demo', 700, 500);
|
||||||
$container = new \PHPNative\Ui\Widget\Container(style: 'm-10 p-10 rounded-xl bg-lime-200');
|
$container = new \PHPNative\Ui\Widget\Container(style: 'm-10 p-10 rounded-xl bg-lime-200');
|
||||||
$containerMenu = new \PHPNative\Ui\Widget\Container(style: 'bg-lime-700');
|
$containerMenu = new \PHPNative\Ui\Widget\Container(style: 'bg-lime-700');
|
||||||
|
$label = new Label(
|
||||||
|
text: 'Todo App',
|
||||||
|
style: 'text-xl2 text-red-500',
|
||||||
|
);
|
||||||
|
$containerMenu->addComponent($label);
|
||||||
$container->addComponent($containerMenu);
|
$container->addComponent($containerMenu);
|
||||||
$app->setRoot($container);
|
$app->setRoot($container);
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|||||||
@ -8,7 +8,6 @@ class Container
|
|||||||
{
|
{
|
||||||
public static function layout(Viewport $viewport, \PHPNative\UI\Widget\Container $view, int $index = 0): Viewport
|
public static function layout(Viewport $viewport, \PHPNative\UI\Widget\Container $view, int $index = 0): Viewport
|
||||||
{
|
{
|
||||||
var_dump('test');
|
|
||||||
return $viewport;
|
return $viewport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ abstract class Component
|
|||||||
protected Viewport $viewport;
|
protected Viewport $viewport;
|
||||||
|
|
||||||
protected array $computedStyles = [];
|
protected array $computedStyles = [];
|
||||||
private Viewport $contentViewport;
|
protected Viewport $contentViewport;
|
||||||
|
|
||||||
public function setViewport(Viewport $viewport): void
|
public function setViewport(Viewport $viewport): void
|
||||||
{
|
{
|
||||||
|
|||||||
44
src/Ui/Widget/Label.php
Normal file
44
src/Ui/Widget/Label.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PHPNative\Ui\Widget;
|
||||||
|
|
||||||
|
use PHPNative\Framework\TextRenderer;
|
||||||
|
use PHPNative\Tailwind\Style\Text;
|
||||||
|
use PHPNative\Ui\Component;
|
||||||
|
|
||||||
|
class Label extends Component
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $text = '',
|
||||||
|
public string $style = '',
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function setText(string $text): void
|
||||||
|
{
|
||||||
|
$this->text = $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderContent(null|TextRenderer $textRenderer = null): void
|
||||||
|
{
|
||||||
|
if (!$this->visible || $textRenderer === null || !$textRenderer->isInitialized()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get text style from computed styles
|
||||||
|
$textStyle = $this->computedStyles[Text::class] ?? new Text();
|
||||||
|
|
||||||
|
// Set text color
|
||||||
|
$color = $textStyle->color;
|
||||||
|
$textRenderer->setColor($color->red / 255, $color->green / 255, $color->blue / 255, $color->alpha / 255);
|
||||||
|
|
||||||
|
// Calculate text position based on alignment
|
||||||
|
$x = $this->contentViewport->x;
|
||||||
|
$y = $this->contentViewport->y;
|
||||||
|
|
||||||
|
// Draw the text
|
||||||
|
$textRenderer->drawText($this->text, (int) $x, (int) $y, $textStyle->size);
|
||||||
|
|
||||||
|
// Call parent to render children if any
|
||||||
|
parent::renderContent($textRenderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user