-
Notifications
You must be signed in to change notification settings - Fork 106
Add border styling #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add border styling #100
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
bd16029
Add border styling
Lynesth b94fdb1
Add border styling
Lynesth 3bf82d3
Fix setBorder() to work like CSS border
Lynesth 4645481
Add setBorder() to CliMenuBuilder
Lynesth 5b9c9f6
Fix PSR2
Lynesth 8ad863f
Fix PSR2
Lynesth 5209f8c
Should fix the tests
Lynesth 796a49d
Fix setBorder
Lynesth 0d83512
Missing newlines
Lynesth 7eb1520
Missing configuration in buildStyle()
Lynesth 763619b
Add MenuStyle border tests
Lynesth 07b4e0c
Fix failing logic...
Lynesth 17164ed
Fix failing logic...
Lynesth 42a0206
Fixing some more
Lynesth a49d87d
Some more fixes
Lynesth 5a23153
Adding border to width and padding tests
Lynesth f435c44
Recalculate content width after setting borders
Lynesth ff3b1e8
Add Builder border tests
Lynesth ce87d98
Max coverage for setBorder tests in Builder
Lynesth 9c0cac9
Fix typo
Lynesth 752fa64
Add borders to custom-styles example
Lynesth ce5ba31
Merge branch 'master' into patch-14
Lynesth 78affc2
Better borderRows generation
Lynesth da7a7f7
Pre generate border top and bottom rows
Lynesth 0b8f8f1
Use pre generated border rows
Lynesth c1ee5d2
Fix wrong scope
Lynesth d484e5c
Add 256 colors support for border colour
Lynesth df9cad4
Many fixes
Lynesth cf795f2
typo
Lynesth ae227bc
Modify border colour handling (string only)
Lynesth 00a84fe
typehint fix
Lynesth 87df3da
throw exception is colour isn't string or null
Lynesth 7a8590a
refactoring
Lynesth c471626
missing ;
Lynesth d645c73
Fixes !
Lynesth cfa7953
Fix "wonky" selected item
Lynesth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,31 @@ class MenuStyle | |
*/ | ||
private $titleSeparator; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $borderTopWidth; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $borderRightWidth; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $borderBottomWidth; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $borderLeftWidth; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $borderColour; | ||
|
||
/** | ||
* Default Values | ||
* | ||
|
@@ -89,6 +114,11 @@ class MenuStyle | |
'itemExtra' => '✔', | ||
'displaysExtra' => false, | ||
'titleSeparator' => '=', | ||
'borderTopWidth' => 0, | ||
'borderRightWidth' => 0, | ||
'borderBottomWidth' => 0, | ||
'borderLeftWidth' => 0, | ||
'borderColour' => 'white', | ||
]; | ||
|
||
public static function getDefaultStyleValues() : array | ||
|
@@ -155,6 +185,12 @@ public function __construct(Terminal $terminal = null) | |
$this->setItemExtra(static::$defaultStyleValues['itemExtra']); | ||
$this->setDisplaysExtra(static::$defaultStyleValues['displaysExtra']); | ||
$this->setTitleSeparator(static::$defaultStyleValues['titleSeparator']); | ||
$this->setBorderTopWidth(static::$defaultStyleValues['borderTopWidth']); | ||
$this->setBorderRightWidth(static::$defaultStyleValues['borderRightWidth']); | ||
$this->setBorderBottomWidth(static::$defaultStyleValues['borderBottomWidth']); | ||
$this->setBorderLeftWidth(static::$defaultStyleValues['borderLeftWidth']); | ||
$this->setBorderColour(static::$defaultStyleValues['borderColour']); | ||
|
||
} | ||
|
||
public static function getAvailableColours() : array | ||
|
@@ -233,7 +269,7 @@ public function getUnselectedUnsetCode() : string | |
*/ | ||
protected function calculateContentWidth() : void | ||
{ | ||
$this->contentWidth = $this->width - ($this->padding*2) - ($this->margin*2); | ||
$this->contentWidth = $this->width - ($this->padding*2) - ($this->margin*2) - ($this->borderRightWidth + $this->borderLeftWidth); | ||
} | ||
|
||
public function getFg() : string | ||
|
@@ -267,7 +303,7 @@ public function getWidth() : int | |
|
||
public function setWidth(int $width) : self | ||
{ | ||
$availableWidth = $this->terminal->getWidth() - ($this->margin * 2) - ($this->padding * 2); | ||
$availableWidth = $this->terminal->getWidth() - ($this->margin * 2) - ($this->padding * 2) - ($this->borderRightWidth + $this->borderLeftWidth); | ||
|
||
if ($width >= $availableWidth) { | ||
$width = $availableWidth; | ||
|
@@ -387,4 +423,74 @@ public function setTitleSeparator(string $actionSeparator) : self | |
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Shorthand function to set all borders values at once | ||
*/ | ||
public function setBorder(int $topWidth, int $rightWidth = null, int $bottomWidth = null, int $leftWidth = null, string $colour = null) : self | ||
{ | ||
$this->borderTopWidth = $topWidth; | ||
$this->borderRightWidth = $rightWidth ?? $topWidth; | ||
$this->borderBottomWidth = $bottomWidth ?? $topWidth; | ||
$this->borderLeftWidth = $leftWidth ?? $rightWidth ?? $topWidth; | ||
if ($colour !== null) { | ||
$this->borderColour = $colour; | ||
} | ||
|
||
return $this; | ||
} | ||
public function setBorderTopWidth(int $width) : self | ||
{ | ||
$this->borderTopWidth = $width; | ||
|
||
return $this; | ||
} | ||
public function setBorderRightWidth(int $width) : self | ||
{ | ||
$this->borderRightWidth = $width; | ||
|
||
return $this; | ||
} | ||
public function setBorderBottomWidth(int $width) : self | ||
{ | ||
$this->borderBottomWidth = $width; | ||
|
||
return $this; | ||
} | ||
public function setBorderLeftWidth(int $width) : self | ||
{ | ||
$this->borderLeftWidth = $width; | ||
|
||
return $this; | ||
} | ||
public function setBorderColour(string $colour) : self | ||
{ | ||
$this->borderColour = $colour; | ||
|
||
return $this; | ||
} | ||
public function getBorderTopWidth() : int | ||
{ | ||
return $this->borderTopWidth; | ||
} | ||
public function getBorderRightWidth() : int | ||
{ | ||
return $this->borderRightWidth; | ||
} | ||
public function getBorderBottomWidth() : int | ||
{ | ||
return $this->borderBottomWidth; | ||
} | ||
public function getBorderLeftWidth() : int | ||
{ | ||
return $this->borderLeftWidth; | ||
} | ||
public function getBorderColour() : string | ||
{ | ||
return $this->borderColour; | ||
} | ||
public function getBorderColourCode() : string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a new line between each of these methods |
||
{ | ||
return sprintf("\033[%sm", self::$availableBackgroundColors[$this->getBorderColour()]['set']); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the $borderRow could be stored in the style so that it doesn't need to be recomputed each time but just when one of the values change, I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't sound like a crazy idea