Skip to content

Commit 531a3e1

Browse files
Merge pull request livecode#2065 from livecode/dg-cont
[[ FasterDG ]] Use container layerMode in form view
2 parents 1106deb + c5e8b24 commit 531a3e1

File tree

3 files changed

+153
-20
lines changed

3 files changed

+153
-20
lines changed

Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript

Lines changed: 132 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,44 @@ private command _Initialize
239239
local theMasterRect
240240
put the rect of me into theMasterRect
241241

242+
## Configure the DG subgroups to enable use of acceleratedRendering
243+
## effectively in form mode.
244+
245+
## The top-level group must be container (this means that no adornment
246+
## props must be set on the top-level group).
247+
set the layerMode of me to "container"
248+
249+
## The dgBackground group holds the backdrop behind the row-templates.
250+
## This can be changed to static when the engine is changed so that
251+
## a control is only redrawn when focused *if* it will change appearance.
252+
set the layerMode of control "dgBackground" of me to "dynamic"
253+
254+
## The dgListMask group holds the scrolling elements; in form view mode
255+
## only the dgList subgroup is relevant. As it holds other subgroups which
256+
## will hold dynamic layers it must be container.
257+
set the layerMode of group "dgListMask" of me to "container"
258+
259+
## The dgList group holds the replicated row template groups. As it holds
260+
## dynamic layer groups it must be container.
261+
set the layerMode of group "dgList" of me to "container"
262+
263+
## The dgHorizontalComponents group holds the horizontal scrollbar and
264+
## corner wedge. Making it dynamic means that it doesn't cause re-rendering
265+
## of static layers above when it changes.
266+
set the layerMode of group "dgHorizontalComponents" of me to "dynamic"
267+
268+
## The dgScrollbar group holds the vertical scrollbar. Making it dynamic
269+
## means that it doesn't cause re-rendering of static layers above when it
270+
## changes.
271+
set the layerMode of scrollbar "dgScrollbar" of me to "dynamic"
272+
273+
## The following groups all relate to table mode. These are all set to
274+
## static for now.
275+
set the layerMode of group "dgAlternatingRowsMask" of me to "static"
276+
set the layerMode of group "dgHighlights" of me to "static"
277+
set the layerMode of group "dgHeaderComponents" of me to "static"
278+
set the layerMode of group "dgDividers" of me to "static"
279+
242280
switch the platform
243281
case "Win32"
244282
if "registryRead" is among the items of the securityPermissions then
@@ -2587,12 +2625,19 @@ private command _DrawListWithProperties pStartingSequence, pSetVScrollTo, pForce
25872625

25882626
## Make sure focus stays with us
25892627
if the long ID of me is in theControl then
2590-
25912628
lock messages
25922629
if there is not a theControl then
2630+
## [[ FocusRedraw ]] Make sure focus is only changed if the target is
2631+
## not already focused.
2632+
if the long id of the focusedObject is not the long id of graphic "dgBackground" of me then
25932633
focus on graphic "dgBackground" of me
2634+
end if
25942635
else
2636+
## [[ FocusRedraw ]] Make sure focus is only changed if the target is
2637+
## not already focused.
2638+
if the long id of the focusedObject is not theControl then
25952639
focus on theControl
2640+
end if
25962641
end if
25972642
unlock messages
25982643
end if
@@ -2964,6 +3009,7 @@ private command _list.FillListWithJustEnoughControls
29643009
repeat with i = theCurrentControlCount + 1 to theRequiredControlCount
29653010
copy theTemplateGroup to group "dgList" of me
29663011
put it into theControl
3012+
set the layerMode of theControl to "dynamic"
29673013
set the name of theControl to the short name of theControl && format("%04d", i)
29683014
put "control id" && word 3 of theControl && "of me" & cr after sTableObjectsA["all row controls"]
29693015

@@ -3096,6 +3142,14 @@ private command _list.DrawControlsInRealTime pForceRefresh, pCallback, pCallback
30963142

30973143
put not controlCountWasModified and sTableObjectsA["current"]["indexes"] is theIndexesInSequence into noRedrawNeeded
30983144
-- put theIndexesInSequence && the milliseconds & cr into msg
3145+
3146+
## [[ DG2Layout ]] If edit mode or enable swipe is enabled or if minimal
3147+
## layout is not enabled then we must still call LayoutControl on each
3148+
## iteration.
3149+
local theMustLayout
3150+
put sEditMode or \
3151+
the dgProps["enable swipe"] of me or \
3152+
not the dgProps["minimal layout"] of me into theMustLayout
30993153

