ListBox: Add Highlight property to highlight the listbox entry under the mouse cursor.

[GB.GUI.BASE]
* NEW: ListBox: Add Highlight property to highlight the listbox entry under the mouse cursor.
* NEW: Helper function for the future 'Window.ShowPopupAt()' method.
* NEW: ScrollArea: The mouse wheel now scroll a number of pixels proportional to 'Desktop.Scale'.
This commit is contained in:
Benoît Minisini 2023-10-13 16:59:01 +02:00
parent 9b15ce56f3
commit dadb89c87d
5 changed files with 139 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# Gambas Project File 3.0
Title=Common controls and classes for GUI components
Startup=FTestCombo
Startup=FListBox
Icon=.hidden/window.png
Version=3.18.90
VersionFile=1

View file

@ -3,7 +3,7 @@
Export
Inherits UserControl
Public Const _Properties As String = "*,List,Border=True,Grid,Mode{Select.*}=Single,ScrollBar{Scroll.*}=Vertical,Wrap,Sorted"
Public Const _Properties As String = "*,List,Border=True,Grid,Mode{Select.*}=Single,ScrollBar{Scroll.*}=Vertical,Wrap,Sorted,Highlight"
Public Const _Group As String = "View"
Public Const _DefaultEvent As String = "Click"
Public Const _DefaultSize As String = "16,16"
@ -19,6 +19,7 @@ Property Index As Integer
Property Read Text As String
Property List As String[]
Property Font As Font
Property Highlight As Boolean
'' Return or set if the item text must wrap and the item height expands automatically.
Property Wrap As Boolean
@ -45,9 +46,14 @@ Private $hTimerClick As Timer
Private $bWrap As Boolean
Private $hResizeTimer As Timer
Private $sFind As String
Private $iHighlight As Integer
Private $hObs As Observer
Private $bHighlight As Boolean
Public Sub _new()
Dim hScrollArea As ScrollArea
$hView = New GridView(Me) As "GridView"
$hView.Columns.Count = 1
$hView.Mode = Select.Single
@ -135,6 +141,8 @@ Public Sub GridView_Data(Row As Integer, (Column) As Integer)
If $hView.Rows[Row].Selected Then
.Background = Color.SelectedBackground
.Foreground = Color.SelectedForeground
Else If $bHighlight And If Row = $iHighlight Then
.Background = Color.LightBackground
Endif
End With
@ -157,6 +165,50 @@ Public Sub GridView_Activate()
End
Private Sub SetHighlight(Y As Integer)
Dim iRow As Integer
Dim hScrollArea As ScrollArea
If $bHighlight Then
hScrollArea = $hView.Children[0]
If hScrollArea.View.Hovered Then
iRow = $hView.RowAt(Y)
Else
iRow = -1
Endif
If iRow <> $iHighlight Then
If $iHighlight >= 0 Then $hView.Rows[$iHighlight].Refresh()
$iHighlight = iRow
If $iHighlight >= 0 Then $hView.Rows[$iHighlight].Refresh()
Endif
Endif
End
Public Sub Area_Leave()
SetHighlight(-1)
End
Public Sub GridView_MouseMove()
SetHighlight(Mouse.Y)
End
Public Sub GridView_Scroll()
SetHighlight(Mouse.ScreenY - $hView.ScreenY)
End
Private Sub FindItem()
Main.FindItem($hView, $sFind, $aText)
@ -539,7 +591,7 @@ Private Sub Wrap_Write(Value As Boolean)
If $bWrap = Value Then Return
$bWrap = Value
UpdateLayout
SortLater
End
@ -561,3 +613,22 @@ Private Sub Grid_Write(Value As Boolean)
$hView.Rows.Padding = If(Value, Desktop.Scale, 0)
End
Private Function Highlight_Read() As Boolean
Return $bHighlight
End
Private Sub Highlight_Write(Value As Boolean)
If $bHighlight = Value Then Return
$bHighlight = Value
If $bHighlight Then
$hObs = New Observer(ScrollArea($hView.Children[0]).View) As "Area"
Else
$hObs.Detach()
$hObs = Null
Endif
End

View file

@ -750,13 +750,16 @@ End
Public Sub DrawingArea_MouseWheel()
Dim D As Integer
If Not Me.Enabled Or If Me.Design Then Return
If Not $bUseMouse Then Return
D = Desktop.Scale * 60
If Mouse.Orientation = Mouse.Horizontal Or If $H <= $hDrawingArea.H Then
Scroll($iScrollX - Mouse.Delta * $hHBar.PageStep / 2, $iScrollY)
Scroll($iScrollX - Mouse.Delta * D, $iScrollY)
Else
Scroll($iScrollX, $iScrollY - Mouse.Delta * $hVBar.PageStep / 2)
Scroll($iScrollX, $iScrollY - Mouse.Delta * D)
Endif
End

View file

@ -12,6 +12,7 @@
List = [("C"), ("a"), ("שלום וברכה"), ("B"), ("Arnaud"), ("Bernard"), ("Benedicte"), ("Antoine"), ("Charles"), ("Dimitri"), ("Fabien"), ("Farid"), ("Marthe"), ("Mathilde"), ("Pierre")]
Wrap = True
Sorted = True
Highlight = True
}
{ Panel1 Panel
MoveScaled(28,3,19.875,32.875)

View file

@ -13,6 +13,10 @@ Static Private $iFrameX As Integer
Static Private $iFrameY As Integer
Static Private $bInFrame As Boolean
Static Private $hPopupCtrl As Control
Static Private $iPopupPos As Integer
Static Private $iPopupAlign As Integer
' Not use anymore?
Static Public Sub _FindShortcut(sText As String) As Integer
@ -415,3 +419,58 @@ Static Public Sub DndFrame_Draw()
Paint.DrawRect(0, 0, Paint.W, Paint.H, Color.SelectedBackground)
End
Static Public Sub _ShowPopupAt(hWin As Window, Control As Control, Optional Position As Integer = Align.Bottom, Alignment As Integer = Align.Normal) As Integer
Dim hObs As Observer
$hPopupCtrl = Control
$iPopupPos = Position
$iPopupAlign = Alignment
hObs = New Observer(hWin) As "PopupWindow"
Return hWin.ShowPopup()
End
Static Public Sub PopupWindow_Resize()
Dim X As Integer
Dim Y As Integer
Dim hWin As Window
hWin = Last
If Align.IsLeft($iPopupPos) Or If Align.IsRight($iPopupPos) Then
If Align.IsLeft($iPopupPos) Then
X = $hPopupCtrl.ScreenX - hWin.W
Else
X = $hPopupCtrl.ScreenX
Endif
If Align.IsTop($iPopupAlign) Then
Y = $hPopupCtrl.ScreenY
Else If Align.IsBottom($iPopupAlign) Then
Y = $hPopupCtrl.ScreenY + $hPopupCtrl.H - hWin.H
Endif
Else
If Align.IsTop($iPopupPos) Then
Y = $hPopupCtrl.ScreenY - hWin.H
Else
Y = $hPopupCtrl.ScreenY + $hPopupCtrl.H
Endif
If Align.IsLeft($iPopupAlign) Then
X = $hPopupCtrl.ScreenX
Else If Align.IsRight($iPopupAlign) Then
X = $hPopupCtrl.ScreenX + $hPopupCtrl.W - hWin.W
Endif
Endif
hWin.Move(X, Y)
End