move statusbar feature to gtk header subtitle

This commit is contained in:
yggverse 2024-07-07 08:05:04 +03:00
parent a516aa958f
commit cf3fde37fa
7 changed files with 104 additions and 143 deletions

View file

@ -41,10 +41,13 @@ class Tab
\GtkWidget $child,
int $position
) {
$label = $entity->get_tab_label(
$child
);
$this->container->browser->header->setTitle(
$entity->get_tab_label(
$child
)->get_text()
$label->get_text(),
$label->get_subtitle() // @TODO extension not supported by GTK-PHP
);
// Keep current selection
@ -92,7 +95,8 @@ class Tab
// Update application title
$this->container->browser->header->setTitle(
$page->title->gtk->get_text()
$page->title->getValue(),
$page->title->getSubtitle()
);
}

View file

@ -7,7 +7,6 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar;
class Page
{
@ -20,7 +19,6 @@ class Page
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title $title;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar $statusbar;
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab $tab
@ -52,20 +50,8 @@ class Page
$this
);
$this->gtk->pack_start(
$this->content->gtk,
true,
true,
0
);
// Init statusbar
$this->statusbar = new Statusbar(
$this
);
$this->gtk->add(
$this->statusbar->gtk
$this->content->gtk
);
// Render
@ -76,7 +62,6 @@ class Page
{
$this->navbar->refresh();
$this->content->refresh();
$this->statusbar->refresh();
}
public function update(

View file

@ -37,6 +37,18 @@ class Content
$this->_margin
);
$this->gtk->set_margin_bottom(
$this->_margin
);
$this->gtk->set_propagate_natural_height( // instead of pack to parent
true
);
$this->gtk->set_propagate_natural_width(
true
);
// Init viewport
// to integrate scrolled window features for data label
$this->viewport = new Viewport(
@ -73,7 +85,8 @@ class Content
// Init new title
$this->page->title->setValue(
$address->getHost()
$address->getHost(),
'loading...'
);
if ($history)
@ -90,11 +103,6 @@ class Content
);
}
// Update statusbar indicator
$this->page->statusbar->setValue(
'Loading...'
);
// Detect protocol
switch ($address->getScheme())
{
@ -124,45 +132,36 @@ class Content
if ($title) // detect title by document h1
{
$this->page->title->setValue(
$title
$title,
$this->page->title->subtitle
);
}
$this->page->statusbar->setValue(
null
);
break;
default:
$this->page->title->setValue(
'Oops!'
'Oops!',
'file extension not supported'
);
$this->data->setPlain(
'File extension not supported'
);
$this->page->statusbar->setValue(
null
);
}
}
else
{
$this->page->title->setValue(
'Failure'
'Failure',
'resource not found or not readable'
);
$this->data->setPlain(
'Could not open file'
);
$this->page->statusbar->setValue(
'Resource not found or not readable'
);
}
break;
@ -212,7 +211,7 @@ class Content
);
}
$this->page->statusbar->setValue(
$this->page->title->setSubtitle(
$response->getMeta()
);
}
@ -220,21 +219,18 @@ class Content
else
{
$this->page->title->setValue(
'Failure'
);
$this->data->setPlain(
'Resource not available!'
);
$this->page->statusbar->setValue(
'Failure',
sprintf(
'code %d',
'could not open resource (code %d)',
intval(
$response->getCode()
)
)
);
$this->data->setPlain(
'Requested resource not available!'
);
}
break;
@ -283,16 +279,13 @@ class Content
default:
$this->page->title->setValue(
'Oops!'
'Oops!',
'protocol not supported!'
);
$this->data->setPlain(
'Protocol not supported!'
);
$this->page->statusbar->setValue(
null
);
}
// Render content
@ -300,5 +293,11 @@ class Content
// Refresh page components
$this->page->refresh();
// Update window header
$this->page->tab->container->browser->header->setTitle(
$this->page->title->getValue(),
$this->page->title->getSubtitle(),
);
}
}

View file

@ -1,83 +0,0 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
class Statusbar
{
public \GtkLabel $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
// Defaults
private int $_margin = 8;
private string $_value = '';
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page
) {
// Init dependency
$this->page = $page;
// Init container
$this->gtk = new \GtkLabel;
$this->gtk->set_use_markup(
true
);
$this->gtk->set_selectable(
true
);
$this->gtk->set_line_wrap(
true
);
$this->gtk->set_xalign(
0
);
$this->gtk->set_yalign(
0
);
$this->gtk->set_margin_top(
$this->_margin
);
$this->gtk->set_margin_bottom(
$this->_margin
);
$this->gtk->set_margin_start(
$this->_margin
);
$this->gtk->set_margin_end(
$this->_margin
);
$this->gtk->set_markup(
$this->_value
);
}
public function setValue(
?string $value = null
): void
{
$this->gtk->set_markup(
is_null($value) ? $this->_value : trim(
$value
)
);
}
public function refresh()
{
// @TODO
}
}

View file

@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
use \Yggverse\Yoda\Gtk\Browser\Container\Tab\Page\Title\Label;
class Title
{
public \GtkLabel $gtk;
public Label $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
@ -15,6 +17,7 @@ class Title
private int $_ellipsize = 3;
private int $_length = 12;
private string $_value = 'New page';
private string $_subtitle = '';
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page,
@ -23,7 +26,7 @@ class Title
$this->page = $page;
// Init container
$this->gtk = new \GtkLabel(
$this->gtk = new Label(
$this->_value
);
@ -37,7 +40,8 @@ class Title
}
public function setValue(
?string $value = null
?string $value = null,
?string $subtitle = null
): void
{
$this->gtk->set_text(
@ -45,5 +49,30 @@ class Title
$value
)
);
$this->setSubtitle(
$subtitle
);
}
public function setSubtitle(
?string $subtitle = null
): void
{
$this->gtk->set_subtitle(
is_null($subtitle) ? $this->_subtitle : trim(
$subtitle
)
);
}
public function getValue(): string
{
return $this->gtk->get_text();
}
public function getSubtitle(): string
{
return $this->gtk->get_subtitle();
}
}