From 75806cd295f12cfe5965755902036bafd5b6e967 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 10 Apr 2024 08:58:16 +0300 Subject: [PATCH] init abstract window controller --- src/Abstract/Window.php | 70 +++++++++++++++++++++++++ src/Controller/{Tab.php => Browser.php} | 23 ++++---- src/Yoda.php | 64 +--------------------- 3 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 src/Abstract/Window.php rename src/Controller/{Tab.php => Browser.php} (93%) diff --git a/src/Abstract/Window.php b/src/Abstract/Window.php new file mode 100644 index 00000000..e6dff812 --- /dev/null +++ b/src/Abstract/Window.php @@ -0,0 +1,70 @@ +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 + ); + } +} \ No newline at end of file diff --git a/src/Controller/Tab.php b/src/Controller/Browser.php similarity index 93% rename from src/Controller/Tab.php rename to src/Controller/Browser.php index 9c24da7b..ab1fb6eb 100644 --- a/src/Controller/Tab.php +++ b/src/Controller/Browser.php @@ -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) diff --git a/src/Yoda.php b/src/Yoda.php index 0510553c..12d1c134 100644 --- a/src/Yoda.php +++ b/src/Yoda.php @@ -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(); \ No newline at end of file