Skip to content

Commit

Permalink
Fix centering
Browse files Browse the repository at this point in the history
  • Loading branch information
AydinHassan committed Oct 27, 2016
1 parent e9b166b commit fff333f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/Dialogue/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public function display($confirmText = 'OK')
$this->emptyRow();

$this->write(sprintf(
"%s %s %s\n",
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
str_repeat(' ', $this->style->getPadding()),
$this->text,
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
));

Expand Down Expand Up @@ -63,9 +65,11 @@ public function display($confirmText = 'OK')
);

$this->write(sprintf(
"%s %s %s\n",
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
str_repeat(' ', $this->style->getPadding()),
str_repeat(' ', mb_strlen($this->text)),
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
));

Expand Down
16 changes: 12 additions & 4 deletions src/Dialogue/Dialogue.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ protected function assertMenuOpen()
*/
protected function calculateCoordinates()
{
$textLines = count(explode("\n", $this->text)) + 2;
$this->y = ceil(($this->parentMenu->getCurrentFrame()->count() / 2)) - ceil($textLines / 2) + 1;
$this->x = ($this->style->getWidth() / 2) - (mb_strlen($this->text) / 2);
//y
$textLines = count(explode("\n", $this->text)) + 2;
$this->y = ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($textLines / 2) + 1;

//x
$parentStyle = $this->parentMenu->getStyle();
$dialogueHalfLength = (mb_strlen($this->text) + ($this->style->getPadding() * 2)) / 2;
$widthHalfLength = ceil($parentStyle->getWidth() / 2);
$this->x = $widthHalfLength - $dialogueHalfLength;
}

/**
Expand All @@ -85,9 +91,11 @@ protected function emptyRow()
{
$this->write(
sprintf(
"%s %s %s\n",
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
str_repeat(' ', $this->style->getPadding()),
str_repeat(' ', mb_strlen($this->text)),
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
)
);
Expand Down
4 changes: 3 additions & 1 deletion src/Dialogue/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public function display()
$this->emptyRow();

$this->write(sprintf(
"%s %s %s\n",
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
str_repeat(' ', $this->style->getPadding()),
$this->text,
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
));

Expand Down

0 comments on commit fff333f

Please sign in to comment.