Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASCII scrollable list with mouse
#1
Hi QB64 Fan Community

here a perfectable demo of a Vertical Scrolling List in ASCII mode
Code: (Select All)
'ASCII scrollbar output  Demo
Dim Num(1 To 100), First As Integer, Last As Integer, Selected As Integer
Dim Stopp, MB1, MB2, Max, MY, MX
Max = 100
For a = 1 To Max
    Num(a) = a * 10
Next
_MouseMove 10, 10
First = 1: Last = 15: Selected = First + 4
While Stopp = 0
    While _MouseInput: Wend
    MB1 = _MouseButton(1)
    MB2 = _MouseButton(2)
    MY = _MouseX 'column
    MX = _MouseY 'row
    If MB1 Then
        If Chr$(Screen(MX, MY, 0)) = "Ý" Then ' if leftmousebuttonclick is on the scrollingbar
            If MX > (Selected Mod 16) Then ' if mouseclick below selected item it scrolls down
                Selected = Selected + 5
                If Selected > Last Then ' if scrolling Selected goes below LastitemShown it adjourns pointers of listToShow
                    First = Selected
                    Last = First + 15
                    If Last > Max Then Last = Max - Selected + 1 ' if lastItemShown is more than LastItemList it adjourns pointer of listToShow
                End If
            Else 'if mouseclick over selected item it scrolls up
                Selected = Selected - 5
                If Selected < First Then
                    First = Selected
                    Last = First + 15
                    If Selected < 1 Then ' if scrolling up selected goes over FirstItemShown it adjourns pointer of ListToShow
                        First = 1
                        Selected = 1
                        Last = First + 15
                    End If
                End If
            End If
        End If
        If Chr$(Screen(MX, MY, 0)) = "Û" Then ' if leftMouseClick is on ruler of scrollingBar
            Do While _MouseInput: Loop ' it waits that MouseInput stops
            If MX > _MouseY Then
                ' if actual vertical position of mouse is less than previous the ruler has been brought up
                Selected = Selected - 1
                If Selected < 1 Then
                    First = 1
                    Selected = 1
                    Last = First + 15
                End If
            Else ' if actual vertical position of mouse is more than previous ther ruler has been brought down
                Selected = Selected + 1
                If Selected > Last Then
                    First = Selected
                    Last = Selected + 15
                    If Last > Max Then Last = Max - Selected
                End If
            End If
        End If
    End If
    If MB2 Then Stopp = 1
    Do While _MouseInput: Loop ' it waits that MouseInput stops
    Cls
    For a = First To Last
        If a = Selected Then Color 14, 1
        Print Num(a); Space$(5 - Len(LTrim$(Str$(a))));
        If a = Selected Then Print "Û" Else Print "Ý"
        Color 7, 0
    Next
    _Limit 5
Wend
End

It's a start and can be expanded to support mouse Drag & Drop, Keyboard shortcuts, and moreover the customizable setting (i.e. how many  rows to show on screen,  position on the screen, colors for text and background). 
Moreover it can become a function that return the selected item.
Reply


Messages In This Thread
ASCII scrollable list with mouse - by TempodiBasic - 10-23-2022, 07:35 AM
RE: ASCII scrollable list with mouse - by bplus - 10-23-2022, 11:50 AM
RE: ASCII scrollable list with mouse - by Pete - 10-23-2022, 02:54 PM



Users browsing this thread: 3 Guest(s)