diff --git a/src/Entity/Browser/Container/Page.php b/src/Entity/Browser/Container/Page.php index 5905e5f2..886e2eac 100644 --- a/src/Entity/Browser/Container/Page.php +++ b/src/Entity/Browser/Container/Page.php @@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Entity\Browser\Container; use \Yggverse\Yoda\Entity\Browser\Container\Page\Title; use \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar; +use \Yggverse\Yoda\Entity\Browser\Container\Page\Progressbar; use \Yggverse\Yoda\Entity\Browser\Container\Page\Content; use \Yggverse\Yoda\Entity\Browser\Container\Page\Response; @@ -19,6 +20,7 @@ class Page // Requirements public \Yggverse\Yoda\Entity\Browser\Container\Page\Title $title; public \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar $navbar; + public \Yggverse\Yoda\Entity\Browser\Container\Page\Progressbar $progressbar; public \Yggverse\Yoda\Entity\Browser\Container\Page\Content $content; public \Yggverse\Yoda\Entity\Browser\Container\Page\Response $response; @@ -59,6 +61,15 @@ class Page 0 ); + // Init progress bar + $this->progressbar = new Progressbar( + $this + ); + + $this->gtk->add( + $this->progressbar->gtk + ); + // Init response bar $this->response = new Response( $this diff --git a/src/Entity/Browser/Container/Page/Content.php b/src/Entity/Browser/Container/Page/Content.php index 4adf9a3b..41815752 100644 --- a/src/Entity/Browser/Container/Page/Content.php +++ b/src/Entity/Browser/Container/Page/Content.php @@ -73,6 +73,9 @@ class Content bool $history = true ): void { + // Show progressbar + $this->page->progressbar->infinitive(); + // Parse address $address = new \Yggverse\Net\Address( $this->page->navbar->request->getValue() @@ -412,5 +415,8 @@ class Content $this->page->title->getValue(), $this->page->title->getSubtitle(), ); + + // Hide progressbar + $this->page->progressbar->hide(); } } \ No newline at end of file diff --git a/src/Entity/Browser/Container/Page/Progressbar.php b/src/Entity/Browser/Container/Page/Progressbar.php new file mode 100644 index 00000000..8e8b73dc --- /dev/null +++ b/src/Entity/Browser/Container/Page/Progressbar.php @@ -0,0 +1,123 @@ +page = $page; + + // Init container + $this->gtk = new \GtkProgressBar; + } + + public function start(): void + { + $this->_active = true; + } + + public function stop(): void + { + $this->_active = false; + } + + public function show(): void + { + $this->gtk->show(); // | set_opacity(1) + } + + public function hide(): void + { + $this->stop(); // make sure iterator get stopped + + $this->gtk->hide(); // | set_opacity(0) + } + + public function infinitive( + int $timeout = 100, + bool $show = true + ): void + { + // Init visible + if ($show) + { + $this->gtk->show(); + } + + // Activate iterator + $this->_active = true; + + // Begin iterator + \Gtk::timeout_add( + $timeout, + function() + { + if ($this->_active) + { + $this->gtk->pulse(); + } + + else return false; // stop + } + ); + } + + public function progressive( + float $fraction = 0, + int $timeout = 100, + bool $show = true + ): void + { + // Init visible + if ($show) + { + $this->gtk->show(); + } + + // Activate iterator + $this->_active = true; + + // Set initial progress + $this->gtk->set_fraction( + $fraction + ); + + // Begin iterator + \Gtk::timeout_add( + $timeout, + function() + { + if ($this->_active) + { + // Update fraction step + $this->gtk->set_fraction( + $fraction = $this->gtk->get_fraction() + $this->_step + ); + + // Deactivate loop on progress complete + if ($fraction >= 1) + { + $this->_active = false; + } + } + + else return false; // stop + } + ); + } +} \ No newline at end of file