replace unsupported gtk class extension by local dependency array

This commit is contained in:
yggverse 2024-07-12 15:22:21 +03:00
parent 518e575c83
commit dfd37dcef4
3 changed files with 32 additions and 40 deletions

View file

@ -4,11 +4,12 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Page;
use \Yggverse\Yoda\Gtk\Browser\Container\Page\Title\Label;
class Title
{
public Label $gtk;
public \GtkLabel $gtk;
// Extras
public ?string $subtitle = null;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Page $page;
@ -27,7 +28,7 @@ class Title
$this->page = $page;
// Init container
$this->gtk = new Label(
$this->gtk = new \GtkLabel(
$this->_value
);
@ -75,11 +76,9 @@ class Title
?string $subtitle = null
): void
{
$this->gtk->set_subtitle(
is_null($subtitle) ? $this->_subtitle : strtolower(
trim(
$subtitle
)
$this->subtitle = is_null($subtitle) ? $this->_subtitle : strtolower(
trim(
$subtitle
)
);
}
@ -102,7 +101,7 @@ class Title
public function getSubtitle(): ?string
{
return $this->gtk->get_subtitle();
return $this->subtitle;
}
public function getTooltip(): ?string

View file

@ -17,6 +17,9 @@ class Tab
private bool $_reorderable = true;
private bool $_scrollable = true;
// Extras
private array $_page = [];
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container $container
) {
@ -49,16 +52,12 @@ class Tab
function (
\GtkNotebook $entity,
\GtkWidget $child,
int $position
int $index
) {
$label = $entity->get_tab_label(
$child
);
// Update header bar title
$this->container->browser->header->setTitle(
$label->get_text(),
null /* @TODO extension not supported by PHP-GTK3 #117
$label->get_subtitle()*/
$this->getPage($index)->title->getValue(),
$this->getPage($index)->title->getSubtitle()
);
// Keep current selection
@ -111,5 +110,21 @@ class Tab
// Render
$this->gtk->show();
// Extendable classes not supported by PHP-GTK3 #117
// create internal pages registry
$this->_page[] = $page;
}
public function getPage(
int $index
): ?\Yggverse\Yoda\Entity\Browser\Container\Page
{
if (empty($this->_page[$index]))
{
throw new \Exception;
}
return $this->_page[$index];
}
}

View file

@ -1,22 +0,0 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Gtk\Browser\Container\Page\Title;
class Label extends \GtkLabel
{
private ?string $_subtitle = null;
public function set_subtitle(
?string $value = null
): void
{
$this->_subtitle = $value;
}
public function get_subtitle(): ?string
{
return $this->_subtitle;
}
}