From 971747a31b0aba98981adc96f2ae2ae948849eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 27 May 2022 15:48:24 +0200 Subject: [PATCH] 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. --- .../gb.gui.base/.src/ComboBox/ComboBox.class | 2 +- .../.src/ComboBox/FComboBoxPopup.class | 40 ++++++++++++++++--- .../.src/ComboBox/FComboBoxPopup.form | 1 - .../gb.gui.base/.src/Test/FTestMyCombo.form | 6 +-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/comp/src/gb.gui.base/.src/ComboBox/ComboBox.class b/comp/src/gb.gui.base/.src/ComboBox/ComboBox.class index 22be10730..2f2f65ec4 100644 --- a/comp/src/gb.gui.base/.src/ComboBox/ComboBox.class +++ b/comp/src/gb.gui.base/.src/ComboBox/ComboBox.class @@ -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 diff --git a/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.class b/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.class index d9c03cf63..e8b6f0b6a 100644 --- a/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.class +++ b/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.class @@ -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 diff --git a/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.form b/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.form index 5fbee1135..ded11d646 100644 --- a/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.form +++ b/comp/src/gb.gui.base/.src/ComboBox/FComboBoxPopup.form @@ -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 diff --git a/comp/src/gb.gui.base/.src/Test/FTestMyCombo.form b/comp/src/gb.gui.base/.src/Test/FTestMyCombo.form index b063aa78b..467aea3fc 100644 --- a/comp/src/gb.gui.base/.src/Test/FTestMyCombo.form +++ b/comp/src/gb.gui.base/.src/Test/FTestMyCombo.form @@ -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)