#!/usr/bin/env gbs3
USE "gb.ncurses"
class Menu
property read Width as integer
property Height as integer
property X as integer
property Y as integer
property Align as integer
EVENT Activate(Index as Integer, Value as String)
private $iWidth as integer
private $iHeight as integer
private $iX as integer
private $iY as integer
private $iAlign as integer
private $hWin as window
private $sOpts as string[]
private $iOption as integer
private $iEsc as integer = 27
public sub _new(hWin as window, Opts as string[], X as Integer, Y as Integer, optional Width as integer = 0, optional Height as integer = 0)
$hWin = hWin
$sOpts = Opts
$iX = X
$iY = Y
$iWidth = iif(Width = 0, Maximo(), Width)
$iHeight = iif(Height = 0, $sOpts.Count, Height)
end
public sub Show()
dim i, iOpt, iIni, iFin as integer
dim sLinea, sCol, sOpt, sOption as string
DIM bResult AS Boolean
$iOption = 0
sLinea = "+"
' for i = 1 to $iWidth
for i = 1 to Maximo()
sLinea &= "-"
next
sLinea &= "+"
$hWin.print(sLinea, $iX, $iY)
for i = $iY + 1 to $iY + $iHeight
$hWin.print("|", $iX, i)
$hWin.print("|", $iX + Maximo() + 1, i)
' $hWin.print("|", $iX + $iWidth + 1, i)
next
$hWin.print(sLinea, $iX, i)
While iOpt <> $iEsc
i = 1
iIni = iif($iOption < $iHeight, 0, $iOption - $iHeight + 1)
iFin = iIni + $iHeight - 1
' $hWin.print($iOption & "/" & $sOpts.count, 0, 0)
' $hWin.print(iIni & "x" & iFin, 0, 1)
for i = iIni to iFin
if $iOption = i then
$hwin.Attributes.Reverse = True
$hwin.Attributes.Bold = True
' endif
' if $iAlign = 1 then
' sOption = $sOpts[i] & space$($iWidth - len($sOpts[i]))
' endif
' $hWin.print(mid($sOpts[i] & space$($iWidth - len($sOpts[i])), 1, $iWidth - 1), $iX + 1, $iY + i + 1 - iIni)
' sOption = mid($sOpts[i], 3, 1)
sOption = $sOpts[i] & space(Maximo() - len($sOpts[i]))
$hWin.print(sOption, $iX + 1, $iY + i + 1 - iIni)
$hwin.Attributes.Normal = True
next
iOpt = $hwin.WaitKey()
if iOpt = key.up then
dec $iOption
if $iOption < 0 then $iOption = $sOpts.count - 1
else if iOpt = key.down then
inc $iOption
if $iOption >= $sOpts.count then $iOption = 0
else if iOpt = key.Return then
bResult = raise Activate($iOption, $sOpts[$iOption])
endif
wend
end
private function Maximo() as integer
dim iMax as integer
dim sOpt, sOpt1, sOpt2 as string
sOpt1 = ""
sOpt2 = ""
for each sOpt in $sOpts
sOpt1 = sOpt2
sOpt2 = sOpt
iMax = Max(len(sOpt1), len(sOpt2))
next
return iMax
end
private sub Width_Read() as integer
return $iWidth
end
private sub Height_Read() as integer
return $iHeight
end
private sub Height_Write(Value as integer)
$iHeight = Value
end
private sub X_Read() as integer
return $iX
end
private sub X_Write(Value as integer)
$iX = Value
end
private sub Y_Read() as integer
return $iY
end
private sub Y_Write(Value as integer)
$iY = Value
end
private sub Align_Read() as integer
return $iAlign
end
private sub Align_Write(Value as integer)
$iAlign = Value
end
end class
private hwin As Window
private ventana as string = "menu"
public sub main()
dim a as integer
dim b as string
dim hMenu as Menu
hwin = New Window(0, 0, 20, 30)
hwin.Background = Color.Blue
hwin.show()
hwin.Full()
hMenu = New Menu(hwin, ["a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "jjjjjjjjjj", "kkkkkkkkkkk", "llllllllllll"], 0, 0, 5, 5) as "hMenu"
hMenu.show
if Screen.Lines >= 30 then hwin.Border=True
end
public sub hMenu_Activate(Index as Integer, Value as String)
hwin.printcenter("Index: " & Index & " - Value: " & Value)
end
USE "gb.ncurses"
class Menu
property read Width as integer
property Height as integer
property X as integer
property Y as integer
property Align as integer
EVENT Activate(Index as Integer, Value as String)
private $iWidth as integer
private $iHeight as integer
private $iX as integer
private $iY as integer
private $iAlign as integer
private $hWin as window
private $sOpts as string[]
private $iOption as integer
private $iEsc as integer = 27
public sub _new(hWin as window, Opts as string[], X as Integer, Y as Integer, optional Width as integer = 0, optional Height as integer = 0)
$hWin = hWin
$sOpts = Opts
$iX = X
$iY = Y
$iWidth = iif(Width = 0, Maximo(), Width)
$iHeight = iif(Height = 0, $sOpts.Count, Height)
end
public sub Show()
dim i, iOpt, iIni, iFin as integer
dim sLinea, sCol, sOpt, sOption as string
DIM bResult AS Boolean
$iOption = 0
sLinea = "+"
' for i = 1 to $iWidth
for i = 1 to Maximo()
sLinea &= "-"
next
sLinea &= "+"
$hWin.print(sLinea, $iX, $iY)
for i = $iY + 1 to $iY + $iHeight
$hWin.print("|", $iX, i)
$hWin.print("|", $iX + Maximo() + 1, i)
' $hWin.print("|", $iX + $iWidth + 1, i)
next
$hWin.print(sLinea, $iX, i)
While iOpt <> $iEsc
i = 1
iIni = iif($iOption < $iHeight, 0, $iOption - $iHeight + 1)
iFin = iIni + $iHeight - 1
' $hWin.print($iOption & "/" & $sOpts.count, 0, 0)
' $hWin.print(iIni & "x" & iFin, 0, 1)
for i = iIni to iFin
if $iOption = i then
$hwin.Attributes.Reverse = True
$hwin.Attributes.Bold = True
' endif
' if $iAlign = 1 then
' sOption = $sOpts[i] & space$($iWidth - len($sOpts[i]))
' endif
' $hWin.print(mid($sOpts[i] & space$($iWidth - len($sOpts[i])), 1, $iWidth - 1), $iX + 1, $iY + i + 1 - iIni)
' sOption = mid($sOpts[i], 3, 1)
sOption = $sOpts[i] & space(Maximo() - len($sOpts[i]))
$hWin.print(sOption, $iX + 1, $iY + i + 1 - iIni)
$hwin.Attributes.Normal = True
next
iOpt = $hwin.WaitKey()
if iOpt = key.up then
dec $iOption
if $iOption < 0 then $iOption = $sOpts.count - 1
else if iOpt = key.down then
inc $iOption
if $iOption >= $sOpts.count then $iOption = 0
else if iOpt = key.Return then
bResult = raise Activate($iOption, $sOpts[$iOption])
endif
wend
end
private function Maximo() as integer
dim iMax as integer
dim sOpt, sOpt1, sOpt2 as string
sOpt1 = ""
sOpt2 = ""
for each sOpt in $sOpts
sOpt1 = sOpt2
sOpt2 = sOpt
iMax = Max(len(sOpt1), len(sOpt2))
next
return iMax
end
private sub Width_Read() as integer
return $iWidth
end
private sub Height_Read() as integer
return $iHeight
end
private sub Height_Write(Value as integer)
$iHeight = Value
end
private sub X_Read() as integer
return $iX
end
private sub X_Write(Value as integer)
$iX = Value
end
private sub Y_Read() as integer
return $iY
end
private sub Y_Write(Value as integer)
$iY = Value
end
private sub Align_Read() as integer
return $iAlign
end
private sub Align_Write(Value as integer)
$iAlign = Value
end
end class
private hwin As Window
private ventana as string = "menu"
public sub main()
dim a as integer
dim b as string
dim hMenu as Menu
hwin = New Window(0, 0, 20, 30)
hwin.Background = Color.Blue
hwin.show()
hwin.Full()
hMenu = New Menu(hwin, ["a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "jjjjjjjjjj", "kkkkkkkkkkk", "llllllllllll"], 0, 0, 5, 5) as "hMenu"
hMenu.show
if Screen.Lines >= 30 then hwin.Border=True
end
public sub hMenu_Activate(Index as Integer, Value as String)
hwin.printcenter("Index: " & Index & " - Value: " & Value)
end