Add PgUp/Dn/Home/End to menu, bugfixes

This commit is contained in:
2024-10-05 17:54:49 +02:00
parent 0a82eb7a3c
commit f389e5985f
3 changed files with 131 additions and 73 deletions
+32 -10
View File
@@ -105,15 +105,37 @@ class Menu
return array_keys($this->items)[$this->index];
}
} else {
if ($ch == "k{UP}") {
$this->index--;
if ($this->index < 0) $this->index = count($this->items) - 1;
$this->redraw($left, $top, $width, $height);
} elseif ($ch == "k{DOWN}") {
$this->index++;
if ($this->index >= count($this->items)) $this->index = 0;
$this->redraw($left, $top, $width, $height);
switch ($ch) {
case "k{UP}":
$this->index--;
if ($this->index < 0) $this->index = count($this->items) - 1;
$this->redraw($left, $top, $width, $height);
break;
case "k{DOWN}":
$this->index++;
if ($this->index >= count($this->items)) $this->index = 0;
$this->redraw($left, $top, $width, $height);
break;
case "k{PGUP}":
$this->index -= $height - 2;
if ($this->index < 0) $this->index = count($this->items) - 1;
$this->redraw($left, $top, $width, $height);
break;
case "k{PGDN}":
$this->index += $height - 2;
if ($this->index >= count($this->items)) $this->index = 0;
$this->redraw($left, $top, $width, $height);
break;
case "k{HOME}":
$this->index = 0;
if ($this->index >= count($this->items)) $this->index = 0;
$this->redraw($left, $top, $width, $height);
break;
case "k{END}":
$this->index = count($this->items) - 1;
if ($this->index >= count($this->items)) $this->index = 0;
$this->redraw($left, $top, $width, $height);
break;
}
}
}
@@ -146,7 +168,7 @@ class Menu
$scrollTop = $this->scroll;
$scrollBottom = $scrollTop + $visibleItems - 1;
$thumbTop = round(($visibleItems - 1) / count($this->items) * $scrollTop);
$thumbBottom = round(($visibleItems - 1) / count($this->items) * $scrollBottom);
$thumbBottom = round(($visibleItems) / count($this->items) * $scrollBottom);
$tleft = round(($width / 2) - ((mb_strlen($this->title) + 2) / 2));