Browse Source

replace unsupported gtk class extension by local dependency array

PHP-GTK3
yggverse 4 months ago
parent
commit
dfd37dcef4
  1. 15
      src/Entity/Browser/Container/Page/Title.php
  2. 31
      src/Entity/Browser/Container/Tab.php
  3. 22
      src/Gtk/Browser/Container/Page/Title/Label.php

15
src/Entity/Browser/Container/Page/Title.php

@ -4,11 +4,12 @@ declare(strict_types=1); @@ -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 @@ -27,7 +28,7 @@ class Title
$this->page = $page;
// Init container
$this->gtk = new Label(
$this->gtk = new \GtkLabel(
$this->_value
);
@ -75,12 +76,10 @@ class Title @@ -75,12 +76,10 @@ class Title
?string $subtitle = null
): void
{
$this->gtk->set_subtitle(
is_null($subtitle) ? $this->_subtitle : strtolower(
$this->subtitle = is_null($subtitle) ? $this->_subtitle : strtolower(
trim(
$subtitle
)
)
);
}
@ -102,7 +101,7 @@ class Title @@ -102,7 +101,7 @@ class Title
public function getSubtitle(): ?string
{
return $this->gtk->get_subtitle();
return $this->subtitle;
}
public function getTooltip(): ?string

31
src/Entity/Browser/Container/Tab.php

@ -17,6 +17,9 @@ class Tab @@ -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 @@ -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 @@ -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];
}
}

22
src/Gtk/Browser/Container/Page/Title/Label.php

@ -1,22 +0,0 @@ @@ -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;
}
}
Loading…
Cancel
Save