use label widget as contain destroy method to free memory on width rule iteration

This commit is contained in:
yggverse 2024-07-30 14:39:51 +03:00
parent 1ef9c91b64
commit 5b3f0c2497

View file

@ -4,8 +4,7 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Abstract\Model\Gtk\Pango; namespace Yggverse\Yoda\Abstract\Model\Gtk\Pango;
use \PangoLayout; use \GtkLabel;
use \GtkDrawingArea;
class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
{ {
@ -143,16 +142,20 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
string $markup string $markup
): ?int ): ?int
{ {
$layout = new PangoLayout( // @TODO cleanup $label = new GtkLabel;
(new GtkDrawingArea)->create_pango_context()
$label->set_use_markup(
true
); );
$layout->set_markup( $label->set_markup(
$markup, -1 $markup, -1
); );
if ($size = $layout->get_pixel_size()) if ($size = $label->get_layout()->get_pixel_size())
{ {
$label->destroy();
return $size['width']; return $size['width'];
} }