From 74c1e9b6ce451f317f53a9c7be242314645d94b4 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 2 May 2018 21:49:29 +1100 Subject: [PATCH 1/2] Adding alternateText to AsciiArtItem --- src/MenuItem/AsciiArtItem.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/MenuItem/AsciiArtItem.php b/src/MenuItem/AsciiArtItem.php index 4da5f683..efdc3d3c 100644 --- a/src/MenuItem/AsciiArtItem.php +++ b/src/MenuItem/AsciiArtItem.php @@ -27,17 +27,23 @@ class AsciiArtItem implements MenuItemInterface */ private $position; + /** + * @var string + */ + private $alternateText; + /** * @var int */ private $artLength; - public function __construct(string $text, string $position = self::POSITION_CENTER) + public function __construct(string $text, string $position = self::POSITION_CENTER, string $alt = '') { Assertion::inArray($position, [self::POSITION_CENTER, self::POSITION_RIGHT, self::POSITION_LEFT]); $this->text = $text; $this->position = $position; + $this->alternateText = $alt; $this->artLength = max(array_map('mb_strlen', explode("\n", $text))); } @@ -46,6 +52,11 @@ public function __construct(string $text, string $position = self::POSITION_CENT */ public function getRows(MenuStyle $style, bool $selected = false) : array { + if ($this->artLength > $style->getContentWidth()) { + $alternate = new StaticItem($this->alternateText); + return $alternate->getRows($style, false); + } + return array_map(function ($row) use ($style) { $length = mb_strlen($row); From ff9df062d88d7116a3e640cf1044f50b0ff0ac5e Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 2 May 2018 21:58:58 +1100 Subject: [PATCH 2/2] Update CliMenuBuilder.php --- src/CliMenuBuilder.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/CliMenuBuilder.php b/src/CliMenuBuilder.php index b3fc75ff..158db569 100644 --- a/src/CliMenuBuilder.php +++ b/src/CliMenuBuilder.php @@ -136,13 +136,9 @@ public function addLineBreak(string $breakChar = ' ', int $lines = 1) : self return $this; } - public function addAsciiArt(string $art, string $position = AsciiArtItem::POSITION_CENTER) : self + public function addAsciiArt(string $art, string $position = AsciiArtItem::POSITION_CENTER, string $alt) : self { - $asciiArtItem = new AsciiArtItem($art, $position); - - if ($asciiArtItem->getArtLength() <= $this->getMenuStyle()->getContentWidth()) { - $this->addMenuItem($asciiArtItem); - } + $this->addMenuItem(new AsciiArtItem($art, $position, $alt)); return $this; }