-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add option to change the newlines before and after the menu is drawn #280
base: master
Are you sure you want to change the base?
Conversation
…aka vertical margin
What is the difference between this and the top/bottom padding? |
@AydinHassan could you take another look at this PR? |
@Zhigalin sorry i took so long to look. I think it would make a bit more sense to just use the margin value here? |
@AydinHassan margins are horisontal, the proposed fearure is abount vertical spacing. |
yes but we have the concept of top/bottom padding and left/right padding so we could do the same with margin, and then use the top/bottom margin instead of the top/bottom frame count. Then we could also take in to consideration the margin auto option and center the menu vertically when it's set. So yeah first lets add |
I was thinking something like: [$marginTop, $marginBottom] = $this->style->getMarginTopBottom($frame->count());
$frame->prependNewLine($marginTop);
$frame->newLine($marginBottom); in CliMenu::draw and /**
* @return array{0: int, 1: int}
*/
public function getMarginTopBottom(int $contentHeight): array
{
if ($this->isMarginAuto()) {
$availableHeight = $this->terminal->getHeight();
if ($contentHeight < $availableHeight) {
return [
(int) floor(($availableHeight - $contentHeight) / 2),
(int) ceil(($availableHeight - $contentHeight) / 2)
];
}
return [0, 0];
}
return [$this->marginTop, $this->marginBottom];
} in |
Ok, will do |
This feature is useful because it allows you to either reduce or set to zero the vertical margins in cases of a small terminal window (my case for which I made this feature) or a very large menu and you have to use every inch to fit it into the terminal,
or you can increment it to move or center the menu vertically.