162 lines
4.4 KiB
PHP
162 lines
4.4 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use PHPNative\Framework\Application;
|
|
use PHPNative\Ui\Widget\Button;
|
|
use PHPNative\Ui\Widget\Container;
|
|
use PHPNative\Ui\Widget\Label;
|
|
|
|
// Create application
|
|
$app = new Application();
|
|
|
|
// Create main window
|
|
$mainWindow = $app->createWindow('Main Window - Multi-Window Demo', 600, 400, 100, 100);
|
|
|
|
// Counter for new windows
|
|
$windowCounter = 1;
|
|
|
|
// Create main window UI
|
|
$mainContainer = new Container('flex flex-col p-6 gap-4 bg-gray-100');
|
|
|
|
$title = new Label(
|
|
text: 'Multi-Window Demo',
|
|
style: 'text-2xl text-gray-900'
|
|
);
|
|
|
|
$description = new Label(
|
|
text: 'Klicken Sie auf die Buttons, um neue Windows zu erstellen!',
|
|
style: 'text-base text-gray-700'
|
|
);
|
|
|
|
$windowCountLabel = new Label(
|
|
text: 'Offene Windows: 1',
|
|
style: 'text-sm text-blue-600 p-2 bg-white rounded'
|
|
);
|
|
|
|
// Button to create a simple new window
|
|
$createSimpleButton = new Button(
|
|
text: 'Neues Fenster erstellen',
|
|
style: 'bg-blue-500 hover:bg-blue-700 text-white p-4 rounded-lg'
|
|
);
|
|
|
|
$createSimpleButton->setOnClick(function() use ($app, &$windowCounter, $windowCountLabel) {
|
|
// Create new window with offset position
|
|
$offset = $windowCounter * 30;
|
|
$newWindow = $app->createWindow(
|
|
"Window #$windowCounter",
|
|
500,
|
|
300,
|
|
150 + $offset,
|
|
150 + $offset
|
|
);
|
|
|
|
// Create UI for new window
|
|
$container = new Container('flex flex-col p-6 gap-3 bg-gradient-to-br from-purple-400 to-pink-400');
|
|
|
|
$label = new Label(
|
|
text: "Dies ist Window #$windowCounter",
|
|
style: 'text-xl text-white'
|
|
);
|
|
|
|
$closeButton = new Button(
|
|
text: 'Fenster schließen',
|
|
style: 'bg-red-500 hover:bg-red-700 text-white p-3 rounded'
|
|
);
|
|
|
|
$closeButton->setOnClick(function() use ($newWindow) {
|
|
$newWindow->close();
|
|
});
|
|
|
|
$container->addComponent($label);
|
|
$container->addComponent($closeButton);
|
|
$newWindow->setRoot($container);
|
|
|
|
$windowCounter++;
|
|
|
|
// Update counter
|
|
$windowCountLabel->setText('Offene Windows: ' . $app->getWindowCount());
|
|
});
|
|
|
|
// Button to create a window with interactive content
|
|
$createInteractiveButton = new Button(
|
|
text: 'Interaktives Fenster erstellen',
|
|
style: 'bg-green-500 hover:bg-green-700 text-white p-4 rounded-lg'
|
|
);
|
|
|
|
$createInteractiveButton->setOnClick(function() use ($app, &$windowCounter, $windowCountLabel) {
|
|
$offset = $windowCounter * 30;
|
|
$newWindow = $app->createWindow(
|
|
"Interactive Window #$windowCounter",
|
|
600,
|
|
400,
|
|
150 + $offset,
|
|
150 + $offset
|
|
);
|
|
|
|
// Create interactive UI
|
|
$container = new Container('flex flex-col p-6 gap-3 bg-blue-50');
|
|
|
|
$title = new Label(
|
|
text: "Interaktives Window #$windowCounter",
|
|
style: 'text-xl text-gray-900'
|
|
);
|
|
|
|
$counter = 0;
|
|
$counterLabel = new Label(
|
|
text: "Zähler: $counter",
|
|
style: 'text-lg text-blue-600 p-2 bg-white rounded'
|
|
);
|
|
|
|
$incrementButton = new Button(
|
|
text: 'Zähler erhöhen',
|
|
style: 'bg-blue-500 hover:bg-blue-700 text-white p-3 rounded'
|
|
);
|
|
|
|
$incrementButton->setOnClick(function() use (&$counter, $counterLabel) {
|
|
$counter++;
|
|
$counterLabel->setText("Zähler: $counter");
|
|
});
|
|
|
|
$closeButton = new Button(
|
|
text: 'Fenster schließen',
|
|
style: 'bg-red-500 hover:bg-red-700 text-white p-3 rounded'
|
|
);
|
|
|
|
$closeButton->setOnClick(function() use ($newWindow) {
|
|
$newWindow->close();
|
|
});
|
|
|
|
$container->addComponent($title);
|
|
$container->addComponent($counterLabel);
|
|
$container->addComponent($incrementButton);
|
|
$container->addComponent($closeButton);
|
|
$newWindow->setRoot($container);
|
|
|
|
$windowCounter++;
|
|
$windowCountLabel->setText('Offene Windows: ' . $app->getWindowCount());
|
|
});
|
|
|
|
// Button to quit application
|
|
$quitButton = new Button(
|
|
text: 'Alle Fenster schließen und beenden',
|
|
style: 'bg-red-600 hover:bg-red-800 text-white p-4 rounded-lg mt-4'
|
|
);
|
|
|
|
$quitButton->setOnClick(function() use ($app) {
|
|
$app->quit();
|
|
});
|
|
|
|
// Add all components to main container
|
|
$mainContainer->addComponent($title);
|
|
$mainContainer->addComponent($description);
|
|
$mainContainer->addComponent($windowCountLabel);
|
|
$mainContainer->addComponent($createSimpleButton);
|
|
$mainContainer->addComponent($createInteractiveButton);
|
|
$mainContainer->addComponent($quitButton);
|
|
|
|
$mainWindow->setRoot($mainContainer);
|
|
|
|
// Run application
|
|
$app->run();
|