31003154
if not noRedrawNeeded or pForceRefresh then
31013155
put empty into sTableObjectsA["visible row controls"]
@@ -3137,16 +3191,24 @@ private command _list.DrawControlsInRealTime pForceRefresh, pCallback, pCallback
31373191

31383192
## Set row color
31393193
if there is a graphic "Background" of theEffectiveControl then
3194+
## Compute the new row color based on the alternating index
3195+
local theNewRowColor
31403196
if theSequence mod 2 is kAlternatingRowModValue then
3141-
set the backgroundColor of graphic "Background" of theEffectiveControl to theRow2Color
3197+
put theRow2Color into theNewRowColor
31423198
else
3143-
set the backgroundColor of graphic "Background" of theEffectiveControl to theRow1Color
3199+
put theRow1Color into theNewRowColor
3200+
end if
3201+
3202+
## [[ ColorRedraw ]] Only change the backgroundColor of the control
3203+
## if it has changed.
3204+
if the backgroundColor of graphic "Background" of theEffectiveControl is not theNewRowColor then
3205+
set the backgroundColor of graphic "Background" of theEffectiveControl to theNewRowColor
31443206
end if
31453207
end if
31463208

31473209
## If control index is not the index we are working on then
31483210
## Load new data
3149-
local theCurrentIndex
3211+
local theCurrentIndex, theNeedsLayout
31503212
put the dgIndex of theControl into theCurrentIndex
31513213
if theCurrentIndex is not theIndex then
31523214
## Allow developer to do something if unloading control
@@ -3170,32 +3232,56 @@ private command _list.DrawControlsInRealTime pForceRefresh, pCallback, pCallback
31703232
dispatch "FillInData" to theControl with sDataArray[theIndex]
31713233
lock messages
31723234
end if
3235+
3236+
## If data was changed, then the control must layout
3237+
put true into theNeedsLayout
31733238
else
31743239
-- put "not drawing index:" && theIndex & cr after msg
3240+
3241+
## If data has not changed then only layout if DG2 features are
3242+
## active
3243+
put theMustLayout into theNeedsLayout
31753244
end if
31763245

31773246
## Set the rect AFTER filling in data in case filling in data causes the group to resize
31783247
unlock messages
31793248
if pCallback is not empty then
31803249
dispatch pCallback to me with pCallbackContext, theControl, theSequence, theRect, theTopLeft
31813250
end if
3182-
set the topLeft of theControl to item 1 to 2 of theRect ## So developer can always count on topleft of controls in template code
3183-
lock messages
3184-
set the rect of theControl to theRect
3185-
unlock messages
3186-
dispatch "LayoutControl" to theControl with theRect, DG2_GetWorkingRectOfControlFromControlRect(theControl, theRect)
3187-
3188-
## Resize to fit height
3189-
if not controlHeightIsFixed then
3251+
3252+
## Always set the topLeft of the row template - this causes unchanged
3253+
## rows to scroll, and ensure that changed rows controls are where they
3254+
## expect.
3255+
set the topLeft of theControl to item 1 to 2 of theRect
3256+
3257+
## If the width or height of the row template has changed then get the
3258+
## user script to layout it out again.
3259+
if theNeedsLayout or \
3260+
the width of theControl is not (item 3 of theRect - item 1 of theRect) or \
3261+
the height of theControl is not (item 4 of theRect - item 2 of theRect) then
31903262
lock messages
3191-
put item 2 of theRect + the formattedHeight of theControl into item 4 of theRect
31923263
set the rect of theControl to theRect
31933264
unlock messages
3265+
3266+
set the lockUpdates of theControl to true
3267+
dispatch "LayoutControl" to theControl with theRect, DG2_GetWorkingRectOfControlFromControlRect(theControl, theRect)
3268+
set the lockUpdates of theControl to false
3269+
3270+
## Resize to fit height
3271+
if not controlHeightIsFixed then
3272+
lock messages
3273+
put item 2 of theRect + the formattedHeight of theControl into item 4 of theRect
3274+
set the rect of theControl to theRect
3275+
unlock messages
3276+
end if
31943277
end if
31953278

31963279
put the bottom of theControl into item 2 of theTopLeft
31973280

