ComboBox: The popup layout is now more clever to mimic the old Qt native popup behaviour.

[GB.GUI.BASE]
* NEW: ComboBox: The width of the popup now tries to fit the largest item if possible.
* NEW: ComboBox: The popup is now positioned so that it is always fully visible as much as possible. It must not work on Wayland.
This commit is contained in:
Benoît Minisini 2022-05-27 15:48:24 +02:00
parent 33ec6b88e3
commit 971747a31b
4 changed files with 39 additions and 10 deletions

View file

@ -337,7 +337,7 @@ Public Sub ArrowBox_MouseDown()
iIndex = Index_Read()
$hPopup = New FComboBoxPopup
iIndex = $hPopup.Open($aList, iIndex, Me.ScreenX, Me.ScreenY + Me.H, Me.W)
iIndex = $hPopup.Open($aList, iIndex, Me)
$hPopup = Null
If iIndex >= 0 Then Index_Write(iIndex)
Me.SetFocus

View file

@ -1,21 +1,51 @@
' Gambas class file
Private Const MAX_ITEMS As Integer = 10
Private $aList As String[]
Public Sub Open(aList As String[], iIndex As Integer, X As Integer, Y As Integer, W As Integer) As Integer
Public Sub Open(aList As String[], iIndex As Integer, hCtrl As Control) As Integer
Dim iRow As Integer
Dim I As Integer
Dim hFont As Font
Dim WM As Integer
Dim X, Y, W, H As Integer
Dim hScreen As Screen
hScreen = Screens[hCtrl.Window.Screen]
$aList = aList
Me.Arrangement = Arrange.None
gvwPopup.Rows.Count = aList.Count
gvwPopup.Columns.Count = 1
gvwPopup.Columns[0].Expand = True
'gvwPopup.Columns[0].Expand = True
gvwPopup.Columns[0].W = -1
W -= Style.FrameWidth * 2
X += Style.FrameWidth
W = hCtrl.W - Style.FrameWidth * 2
X = hCtrl.ScreenX + Style.FrameWidth
Me.Resize(W, (gvwPopup.Font.TextHeight(" ") + 6) * Min(10, $aList.Count) + 2)
WM = gvwPopup.Columns[0].W + 2
If $aList.Count > MAX_ITEMS Then WM += Style.ScrollbarSize
W = Max(W, WM) + 2
H = (gvwPopup.Font.TextHeight(" ") + 6) * Min(MAX_ITEMS, $aList.Count) + 2
Me.Arrangement = Arrange.Fill
W = Min(W, hScreen.AvailableWidth)
Me.Resize(W, H)
If hCtrl.ScreenY + hCtrl.H + H > hScreen.AvailableHeight Then
Y = hCtrl.ScreenY - H
Else
Y = hCtrl.ScreenY + hCtrl.H
Endif
If X + W > hScreen.AvailableWidth Then X = hScreen.AvailableWidth - W
If X < 0 Then X = 0
Try gvwPopup.Row = iIndex

View file

@ -3,7 +3,6 @@
{ Form Form
MoveScaled(0,0,20,25)
Resizable = False
Arrangement = Arrange.Fill
{ gvwPopup GridView
MoveScaled(2,2,16,19)
Mode = Select.Single

View file

@ -1,18 +1,18 @@
# Gambas Form File 3.0
{ Form Form
MoveScaled(0,0,64,64)
MoveScaled(0,0,30,64)
Arrangement = Arrange.Vertical
Spacing = True
Margin = True
{ MyComboBox1 ComboBox
MoveScaled(5,2,21,4)
ReadOnly = True
List = [("Élément 1"), ("Élément 2"), ("Élément 3"), ("Élément 4"), ("Élément 5"), ("Élément 6"), ("Élément 7"), ("Élément 8"), ("Élément 9"), ("Élément 10"), ("Élément 11"), ("Élément 12")]
List = [("Élément 1"), ("Élément 2"), ("Élément 3"), ("Élément 4"), ("Élément 5"), ("Élément 6"), ("Élément 7"), ("Élément 8"), ("Élément 9"), ("Élément 10"), ("Élément 11"), ("Élément 12"), ("Élément plus long que les autres")]
}
{ MyComboBox2 ComboBox
MoveScaled(5,8,24,4)
List = [("Élément 1"), ("Élément 2"), ("Élément 3"), ("Élément 4"), ("Élément 5"), ("Élément 6"), ("Élément 7"), ("Élément 8"), ("Élément 9"), ("Élément 10"), ("Élément 11"), ("Élément 12")]
List = [("Élément 6"), ("Élément 7"), ("Élément 8"), ("Élément 9"), ("Élément 10"), ("Élément 11"), ("Élément 12"), ("Élément plus long que les autres")]
}
{ MyComboBox3 ComboBox
MoveScaled(4,13,24,4)