From 3a5088edadac4ae2b297fa273de8171052678973 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Tue, 15 May 2018 21:23:04 +1100 Subject: [PATCH 1/2] Split Item docs --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8160d9dd..8d5ecb29 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ * [Static Item](#static-item) * [Ascii Art Item](#ascii-art-item) * [Sub Menu Item](#sub-menu-item) + * [Split Item](#split-item) * [Disabling Items & Sub Menus](#disabling-items--sub-menus) * [Item Markers](#item-markers) * [Item Extra](#item-extra) @@ -464,6 +465,7 @@ There a few different types of items you can add to your menu * Static Item - This will print whatever text is passed, useful for headings. * Ascii Art Item - Special item which allows usage of Ascii art. It takes care of padding and alignment. * Sub Menu Item - Special item to allow an item to open another menu. Useful for an options menu. +* Split Item - Special item to fit multiple items on the same row. ### Selectable Item @@ -569,7 +571,7 @@ $menu = (new CliMenuBuilder) The third optional parameter to `addAsciiArt` is alternate text. If the ascii art is too wide for the terminal, then it will not be displayed at all. However, if you pass a string to the third argument, in the case that the ascii art is too -wide for the terminal the alternate text will be displayed instead. +wide for the terminal the alternate text will be displayed instead. ### Sub Menu Item @@ -610,7 +612,7 @@ There are a few things to note about the syntax and builder process here 1. The first parameter to `addSubMenu` must be a unique id to reference the sub menu. The second parameter is the text to be displayed on the menu which you select to enter the submenu. 2. `addSubMenu` returns an instance of `CliMenuBuilder` so you can can customise exactly the same way you would the parent. 3. If you do not modify the styles of the sub menu (eg, colours) it will inherit styles from the parent! -4. You can call `end()` on the sub menu `CliMenuBuilder` instance to get the parent `CliMenuBuilder` back again. This is useful for chaining. +4. You can call `end()` on the sub menu `CliMenuBuilder` instance to get the parent `Builder` back again. This is useful for chaining. If you need the `CliMenu` instance of the Sub Menu you can grab it after the main menu has been built using the unique id you passed to `addSubMenu. @@ -649,6 +651,44 @@ In this case `addSubMenu` will return the main menu builder, not the sub menu bu The submenu menu item will be an instance of `\PhpSchool\CliMenu\MenuItem\MenuMenuItem`. If you need access to the submenu, you can get it via `$menuMenuItem->getSubMenu()`. +### Split Item + +Split Items allows you to add multiple items on the same row. The full width of the menu will be split evenly between all items. You can move between those items using left/right arrows. +Only Selectable, Static and SubMenu items are currently allowed inside a Split Item. + +```php +getSelectedItem()->getText(); +}; + +$menu = (new CliMenuBuilder) + ->setWidth(150) + ->addStaticItem('Below is a SplitItem') + ->addSplitItem() + ->addSubMenu('Sub Menu on a split item') + ->setTitle('Behold the awesomeness') + ->addItem('This is awesome', function() { print 'Yes!'; }) + ->end() + ->addItem('Item 2', $itemCallable) + ->addStaticItem('Item 3 - Static') + ->end() + ->build(); + +$menu->open(); +``` + +There are a few things to note about the syntax and builder process here: + +1. There is no argument to `addSplitItem`. +2. `addSplitItem` returns an instance of `SplitItemBuilder`, the main menu will take care of building all split items (and any submenu they might contain). +3. You can call `addItem`, `addSubMenu` and `addStaticItem` on the `SplitItemBuilder`. +4. Like when building submenus, you can call `end()` on the Split Item `SplitItemBuilder` instance to get the parent `CliMenuBuilder` back again. This is useful for chaining. + ### Disabling Items & Sub Menus In this example we are disabling certain items and a submenu but still having them shown in the menu. @@ -685,7 +725,7 @@ The third param on the `->addItem` call is what disables an item while the `->di The outcome is a full menu with dimmed rows to denote them being disabled. When a user navigates these items are jumped over to the next available selectable item. -#### Item Markers +### Item Markers The marker displayed by the side of the currently active item can be modified, UTF-8 characters are supported. The marker for un-selected items can also be modified. If you want to disable it, just set it to a space character. Item From 2f49c54cb7d8c0f798ec7c499a5420867cd707e1 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Tue, 15 May 2018 23:32:36 +1100 Subject: [PATCH 2/2] Add screenshot and info for Split Item --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 8d5ecb29..02d66f6d 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,9 @@ php basic.php submenu submenu-options +#### Split Item +split-item + #### Disabled Items & Submenus submenu @@ -654,6 +657,9 @@ you can get it via `$menuMenuItem->getSubMenu()`. ### Split Item Split Items allows you to add multiple items on the same row. The full width of the menu will be split evenly between all items. You can move between those items using left/right arrows. + +You can set the number of spaces separating items using `->setGutter()` (defaults to 2). + Only Selectable, Static and SubMenu items are currently allowed inside a Split Item. ```php @@ -670,6 +676,7 @@ $menu = (new CliMenuBuilder) ->setWidth(150) ->addStaticItem('Below is a SplitItem') ->addSplitItem() + ->setGutter(5) ->addSubMenu('Sub Menu on a split item') ->setTitle('Behold the awesomeness') ->addItem('This is awesome', function() { print 'Yes!'; })