Browse Source

await for min renderer dimensions init

PHP-GTK3
yggverse 4 months ago
parent
commit
62c2681cf9
  1. 30
      src/Entity/Browser/Container/Page/Content.php
  2. 39
      src/Entity/Browser/Container/Page/Content/Gemtext.php

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

@ -53,7 +53,7 @@ class Content
); );
} }
public function set( // @TODO make async public function set(
?string $mime, ?string $mime,
?string $data ?string $data
): void ): void
@ -64,39 +64,13 @@ class Content
{ {
case Filesystem::MIME_TEXT_GEMINI: case Filesystem::MIME_TEXT_GEMINI:
$title = null;
$document = new Content\Gemtext( $document = new Content\Gemtext(
$this $this
); );
$document->set( $document->set(
$data, $data
$title
);
// Update title by gemtext H1 tag (on available)
if ($title)
{
// Set new title
$this->page->title->setValue(
$title
);
// Update tooltip
$this->page->title->setTooltip(
$title
);
// Refresh header by new title if current page is active
if ($this->page === $this->page->container->tab->get())
{
$this->page->container->browser->header->setTitle(
$this->page->title->getValue(),
$this->page->title->getSubtitle()
); );
}
}
break; break;

39
src/Entity/Browser/Container/Page/Content/Gemtext.php

@ -7,6 +7,7 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Page\Content;
use \Exception; use \Exception;
use \Gdk; use \Gdk;
use \GdkEvent; use \GdkEvent;
use \Gtk;
use \GtkLabel; use \GtkLabel;
use \Pango; use \Pango;
@ -17,18 +18,50 @@ use \Yggverse\Yoda\Model\Gtk\Pango\Markup\Gemtext as Markup;
class Gemtext extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup class Gemtext extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup
{ {
public function set( public function set(
string $source, string $value
string | null &$title = null
): void ): void
{
Gtk::timeout_add( // await for renderer dimensions init
1, function(?string $title = null) use ($value)
{
if ($this->content->page->content->gtk->get_allocated_width() > Markup::WRAP_WIDTH)
{ {
$this->gtk->set_markup( $this->gtk->set_markup(
Markup::format( Markup::format(
$this->_source = $source, $this->_source = $value,
$this->content->page->navbar->request->getValue(), $this->content->page->navbar->request->getValue(),
$this->content->page->content->gtk->get_allocated_width(), $this->content->page->content->gtk->get_allocated_width(),
$title $title
) )
); );
// Update title by gemtext H1 tag (on available)
if ($title)
{
// Set new title
$this->content->page->title->setValue(
$title
);
// Update tooltip
$this->content->page->title->setTooltip(
$title
);
// Refresh header by new title if current page is active
if ($this->content->page === $this->content->page->container->tab->get())
{
$this->content->page->container->browser->header->setTitle(
$this->content->page->title->getValue(),
$this->content->page->title->getSubtitle()
);
}
};
return false; // stop
}
}
);
} }
protected function _onActivateLink( protected function _onActivateLink(

Loading…
Cancel
Save