@@ -108,7 +108,12 @@ public function getRows(MenuStyle $style, bool $selected = false) : array
108
108
$ this ->setDefaultSelectedItem ();
109
109
}
110
110
111
- $ length = floor ($ style ->getContentWidth () / $ numberOfItems ) - $ this ->margin ;
111
+ $ length = $ style ->getDisplaysExtra ()
112
+ ? floor ($ style ->getContentWidth () / $ numberOfItems ) - (mb_strlen ($ style ->getItemExtra ()) + 2 )
113
+ : floor ($ style ->getContentWidth () / $ numberOfItems );
114
+
115
+ $ length -= $ this ->margin ;
116
+
112
117
$ missingLength = $ style ->getContentWidth () % $ numberOfItems ;
113
118
114
119
return $ this ->buildRows (
@@ -118,37 +123,48 @@ public function getRows(MenuStyle $style, bool $selected = false) : array
118
123
? sprintf ('%s ' , $ style ->getMarker ($ isSelected ))
119
124
: '' ;
120
125
126
+ $ itemExtra = '' ;
127
+ if ($ style ->getDisplaysExtra ()) {
128
+ $ itemExtra = $ item ->showsItemExtra ()
129
+ ? sprintf (' %s ' , $ style ->getItemExtra ())
130
+ : sprintf (' %s ' , str_repeat (' ' , mb_strlen ($ style ->getItemExtra ())));
131
+ }
132
+
121
133
return $ this ->buildCell (
122
134
explode ("\n" , StringUtil::wordwrap (sprintf ('%s%s ' , $ marker , $ item ->getText ()), $ length )),
123
135
$ length ,
124
136
$ style ,
125
- $ isSelected
137
+ $ isSelected ,
138
+ $ itemExtra
126
139
);
127
140
}, array_keys ($ this ->items ), $ this ->items ),
141
+ $ style ,
128
142
$ missingLength ,
129
143
$ length
130
144
);
131
145
}
132
146
133
- private function buildRows (array $ cells , int $ missingLength , int $ length ) : array
147
+ private function buildRows (array $ cells , MenuStyle $ style , int $ missingLength , int $ length ) : array
134
148
{
149
+ $ extraPadLength = $ style ->getDisplaysExtra () ? 2 + mb_strlen ($ style ->getItemExtra ()) : 0 ;
150
+
135
151
return array_map (
136
- function ($ i ) use ($ cells , $ length , $ missingLength ) {
137
- return $ this ->buildRow ($ cells , $ i , $ length , $ missingLength );
152
+ function ($ i ) use ($ cells , $ length , $ missingLength, $ extraPadLength ) {
153
+ return $ this ->buildRow ($ cells , $ i , $ length , $ missingLength, $ extraPadLength );
138
154
},
139
155
range (0 , max (array_map ('count ' , $ cells )) - 1 )
140
156
);
141
157
}
142
158
143
- private function buildRow (array $ cells , int $ index , int $ length , int $ missingLength ) : string
159
+ private function buildRow (array $ cells , int $ index , int $ length , int $ missingLength, int $ extraPadLength ) : string
144
160
{
145
161
return sprintf (
146
162
'%s%s ' ,
147
163
implode (
148
164
'' ,
149
165
array_map (
150
- function ($ cell ) use ($ index , $ length ) {
151
- return $ cell [$ index ] ?? str_repeat (' ' , $ length + $ this ->margin );
166
+ function ($ cell ) use ($ index , $ length, $ extraPadLength ) {
167
+ return $ cell [$ index ] ?? str_repeat (' ' , $ length + $ this ->margin + $ extraPadLength );
152
168
},
153
169
$ cells
154
170
)
@@ -157,9 +173,14 @@ function ($cell) use ($index, $length) {
157
173
);
158
174
}
159
175
160
- private function buildCell (array $ content , int $ length , MenuStyle $ style , bool $ isSelected ) : array
161
- {
162
- return array_map (function ($ row ) use ($ length , $ style , $ isSelected ) {
176
+ private function buildCell (
177
+ array $ content ,
178
+ int $ length ,
179
+ MenuStyle $ style ,
180
+ bool $ isSelected ,
181
+ string $ itemExtra
182
+ ) : array {
183
+ return array_map (function ($ row , $ index ) use ($ length , $ style , $ isSelected , $ itemExtra ) {
163
184
$ invertedColoursSetCode = $ isSelected
164
185
? $ style ->getInvertedColoursSetCode ()
165
186
: '' ;
@@ -168,14 +189,15 @@ private function buildCell(array $content, int $length, MenuStyle $style, bool $
168
189
: '' ;
169
190
170
191
return sprintf (
171
- '%s%s%s%s%s ' ,
192
+ '%s%s%s%s%s%s ' ,
172
193
$ invertedColoursSetCode ,
173
194
$ row ,
174
195
str_repeat (' ' , $ length - mb_strlen ($ row )),
196
+ $ index === 0 ? $ itemExtra : str_repeat (' ' , mb_strlen ($ itemExtra )),
175
197
$ invertedColoursUnsetCode ,
176
198
str_repeat (' ' , $ this ->margin )
177
199
);
178
- }, $ content );
200
+ }, $ content, array_keys ( $ content ) );
179
201
}
180
202
181
203
public function setSelectedItemIndex (int $ index ) : void
0 commit comments