File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ protected function calculateCoordinates() : void
7474 //x
7575 $ parentStyle = $ this ->parentMenu ->getStyle ();
7676 $ dialogueHalfLength = (mb_strlen ($ this ->text ) + ($ this ->style ->getPadding () * 2 )) / 2 ;
77- $ widthHalfLength = ceil ($ parentStyle ->getWidth () / 2 );
77+ $ widthHalfLength = ceil ($ parentStyle ->getWidth () / 2 + $ parentStyle -> getMargin () );
7878 $ this ->x = $ widthHalfLength - $ dialogueHalfLength ;
7979 }
8080
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ private function calculateXPosition(Input $input, string $userInput) : int
132132
133133 $ parentStyle = $ this ->parentMenu ->getStyle ();
134134 $ halfWidth = ($ width + ($ input ->getStyle ()->getPadding () * 2 )) / 2 ;
135- $ parentHalfWidth = ceil ($ parentStyle ->getWidth () / 2 );
135+ $ parentHalfWidth = ceil ($ parentStyle ->getWidth () / 2 + $ parentStyle -> getMargin () );
136136
137137 return $ parentHalfWidth - $ halfWidth ;
138138 }
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ public function getUnselectedUnsetCode() : string
233233 */
234234 protected function calculateContentWidth () : void
235235 {
236- $ this ->contentWidth = $ this ->width - ($ this ->padding *2 ) - ( $ this -> margin * 2 ) ;
236+ $ this ->contentWidth = $ this ->width - ($ this ->padding *2 );
237237 }
238238
239239 public function getFg () : string
@@ -267,13 +267,14 @@ public function getWidth() : int
267267
268268 public function setWidth (int $ width ) : self
269269 {
270- $ availableWidth = $ this ->terminal ->getWidth () - ($ this ->margin * 2 ) - ($ this ->padding * 2 );
271-
272- if ($ width >= $ availableWidth ) {
273- $ width = $ availableWidth ;
270+ if ($ width >= $ this ->terminal ->getWidth ()) {
271+ $ width = $ this ->terminal ->getWidth ();
274272 }
275273
276274 $ this ->width = $ width ;
275+ if ($ this ->margin === -1 ) {
276+ $ this ->setMargin (-1 );
277+ }
277278 $ this ->calculateContentWidth ();
278279
279280 return $ this ;
@@ -300,9 +301,11 @@ public function getMargin() : int
300301
301302 public function setMargin (int $ margin ) : self
302303 {
303- $ this ->margin = $ margin ;
304-
305- $ this ->calculateContentWidth ();
304+ if ($ this ->margin === -1 ) {
305+ $ this ->margin = floor (($ this ->terminal ->getWidth () - $ this ->width ) / 2 );
306+ } else {
307+ $ this ->margin = $ margin ;
308+ }
306309
307310 return $ this ;
308311 }
You can’t perform that action at this time.
0 commit comments