3198-
## Hilited index?
3281+
## [[ HiliteAll ]] Update the hilite of the row template - ideally
3282+
## this would only be done *if* the hilite of the row has changed
3283+
## or the row template has been reused or the data for the row has
3284+
## changed.
31993285
if theIndex is among the items of sHilitedIndexes then
32003286
_HiliteControl theEffectiveControl, true
32013287
else
@@ -3214,7 +3300,7 @@ private command _list.DrawControlsInRealTime pForceRefresh, pCallback, pCallback
32143300
## Filter control list and reset controls that aren't part of visible list
32153301
put line (the number of lines of sTableObjectsA["visible row controls"] + 1) to -1 of theMasterControlList into theMasterControlList
32163302
_ResetControls theMasterControlList
3217-
3303+
32183304
return empty
32193305
end _list.DrawControlsInRealTime
32203306

@@ -3398,6 +3484,7 @@ private command _list.CalculateFormattedHeight
33983484
lock messages
33993485
copy theTemplateGroup to group "dgList" of me
34003486
put it into theControl
3487+
set the layerMode of theControl to "dynamic"
34013488
unlock messages
34023489

34033490
try ## Watch for user errors
@@ -6143,6 +6230,12 @@ setprop dgProps [pProp] pValue
61436230
set the dgProps[pProp] of me to "Data Grid"
61446231
unlock messages
61456232
break
6233+
6234+
case "minimal layout"
6235+
lock messages
6236+
set the dgProps[pProp] of me to pValue is true
6237+
unlock messages
6238+
break
61466239

61476240
default
61486241
throw "invalid property '" & pProp & "'"
@@ -6358,6 +6451,10 @@ getprop dgProps [pProp]
63586451
case "fixed control height" ## early dev versions
63596452
return the dgProps["fixed row height"] of me
63606453
break
6454+
6455+
case "minimal layout"
6456+
return the dgProps["minimal layout"] of me
6457+
break
63616458
end switch
63626459

63636460
pass dgProps
@@ -7683,6 +7780,7 @@ private command _ProcessNewIndexData pIndex
76837780
put "control id" && word 3 of theControl && "of me" into sControlOfIndexA[pIndex]
76847781
set the visible of theControl to false
76857782
set the dgIndex of theControl to pIndex
7783+
set the layerMode of theControl to "dynamic"
76867784
unlock messages
76877785

76887786
put sControlOfIndexA[pIndex] into line (the number of lines of sTableObjectsA["all row controls"] + 1) of sTableObjectsA["all row controls"]
@@ -7735,6 +7833,7 @@ private command _UpdateIndexWithNewData pIndex
77357833
lock messages
77367834
copy theTemplateGroup to group "dgList" of me
77377835
put it into theControl
7836+
set the layerMode of theControl to "dynamic"
77387837
end if
77397838

77407839
## Insert data into control
@@ -8392,6 +8491,7 @@ private command _CacheControls
83928491
copy theTemplateGroup to group "dgList" of me
83938492
put "control id" && word 3 of it && "of me" & cr after sTableObjectsA["all row controls"]
83948493
set the name of it to the short name of it && format("%04d", i)
8494+
set the layerMode of it to "dynamic"
83958495

83968496
## Take over geometry
83978497
set the lockloc of it to true
@@ -8558,21 +8658,29 @@ private command _LayoutCachedControls
85588658
unlock screen
85598659
end _LayoutCachedControls
85608660

8561-
85628661
private command _HiliteControl pControl, pBoolean
8563-
if there is a graphic "Background" of pControl then
8662+
if there is a graphic "Background" of pControl then
8663+
## Compute the new background color based on whether it is hilited and
8664+
## if not hilited, whether alternating colors should be used.
8665+
local tNewBackgroundColor
85648666
if pBoolean then
8565-
set the backgroundColor of graphic "Background" of pControl to _GetHiliteColor()
8667+
put _GetHiliteColor() into tNewBackgroundColor
85668668
else
85678669
set the wholeMatches to true
85688670
local theLine
85698671
put itemOffset(the dgIndex of pControl, sIndexSequencing) into theLine
85708672
if theLine mod 2 is kAlternatingRowModValue then
8571-
set the backgroundColor of graphic "Background" of pControl to _GetEffectiveColor("alternate row color")
8673+
put _GetEffectiveColor("alternate row color") into tNewBackgroundColor
85728674
else
8573-
set the backgroundColor of graphic "Background" of pControl to _GetEffectiveColor("row color")
8675+
put _GetEffectiveColor("row color") into tNewBackgroundColor
85748676
end if
85758677
end if
8678+
8679+
## [[ ColorRedraw ]] Only update the background color if it has actually
8680+
## changed.
8681+
if the backgroundColor of graphic "Background" of pControl is not tNewBackgroundColor then
8682+
set the backgroundColor of graphic "Background" of pControl to tNewBackgroundColor
8683+
end if
85768684
end if
85778685

