IconView: Use an internal cache to speed up item text formatting.
[GB.GUI.BASE] * OPT: IconView: Use an internal cache to speed up item text formatting.
This commit is contained in:
parent
d9aa4e194c
commit
4331940e9e
5 changed files with 46 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
# Gambas Project File 3.0
|
||||
Title=Common controls and classes for GUI components
|
||||
Startup=FLabel
|
||||
Startup=FTestIconView
|
||||
Icon=.hidden/window.png
|
||||
Version=3.16.90
|
||||
VersionFile=1
|
||||
|
@ -8,7 +8,7 @@ Component=gb.image
|
|||
Component=gb.gui
|
||||
Component=gb.settings
|
||||
Arguments=[["-style=oxygen"],["-style=qtcurve"]]
|
||||
Environment="GB_JIT_DEBUG=1\nGB_GUI=gb.gtk3\nLIBOVERLAY_SCROLLBAR=0\n GTK_DEBUG=interactive"
|
||||
Environment="GB_JIT_DEBUG=1\nGB_GUI=gb.qt5\nLIBOVERLAY_SCROLLBAR=0\n GTK_DEBUG=interactive"
|
||||
TabSize=2
|
||||
Translate=1
|
||||
Language=en
|
||||
|
|
|
@ -107,6 +107,8 @@ Private $fFindTime As Float
|
|||
Private $iLock As Integer
|
||||
Private $hArrangeTimer As Timer
|
||||
|
||||
Private $cTrimTextCache As New Collection
|
||||
|
||||
Public Sub _new()
|
||||
|
||||
$hView = New ScrollArea(Me) As "ScrollArea"
|
||||
|
@ -534,6 +536,8 @@ Public Sub ScrollArea_Arrange()
|
|||
Dim W, H As Integer
|
||||
Dim nRow As Integer
|
||||
Dim DS As Integer
|
||||
Dim iOldGridHeight As Integer
|
||||
Dim iOldGridWidth As Integer
|
||||
|
||||
If $iLock Then Return
|
||||
|
||||
|
@ -550,6 +554,9 @@ Public Sub ScrollArea_Arrange()
|
|||
|
||||
ExitRename
|
||||
|
||||
iOldGridHeight = $iGridHeight
|
||||
iOldGridWidth = $iGridWidth
|
||||
|
||||
If $bHorizontal Then
|
||||
|
||||
$iGridHeight = Max(DS, $iIconSize) + DS * 2
|
||||
|
@ -594,6 +601,8 @@ Public Sub ScrollArea_Arrange()
|
|||
|
||||
Endif
|
||||
|
||||
If iOldGridWidth <> $iGridWidth Or If iOldGridHeight <> $iGridHeight Then $cTrimTextCache.Clear
|
||||
|
||||
End
|
||||
|
||||
Public Sub ScrollArea_Resize()
|
||||
|
@ -1620,6 +1629,8 @@ Public Sub ScrollArea_Font()
|
|||
|
||||
Dim hItem As _IconView_Item
|
||||
|
||||
$cTrimTextCache.Clear
|
||||
|
||||
For Each hItem In $aItems
|
||||
hItem._Invalidate
|
||||
Next
|
||||
|
@ -1628,6 +1639,12 @@ Public Sub ScrollArea_Font()
|
|||
|
||||
End
|
||||
|
||||
Public Sub _GetTrimTextCache() As Collection
|
||||
|
||||
Return $cTrimTextCache
|
||||
|
||||
End
|
||||
|
||||
Private Function Keys_Read() As String[]
|
||||
|
||||
Dim aKeys As New String[]
|
||||
|
|
|
@ -357,7 +357,7 @@ Public Sub _Draw(hRect As Rect, hClip As Rect, hIconView As IconView, bHorizonta
|
|||
HT = hRect.H + DS \ 2
|
||||
|
||||
If H > HT Then
|
||||
sText = Paint.TrimRichText(sText, W, HT)
|
||||
sText = MyTrimRichText(sText, W, HT)
|
||||
$bEllipsized = True
|
||||
Else
|
||||
$bEllipsized = False
|
||||
|
@ -413,7 +413,7 @@ Public Sub _Draw(hRect As Rect, hClip As Rect, hIconView As IconView, bHorizonta
|
|||
HT = hRect.H - (Y - hRect.Y)
|
||||
|
||||
If H > HT Then
|
||||
sText = Paint.TrimRichText(sText, hRect.W, HT)
|
||||
sText = MyTrimRichText(sText, hRect.W, HT)
|
||||
$bEllipsized = True
|
||||
Else
|
||||
$bEllipsized = False
|
||||
|
@ -794,3 +794,26 @@ Private Sub Tag_Write(Value As Variant)
|
|||
$vTag = Value
|
||||
|
||||
End
|
||||
|
||||
Private Sub MyTrimRichText(RichText As String, W As Float, Optional H As Float) As String
|
||||
|
||||
Dim sResult As String
|
||||
Dim cCache As Collection
|
||||
|
||||
cCache = GetIconView()._GetTrimTextCache()
|
||||
sResult = cCache[RichText]
|
||||
If Not sResult Then
|
||||
sResult = Paint.TrimRichText(RichText, W, H)
|
||||
cCache[RichText] = sResult
|
||||
If cCache.Count > 256 Then
|
||||
For Each cCache
|
||||
cCache.Remove(cCache.Key)
|
||||
Break
|
||||
Next
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return sResult
|
||||
|
||||
End
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ Static Public Sub TrimRichText(RichText As String, W As Float, Optional H As Flo
|
|||
If bMarkup Then Continue
|
||||
sPrevLeft = sLeft
|
||||
sLeft = HtmlLeft(RichText, I)
|
||||
If Paint.Font.RichTextHeight(sLeft, W) > H Then Break
|
||||
If Paint.Font.RichTextHeight(AddThreeDots(sLeft), W) > H Then Break
|
||||
Next
|
||||
|
||||
If I = 1 Then Return
|
||||
|
|
|
@ -25,5 +25,6 @@
|
|||
Sorted = True
|
||||
Editable = True
|
||||
GridSize = 24
|
||||
IconLines = 3
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue