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;
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue