Finalize SelectableStyle for items#216
Finalize SelectableStyle for items#216AydinHassan merged 6 commits intophp-school:masterfrom jtreminio:feature/selectable-style
Conversation
Codecov Report
@@ Coverage Diff @@
## master #216 +/- ##
============================================
- Coverage 93.29% 93.01% -0.29%
- Complexity 589 591 +2
============================================
Files 31 30 -1
Lines 1760 1761 +1
============================================
- Hits 1642 1638 -4
- Misses 118 123 +5
Continue to review full report at Codecov.
|
src/MenuItem/SplitItem.php
Outdated
| /** | ||
| * Finds largest itemExtra value in items | ||
| */ | ||
| private function calculateItemExtra() : void |
There was a problem hiding this comment.
Is this a change in behaviour or just a refactor?
There was a problem hiding this comment.
The only thing noteworthy in this particular PR is the addition of SplitItem::calculateItemExtra().
Since SplitItem does not contain its own styling, and markers/item extra are item-level now vs living in MenuStyle, this method loops through all items assigned to the split and finds the item with the largest item-extra value to calculate column sizes.
There was a problem hiding this comment.
Yes but what I mean is why. Is that new behaviour, for all columns to be equal size? I don't remember the current behaviour.
There was a problem hiding this comment.
Checking latest stable tag with this:
<?php
use PhpSchool\CliMenu\Builder\SplitItemBuilder;
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
require_once(__DIR__ . '/../vendor/autoload.php');
$itemCallable = function (CliMenu $menu) {
echo $menu->getSelectedItem()->getText();
};
$builder = (new CliMenuBuilder)
->setTitle('Basic CLI Menu Custom Item Extra')
->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
$b->addItem('First Item', $itemCallable, true)
->addItem('Second Item', $itemCallable, true)
->addItem('Third Item', $itemCallable, true);
})
->setItemExtra('[COMPLETE!]')
->addLineBreak('-');
$builder->getStyle()
->setDisplaysExtra(true);
$menu = $builder->build();
$menu->open();
It seems the item extra string is not displayed when in a split item:
Should I remove?
This is how it looks in this PR:
using this code:
<?php
use PhpSchool\CliMenu\Builder\SplitItemBuilder;
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\MenuItem\SelectableItem;
require_once(__DIR__ . '/../vendor/autoload.php');
$itemCallable = function (CliMenu $menu) {
echo $menu->getSelectedItem()->getText();
};
$menu = (new CliMenuBuilder)
->setTitle('Basic CLI Menu Custom Item Extra')
->setWidth(150)
->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
$item1 = new SelectableItem('First Item', $itemCallable, true);
$item1->getStyle()->setItemExtra('[COMPLETE!]');
$item2 = new SelectableItem('Second Item Second Item Second Item', $itemCallable, true);
$item2->getStyle()->setItemExtra('[abc!]');
$item3 = new SelectableItem('Third Item', $itemCallable, true);
$item3->getStyle()->setItemExtra('[!]');
$b->build()
->addItem($item1)
->addItem($item2)
->addItem($item3);
})
->addLineBreak('-')
->build();
$menu->open();
|
Thank you |


Related to #200
MenuStyle::$itemExtrashould also be removedMenuStyle::$displaysExtra, as they are no longer used for anything. Will put that in a separate PR.The only thing noteworthy in this particular PR is the addition of
SplitItem::calculateItemExtra().Since SplitItem does not contain its own styling, and markers/item extra are item-level now vs living in
MenuStyle, this method loops through all items assigned to the split and finds the item with the largest item-extra value to calculate column sizes.