85788686
local msgsAreLocked
@@ -10827,6 +10935,7 @@ function DG2_CustomisableControlsGetDefaultEditModeReorderControl
1082710935
reset the templateGroup
1082810936
create invisible group "DG2 Default Edit Mode Reorder Control" in _TemplateControl()
1082910937
set the margins of it to kEditModeReorderControlMargins
10938+
set the layerMode of it to "dynamic"
1083010939

1083110940
create widget as "com.livecode.widget.svgpath" in it
1083210941
set the iconPresetName of it to kEditModeReorderControlIcon
@@ -10848,6 +10957,7 @@ function DG2_CustomisableControlsGetDefaultEditModeActionSelectControl
1084810957
reset the templateGroup
1084910958
create invisible group "DG2 Default Edit Mode Action Select Control" in _TemplateControl()
1085010959
set the margins of it to kEditModeActionSelectControlMargins
10960+
set the layerMode of it to "dynamic"
1085110961

1085210962
create widget as "com.livecode.widget.svgpath" in it
1085310963
set the iconPresetName of it to kEditModeActionSelectControlIcon
@@ -10872,6 +10982,7 @@ function DG2_CustomisableControlsGetDefaultEditModeActionControl
1087210982
reset the templateGroup
1087310983
create invisible group "DG2 Default Action Control" in _TemplateControl()
1087410984
set the margins of it to 0
10985+
set the layerMode of it to "dynamic"
1087510986

1087610987
reset the templateButton
1087710988
create button "DG2 Default Action Control" in it
@@ -10903,6 +11014,7 @@ private function DG2_CustomisableControlsGetDefaultSwipeControl pName
1090311014
reset the templateGroup
1090411015
create invisible group pName in _TemplateControl()
1090511016
set the margins of it to 0
11017+
set the layerMode of it to "dynamic"
1090611018
put it into tGroup
1090711019

1090811020
reset the templateGraphic

Toolset/resources/supporting_files/property_definitions/com.livecode.interface.classic.DataGridForm.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cache controls:revIDEGetDataGridProperty:revIDESetDataGridProperty Cache control
1313
persistent data:revIDEGetDataGridProperty:revIDESetDataGridProperty Persistent data Data Grid com.livecode.pi.boolean true false no_default
1414
animate actions:revIDEGetDataGridProperty:revIDESetDataGridProperty Animate actions Data Grid com.livecode.pi.boolean true false true
1515
enable swipe:revIDEGetDataGridProperty:revIDESetDataGridProperty Enable swipes Data Grid com.livecode.pi.boolean true false false
16+
minimal layout:revIDEGetDataGridProperty:revIDESetDataGridProperty Minimal layout Data Grid com.livecode.pi.boolean true false false
1617
fixed control height:revIDEGetDataGridProperty:revIDESetDataGridProperty Fixed row height Data Grid com.livecode.pi.boolean true false no_default
1718
row height:revIDEGetDataGridProperty:revIDESetDataGridProperty Row height Data Grid com.livecode.pi.number true false 21 1
1819
row behavior:revIDEGetDataGridProperty:revIDESetDataGridProperty Row behavior Data Grid com.livecode.pi.script true true no_default 1

notes/feature-faster_dg.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Accelerated DataGrid
2+
3+
The DataGrid has been updated to use the new container layer mode
4+
feature when running in form view mode.
5+
6+
To take advantage of this, the datagrid must be at top-level or
7+
contained withing groups all having container layer mode set. It
8+
must have showBorder set to false, and the acceleratedRendering
9+
property must be enabled on the stack with appropriate compositor
10+
property settings.
11+
12+
To get the maximum benefit from accelerated rendering, the behavior
13+
script for a row template should changing properties within the
14+
template unnecessarily.
15+
16+
A new datagrid property `minimal layout` has been added. When this
17+
property is true, a row template will only receive the `LayoutControl`
18+
message if its data or its width or height has changed as opposed
19+
to every time its rect changes (e.g. due to scrolling).
20+

0 commit comments

Comments
 (0)