mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
use single label container for wrap ruler iteration
This commit is contained in:
parent
0b32d97622
commit
d5171d1900
1 changed files with 14 additions and 28 deletions
|
|
@ -138,30 +138,6 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
|
|||
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(
|
||||
string $string,
|
||||
int $width,
|
||||
|
|
@ -170,15 +146,23 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
|
|||
array $lines = []
|
||||
): string
|
||||
{
|
||||
$label = new GtkLabel;
|
||||
|
||||
$label->set_use_markup(
|
||||
true
|
||||
);
|
||||
|
||||
foreach (explode(' ', $string) as $word)
|
||||
{
|
||||
if (isset($words[$line]))
|
||||
{
|
||||
$markup = implode(
|
||||
' ' , $words[$line]
|
||||
) . ' ' . $word;
|
||||
$label->set_markup(
|
||||
implode(
|
||||
' ' , $words[$line]
|
||||
) . ' ' . $word
|
||||
);
|
||||
|
||||
if (self::_width($markup) > $width)
|
||||
if ($label->get_layout()->get_pixel_size()['width'] > $width)
|
||||
{
|
||||
$line++;
|
||||
}
|
||||
|
|
@ -195,6 +179,8 @@ class Markup implements \Yggverse\Yoda\Interface\Model\Gtk\Pango\Markup
|
|||
);
|
||||
}
|
||||
|
||||
$label->destroy();
|
||||
|
||||
return implode(
|
||||
PHP_EOL,
|
||||
$lines
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue