use single label container for wrap ruler iteration

This commit is contained in:
yggverse 2024-07-31 22:13:01 +03:00
parent 0b32d97622
commit d5171d1900

View file

@ -138,30 +138,6 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
throw new Exception; throw new Exception;
} }
protected static function _width(
string $markup
): ?int
{
$label = new GtkLabel;
$label->set_use_markup(
true
);
$label->set_markup(
$markup
);
if ($size = $label->get_layout()->get_pixel_size())
{
$label->destroy();
return $size['width'];
}
return null;
}
protected static function _wrap( protected static function _wrap(
string $string, string $string,
int $width, int $width,
@ -170,15 +146,23 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
array $lines = [] array $lines = []
): string ): string
{ {
$label = new GtkLabel;
$label->set_use_markup(
true
);
foreach (explode(' ', $string) as $word) foreach (explode(' ', $string) as $word)
{ {
if (isset($words[$line])) if (isset($words[$line]))
{ {
$markup = implode( $label->set_markup(
' ' , $words[$line] implode(
) . ' ' . $word; ' ' , $words[$line]
) . ' ' . $word
);
if (self::_width($markup) > $width) if ($label->get_layout()->get_pixel_size()['width'] > $width)
{ {
$line++; $line++;
} }
@ -195,6 +179,8 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
); );
} }
$label->destroy();
return implode( return implode(
PHP_EOL, PHP_EOL,
$lines $lines