init abstract window controller

This commit is contained in:
yggverse 2024-04-10 08:58:16 +03:00
parent 78a2fa16c9
commit 75806cd295
3 changed files with 83 additions and 74 deletions

70
src/Abstract/Window.php Normal file
View file

@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Abstract;
abstract class Window
{
public \GtkWindow $window;
public \GtkCssProvider $css;
public \GtkStyleContext $style;
public object $config;
public function __construct(
object $config
) {
$this->config = $config;
$this->window = new \GtkWindow();
$this->window->set_size_request(
$this->config->interface->window->width,
$this->config->interface->window->height
);
if ($this->config->interface->window->header->enabled)
{
$header = new \GtkHeaderBar();
$header->set_show_close_button(
$this->config->interface->window->header->button->close
);
$this->window->set_titlebar(
$header
);
}
$this->window->set_title(
'Yoda'
);
$this->window->connect(
'destroy',
function()
{
\Gtk::main_quit();
}
);
}
public function setTheme(
string $css
): void
{
$this->css = new \GtkCssProvider();
$this->css->load_from_data(
$css
);
$this->style = new \GtkStyleContext();
$this->style->add_provider_for_screen(
$this->css,
600
);
}
}

View file

@ -4,22 +4,17 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Controller;
class Tab
class Browser extends \Yggverse\Yoda\Abstract\Window
{
public \GtkWindow $window;
public \Yggverse\Yoda\Entity\Box\Tab $tab;
public \Yggverse\Yoda\Model\Memory $memory;
public object $config;
public function __construct(
\GtkWindow $window
) {
$this->window = $window;
$this->config = \Yggverse\Yoda\Model\File::getConfig();
public function __construct()
{
parent::__construct(
\Yggverse\Yoda\Model\File::getConfig()
);
$this->memory = new \Yggverse\Yoda\Model\Memory();
@ -72,7 +67,11 @@ class Tab
);
}
// @TODO back, forward buttons
$this->window->add(
$this->tab->box
);
$this->window->show_all();
}
public function navigate(string $url)

View file

@ -6,69 +6,9 @@ require_once __DIR__ .
DIRECTORY_SEPARATOR . 'vendor' .
DIRECTORY_SEPARATOR . 'autoload.php';
// Init config
$config = \Yggverse\Yoda\Model\File::getConfig();
// Init GTK
// Init app
\Gtk::init();
// Init theme
$css = new \GtkCssProvider();
$css->load_from_data(
\Yggverse\Yoda\Model\File::getTheme(
$config->interface->theme
)
);
$style = new \GtkStyleContext();
$style->add_provider_for_screen(
$css,
600
);
// Init app window
$window = new \GtkWindow();
$window->set_size_request(
$config->interface->window->width,
$config->interface->window->height
);
if ($config->interface->window->header->enabled)
{
$header = new \GtkHeaderBar();
$header->set_show_close_button(
$config->interface->window->header->button->close
);
$window->set_titlebar(
$header
);
}
$window->set_title(
'Yoda'
);
$window->connect(
'destroy',
function()
{
\Gtk::main_quit();
}
);
$controller = new \Yggverse\Yoda\Controller\Tab(
$window
);
$window->add(
$controller->tab->box
);
$window->show_all();
new \Yggverse\Yoda\Controller\Browser();
\Gtk::main();