120 lines
4.0 KiB
PHP
120 lines
4.0 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\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 = $menuBar->addMenu('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 = $menuBar->addMenu('Einstellungen');
|
|
$settingsMenu->addItem('Optionen', function () {
|
|
echo "Optionen clicked\n";
|
|
});
|
|
$settingsMenu->addItem('Sprache', function () {
|
|
echo "Sprache clicked\n";
|
|
});
|
|
|
|
$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();
|
|
|
|
$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
|
|
$statusBar = null; // Will be set later
|
|
$table->setOnRowSelect(function ($index, $row) use (&$statusBar) {
|
|
if ($statusBar && $row) {
|
|
$statusBar->updateSegment(0, "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('Bereit', '', 0); // Flexible segment
|
|
$statusBar->addSegment('Zeilen: 10', 'border-l', 200); // Fixed width
|
|
$statusBar->addSegment('Version 1.0', 'border-l', 150); // Fixed width
|
|
|
|
$mainContainer->addComponent($statusBar);
|
|
|
|
// 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();
|