Browse Source

init tabs feature

main
yggverse 2 months ago
parent
commit
2fe9de0163
  1. 2
      README.md
  2. 82
      src/Entity/App.php

2
README.md

@ -7,7 +7,7 @@ At this moment project under development! @@ -7,7 +7,7 @@ At this moment project under development!
* [x] Custom DNS resolver with memory cache, oriented to alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go)
* [x] Flexible settings in `config.json`, then UI
* [x] Native GTK environment, no custom colors until you change it in `css`
* [ ] Page tabs
* [x] Page tabs
* [ ] Local pages history snaps to make it accessible even offline
* [ ] Bookmarks
* [ ] Certificate features

82
src/Entity/App.php

@ -14,9 +14,11 @@ class App @@ -14,9 +14,11 @@ class App
public function __construct()
{
// Init config
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO
$this->window = new \GtkWindow();
// Init window
$this->window = new \GtkWindow;
$this->window->set_size_request(
$this->config->width,
@ -25,7 +27,7 @@ class App @@ -25,7 +27,7 @@ class App
if ($this->config->header->enabled)
{
$this->header = new \GtkHeaderBar();
$this->header = new \GtkHeaderBar;
$this->header->set_title(
$this->config->header->title->default
@ -40,34 +42,72 @@ class App @@ -40,34 +42,72 @@ class App
);
}
$this->window->connect(
'destroy',
function()
{
\Gtk::main_quit();
}
// Init tabs
$this->tabs = new \GtkNotebook;
$this->tabs->set_scrollable(
true
);
$this->tabs = new \GtkNotebook();
// + button
$blank = new \GtkLabel;
$this->tabs->set_scrollable(
$this->tabs->append_page(
$blank,
new \GtkLabel(
'+'
)
);
$this->tabs->set_tab_reorderable(
$blank,
true
);
// Append blank page
$page = $this->blankPage();
$page->open(
$this->config->tab->page->header->button->home->url // @TODO
);
// Render
$this->window->add(
$this->tabs
);
$this->openPage(
$this->config->tab->page->header->button->home->url // @TODO
$this->window->show_all();
// Init event listener
$this->tabs->connect(
'switch-page',
function ($tabs, $child, $position)
{
if ('+' == $tabs->get_tab_label_text($child))
{
$page = $this->blankPage();
$this->tabs->show_all();
$this->tabs->set_current_page(
$this->tabs->page_num(
$page->box
)
);
}
}
);
$this->window->show_all();
$this->window->connect(
'destroy',
function()
{
\Gtk::main_quit();
}
);
}
public function openPage(
string $url
): void
public function blankPage(): \Yggverse\Yoda\Entity\Tab\Page
{
$page = new \Yggverse\Yoda\Entity\Tab\Page(
$this
@ -85,9 +125,15 @@ class App @@ -85,9 +125,15 @@ class App
true
);
$page->open(
$url
$this->tabs->show_all();
$this->tabs->set_current_page(
$this->tabs->page_num(
$page->box
)
);
return $page;
}
public function setTitle(

Loading…
Cancel
Save