Fix menu overflow in open dialog, menu scrolling

This commit is contained in:
2024-10-05 17:08:43 +02:00
parent eb09b4698f
commit 923aed5cbe
2 changed files with 15 additions and 4 deletions
+13 -3
View File
@@ -70,6 +70,7 @@ class Menu
} elseif ($ch == "k{DOWN}") {
$this->index++;
if ($this->index >= count($this->items)) $this->index = 0;
$this->redraw($left, $top, $width, $height);
}
}
@@ -83,6 +84,14 @@ class Menu
$visibleItems = $height - 2;
// scroll if index is out of view
if ($this->index < $this->scroll) {
$this->scroll = $this->index;
}
if ($this->index - $visibleItems >= $this->scroll) {
$this->scroll = $this->index - $visibleItems + 1;
}
$scrollTop = $this->scroll;
$scrollVisible = $visibleItems / count($this->items); // / $visibleItems;
$scrollBottom = $scrollTop + $scrollVisible;
@@ -103,7 +112,7 @@ class Menu
;
$keys = array_keys($this->items);
for ($n = 0; $n < $visibleItems; $n++) {
$key = $keys[$n]??null;
$key = $keys[$n + $this->scroll]??null;
$item = ($key ? ($this->items[$key]) : null);
if ($item === "---") {
$item = "\e[2m".str_repeat("\u{2500}", $width - 2)."\e[22m";
@@ -111,8 +120,9 @@ class Menu
$item = str_repeat(" ", $width - 2);
} else {
$item = mb_substr($item, 0, $width);
$item = " " . $item . str_repeat(" ", $width - 3 - $this->itemlen($item)) . "\e[40;37m";
$item = (($n == $this->index)?"\e[37;44m":"\e[40;37m") . $item;
$padlen = $width - 3 - $this->itemlen($item);
$item = " " . $item . ($padlen>0?str_repeat(" ", $padlen):"") . "\e[40;37m";
$item = (($n + $this->scroll == $this->index)?"\e[37;44m":"\e[40;37m") . $item;
}
if ($n >= $thumbTop && $n <= $thumbBottom) {
$scrollbar = "\e[97;1m".self::U_EDGE_VERTICAL_THUMB."\e[40;37;22m";