134 lines
4.5 KiB
PHP
134 lines
4.5 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use PHPNative\Framework\Application;
|
|
use PHPNative\Ui\Widget\Container;
|
|
use PHPNative\Ui\Widget\Label;
|
|
use PHPNative\Ui\Widget\Menu;
|
|
use PHPNative\Ui\Widget\MenuBar;
|
|
use PHPNative\Ui\Widget\StatusBar;
|
|
use PHPNative\Ui\Widget\TabContainer;
|
|
use PHPNative\Ui\Widget\Table;
|
|
use PHPNative\Ui\Window;
|
|
|
|
$app = new Application();
|
|
$window = new Window('Windows Application Example', 800, 600);
|
|
|
|
// Main container (flex-col: menu, content, status)
|
|
$mainContainer = new Container('flex flex-col bg-gray-100');
|
|
|
|
// === 1. MenuBar ===
|
|
$menuBar = new MenuBar();
|
|
|
|
// File Menu
|
|
$fileMenu = new Menu(title: 'Datei');
|
|
$fileMenu->addItem('Neu', function () {
|
|
echo "Neu clicked\n";
|
|
});
|
|
$fileMenu->addItem('Öffnen', function () {
|
|
echo "Öffnen clicked\n";
|
|
});
|
|
$fileMenu->addSeparator();
|
|
$fileMenu->addItem('Beenden', function () use ($app) {
|
|
echo "Beenden clicked\n";
|
|
exit(0);
|
|
});
|
|
|
|
// Settings Menu
|
|
$settingsMenu = new Menu(title: 'Einstellungen');
|
|
$settingsMenu->addItem('Optionen', function () {
|
|
echo "Optionen clicked\n";
|
|
});
|
|
$settingsMenu->addItem('Sprache', function () {
|
|
echo "Sprache clicked\n";
|
|
});
|
|
$menuBar->addMenu($fileMenu);
|
|
$menuBar->addMenu($settingsMenu);
|
|
$mainContainer->addComponent($menuBar);
|
|
|
|
// === 2. Tab Container (flex-1) ===
|
|
$tabContainer = new TabContainer('flex-1');
|
|
|
|
// Tab 1: Table with data
|
|
$tab1 = new Container('flex flex-col p-4');
|
|
$table = new Table(style: 'bg-lime-200');
|
|
|
|
$table->setColumns([
|
|
['key' => 'id', 'title' => 'ID', 'width' => 80],
|
|
['key' => 'name', 'title' => 'Name'],
|
|
['key' => 'email', 'title' => 'E-Mail'],
|
|
['key' => 'status', 'title' => 'Status', 'width' => 120],
|
|
]);
|
|
|
|
$table->setData([
|
|
['id' => 1, 'name' => 'Max Mustermann', 'email' => 'max@example.com', 'status' => 'Aktiv'],
|
|
['id' => 2, 'name' => 'Anna Schmidt', 'email' => 'anna@example.com', 'status' => 'Aktiv'],
|
|
['id' => 3, 'name' => 'Peter Weber', 'email' => 'peter@example.com', 'status' => 'Inaktiv'],
|
|
['id' => 4, 'name' => 'Lisa Müller', 'email' => 'lisa@example.com', 'status' => 'Aktiv'],
|
|
['id' => 5, 'name' => 'Tom Klein', 'email' => 'tom@example.com', 'status' => 'Aktiv'],
|
|
['id' => 6, 'name' => 'Sarah Wagner', 'email' => 'sarah@example.com', 'status' => 'Inaktiv'],
|
|
['id' => 7, 'name' => 'Michael Becker', 'email' => 'michael@example.com', 'status' => 'Aktiv'],
|
|
['id' => 8, 'name' => 'Julia Fischer', 'email' => 'julia@example.com', 'status' => 'Aktiv'],
|
|
['id' => 9, 'name' => 'Daniel Schneider', 'email' => 'daniel@example.com', 'status' => 'Inaktiv'],
|
|
['id' => 10, 'name' => 'Laura Hoffmann', 'email' => 'laura@example.com', 'status' => 'Aktiv'],
|
|
]);
|
|
|
|
// Row selection handler
|
|
$statusLabel = new Label(
|
|
text: 'Fenster: ' . $window->getViewport()->windowWidth . 'x' . $window->getViewport()->windowHeight,
|
|
style: 'basis-4/8 text-black',
|
|
);
|
|
$table->setOnRowSelect(function ($index, $row) use (&$statusLabel) {
|
|
if ($row) {
|
|
$statusLabel->setText("Selected: {$row['name']} ({$row['email']})");
|
|
}
|
|
});
|
|
|
|
$tab1->addComponent($table);
|
|
$tabContainer->addTab('Daten', $tab1);
|
|
|
|
// Tab 2: Some info
|
|
$tab2 = new Container('flex flex-col p-4');
|
|
$tab2->addComponent(new Label('Dies ist Tab 2', 'text-xl font-bold mb-4'));
|
|
$tab2->addComponent(new Label('Hier könnte weiterer Inhalt stehen...', ''));
|
|
$tabContainer->addTab('Info', $tab2);
|
|
|
|
// Tab 3: Settings
|
|
$tab3 = new Container('flex flex-col p-4');
|
|
$tab3->addComponent(new Label('Einstellungen', 'text-xl font-bold mb-4'));
|
|
$tab3->addComponent(new Label('Konfigurationsoptionen...', ''));
|
|
$tabContainer->addTab('Einstellungen', $tab3);
|
|
|
|
$mainContainer->addComponent($tabContainer);
|
|
|
|
// === 3. StatusBar ===
|
|
$statusBar = new StatusBar();
|
|
$statusBar->addSegment($statusLabel);
|
|
$statusBar->addSegment(new Label(
|
|
text: 'Zeilen: 10',
|
|
style: 'basis-2/8 text-black border-l',
|
|
)); // Fixed width
|
|
$statusBar->addSegment(new Label(
|
|
text: 'Version 1.0',
|
|
style: 'border-l text-black basis-2/8',
|
|
));
|
|
$mainContainer->addComponent($statusBar);
|
|
$window->setOnResize(function (Window $window) use (&$statusLabel) {
|
|
$statusLabel->setText(
|
|
'Fenster: ' . $window->getViewport()->windowWidth . 'x' . $window->getViewport()->windowHeight,
|
|
);
|
|
});
|
|
// Set root and run
|
|
$window->setRoot($mainContainer);
|
|
$app->addWindow($window);
|
|
|
|
echo "Windows Application Example started!\n";
|
|
echo "Features:\n";
|
|
echo "- MenuBar with 'Datei' and 'Einstellungen'\n";
|
|
echo "- Tab Container with 3 tabs\n";
|
|
echo "- Scrollable Table in first tab\n";
|
|
echo "- StatusBar at the bottom\n\n";
|
|
|
|
$app->run();
|