Browse Source

implement progressbar

PHP-GTK3
yggverse 5 months ago
parent
commit
195860c342
  1. 11
      src/Entity/Browser/Container/Page.php
  2. 6
      src/Entity/Browser/Container/Page/Content.php
  3. 123
      src/Entity/Browser/Container/Page/Progressbar.php

11
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\Title;
use \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar; 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\Content;
use \Yggverse\Yoda\Entity\Browser\Container\Page\Response; use \Yggverse\Yoda\Entity\Browser\Container\Page\Response;
@ -19,6 +20,7 @@ class Page
// Requirements // Requirements
public \Yggverse\Yoda\Entity\Browser\Container\Page\Title $title; 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\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\Content $content;
public \Yggverse\Yoda\Entity\Browser\Container\Page\Response $response; public \Yggverse\Yoda\Entity\Browser\Container\Page\Response $response;
@ -59,6 +61,15 @@ class Page
0 0
); );
// Init progress bar
$this->progressbar = new Progressbar(
$this
);
$this->gtk->add(
$this->progressbar->gtk
);
// Init response bar // Init response bar
$this->response = new Response( $this->response = new Response(
$this $this

6
src/Entity/Browser/Container/Page/Content.php

@ -73,6 +73,9 @@ class Content
bool $history = true bool $history = true
): void ): void
{ {
// Show progressbar
$this->page->progressbar->infinitive();
// Parse address // Parse address
$address = new \Yggverse\Net\Address( $address = new \Yggverse\Net\Address(
$this->page->navbar->request->getValue() $this->page->navbar->request->getValue()
@ -412,5 +415,8 @@ class Content
$this->page->title->getValue(), $this->page->title->getValue(),
$this->page->title->getSubtitle(), $this->page->title->getSubtitle(),
); );
// Hide progressbar
$this->page->progressbar->hide();
} }
} }

123
src/Entity/Browser/Container/Page/Progressbar.php

@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Page;
class Progressbar
{
public \GtkProgressBar $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Page $page;
// Defaults
private bool $_active = false;
private float $_step = 0.02;
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Page $page,
) {
// Init dependencies
$this->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
}
);
}
}
Loading…
Cancel
Save