@@ -9,11 +9,14 @@ import {
99} from 'react-virtualized' ;
1010import IconButton from '../../UI/IconButton' ;
1111import KeyboardShortcuts from '../../UI/KeyboardShortcuts' ;
12- import GDevelopThemeContext from '../../UI/Theme/GDevelopThemeContext' ;
1312import CompactSearchBar from '../../UI/CompactSearchBar' ;
1413import RemoveCircle from '../../UI/CustomSvgIcons/RemoveCircle' ;
1514import Lock from '../../UI/CustomSvgIcons/Lock' ;
1615import LockOpen from '../../UI/CustomSvgIcons/LockOpen' ;
16+ import RotateZ from '../../UI/CustomSvgIcons/RotateZ' ;
17+ import Layers from '../../UI/CustomSvgIcons/Layers' ;
18+ import SortArrowUp from '../../UI/CustomSvgIcons/SortArrowUp' ;
19+ import SortArrowDown from '../../UI/CustomSvgIcons/SortArrowDown' ;
1720import { toFixedWithoutTrailingZeros } from '../../Utils/Mathematics' ;
1821import ErrorBoundary from '../../UI/ErrorBoundary' ;
1922import useForceUpdate from '../../Utils/UseForceUpdate' ;
@@ -46,11 +49,15 @@ const styles = {
4649 flexDirection : 'column' ,
4750 alignItems : 'stretch' ,
4851 minWidth : 0 ,
52+ // Search-bar band: matches the column-header band, kept distinct from the
53+ // alternating row colors so it stays stable when the rows change.
54+ backgroundColor : 'var(--table-header-background-color)' ,
4955 } ,
5056 tableContainer : {
5157 flex : 1 ,
5258 overflowX : 'auto' ,
5359 overflowY : 'hidden' ,
60+ backgroundColor : 'var(--table-header-background-color)' ,
5461 } ,
5562} ;
5663
@@ -63,6 +70,40 @@ const compareStrings = (x: string, y: string, direction: number): number => {
6370 return 0 ;
6471} ;
6572
73+ const renderSortableHeader = ( {
74+ dataKey,
75+ label,
76+ sortBy,
77+ sortDirection,
78+ } : {
79+ dataKey : string ,
80+ label : React . Node ,
81+ sortBy : string ,
82+ sortDirection : string ,
83+ } ) => {
84+ const isActive = dataKey === sortBy ;
85+ return (
86+ < span
87+ style = { {
88+ color : isActive
89+ ? 'var(--theme-text-default-color)'
90+ : 'var(--table-text-color-header)' ,
91+ display : 'flex' ,
92+ alignItems : 'center' ,
93+ gap : 4 ,
94+ } }
95+ >
96+ { label }
97+ { isActive &&
98+ ( sortDirection === 'ASC' ? (
99+ < SortArrowUp style = { { width : 12 , height : 12 , display : 'block' } } />
100+ ) : (
101+ < SortArrowDown style = { { width : 12 , height : 12 , display : 'block' } } />
102+ ) ) }
103+ </ span >
104+ ) ;
105+ } ;
106+
66107export type InstancesListInterface = { |
67108 forceUpdate : ( ) => void ,
68109| } ;
@@ -85,8 +126,8 @@ class InstancesList extends Component<Props, State> {
85126 // $FlowFixMe[missing-local-annot]
86127 state = {
87128 searchText : '' ,
88- sortBy : '' ,
89- sortDirection : SortDirection . ASC ,
129+ sortBy : 'zOrder ' ,
130+ sortDirection : SortDirection . DESC ,
90131 } ;
91132 renderedRows : Array < RenderedRowInfo > = [ ] ;
92133 instanceRowRenderer : ?typeof gd . InitialInstanceJSFunctor ;
@@ -118,7 +159,7 @@ class InstancesList extends Component<Props, State> {
118159 y : toFixedWithoutTrailingZeros ( instance . getY ( ) , 2 ) ,
119160 angle : toFixedWithoutTrailingZeros ( instance . getAngle ( ) , 2 ) ,
120161 layer : instance . getLayer ( ) ,
121- zOrder : instance . getZOrder ( ) ,
162+ zOrder : String ( instance . getZOrder ( ) ) ,
122163 } ) ;
123164 }
124165 } ;
@@ -250,112 +291,112 @@ class InstancesList extends Component<Props, State> {
250291 const tableKey = instances . ptr ;
251292
252293 return (
253- < GDevelopThemeContext . Consumer >
254- { gdevelopTheme => (
255- < div style = { styles . container } >
256- < Line >
257- < Column expand noOverflowParent >
258- < CompactSearchBar
259- value = { searchText }
260- onChange = { searchText =>
261- this . setState ( {
262- searchText,
263- } )
264- }
265- onRequestSearch = { this . _selectFirstInstance }
266- placeholder = { t `Search instances` }
294+ < div style = { styles . container } >
295+ < Line >
296+ < Column expand noOverflowParent >
297+ < CompactSearchBar
298+ value = { searchText }
299+ onChange = { searchText =>
300+ this . setState ( {
301+ searchText,
302+ } )
303+ }
304+ onRequestSearch = { this . _selectFirstInstance }
305+ placeholder = { t `Search instances` }
306+ />
307+ </ Column >
308+ </ Line >
309+ < div
310+ style = { styles . tableContainer }
311+ onKeyDown = { this . _keyboardShortcuts . onKeyDown }
312+ onKeyUp = { this . _keyboardShortcuts . onKeyUp }
313+ >
314+ < AutoSizer >
315+ { ( { height, width } ) => (
316+ < RVTable
317+ ref = { table => ( this . table = table ) }
318+ key = { tableKey }
319+ headerHeight = { 30 }
320+ height = { height }
321+ className = { `gd-table` }
322+ headerClassName = { 'tableHeaderColumn' }
323+ headerStyle = { {
324+ backgroundColor : 'var(--table-header-background-color)' ,
325+ } }
326+ rowCount = { this . renderedRows . length }
327+ rowGetter = { this . _rowGetter }
328+ rowHeight = { 32 }
329+ onRowClick = { this . _onRowClick }
330+ rowClassName = { this . _rowClassName }
331+ sort = { this . _sort }
332+ sortBy = { sortBy }
333+ sortDirection = { sortDirection }
334+ width = { Math . max ( width , minimumWidths . table ) }
335+ >
336+ < RVColumn
337+ label = { < Trans > Object name</ Trans > }
338+ dataKey = "name"
339+ width = { Math . max ( width * 0.35 , minimumWidths . objectName ) }
340+ className = { 'tableColumn' }
341+ headerRenderer = { renderSortableHeader }
267342 />
268- </ Column >
269- </ Line >
270- < div
271- style = { styles . tableContainer }
272- onKeyDown = { this . _keyboardShortcuts . onKeyDown }
273- onKeyUp = { this . _keyboardShortcuts . onKeyUp }
274- >
275- < AutoSizer >
276- { ( { height, width } ) => (
277- < RVTable
278- ref = { table => ( this . table = table ) }
279- key = { tableKey }
280- headerHeight = { 30 }
281- height = { height }
282- className = { `gd-table` }
283- headerClassName = { 'tableHeaderColumn' }
284- rowCount = { this . renderedRows . length }
285- rowGetter = { this . _rowGetter }
286- rowHeight = { 32 }
287- onRowClick = { this . _onRowClick }
288- rowClassName = { this . _rowClassName }
289- sort = { this . _sort }
290- sortBy = { sortBy }
291- sortDirection = { sortDirection }
292- width = { Math . max ( width , minimumWidths . table ) }
293- >
294- < RVColumn
295- label = { < Trans > Object name</ Trans > }
296- dataKey = "name"
297- width = { Math . max ( width * 0.35 , minimumWidths . objectName ) }
298- className = { 'tableColumn' }
299- />
300- < RVColumn
301- label = ""
302- dataKey = "locked"
303- width = { Math . max (
304- width * 0.05 ,
305- minimumWidths . numberProperty
306- ) }
307- className = { 'tableColumn' }
308- cellRenderer = { this . _renderLockCell }
309- />
310- < RVColumn
311- label = { < Trans > X</ Trans > }
312- dataKey = "x"
313- width = { Math . max (
314- width * 0.1 ,
315- minimumWidths . numberProperty
316- ) }
317- className = { 'tableColumn' }
318- />
319- < RVColumn
320- label = { < Trans > Y</ Trans > }
321- dataKey = "y"
322- width = { Math . max (
323- width * 0.1 ,
324- minimumWidths . numberProperty
325- ) }
326- className = { 'tableColumn' }
327- />
328- < RVColumn
329- label = { < Trans > Angle</ Trans > }
330- dataKey = "angle"
331- width = { Math . max (
332- width * 0.1 ,
333- minimumWidths . numberProperty
334- ) }
335- className = { 'tableColumn' }
336- />
337- < RVColumn
338- label = { < Trans > Layer</ Trans > }
339- dataKey = "layer"
340- width = { Math . max ( width * 0.2 , minimumWidths . layerName ) }
341- className = { 'tableColumn' }
343+ < RVColumn
344+ label = { < Trans > X</ Trans > }
345+ dataKey = "x"
346+ width = { Math . max ( width * 0.1 , minimumWidths . numberProperty ) }
347+ className = { 'tableColumn tableColumnSecondary' }
348+ headerRenderer = { renderSortableHeader }
349+ />
350+ < RVColumn
351+ label = { < Trans > Y</ Trans > }
352+ dataKey = "y"
353+ width = { Math . max ( width * 0.1 , minimumWidths . numberProperty ) }
354+ className = { 'tableColumn tableColumnSecondary' }
355+ headerRenderer = { renderSortableHeader }
356+ />
357+ < RVColumn
358+ label = { < Trans > Z</ Trans > }
359+ dataKey = "zOrder"
360+ width = { Math . max ( width * 0.1 , minimumWidths . numberProperty ) }
361+ className = { 'tableColumn tableColumnSecondary' }
362+ headerRenderer = { renderSortableHeader }
363+ />
364+ < RVColumn
365+ label = {
366+ < RotateZ
367+ titleAccess = "Rotation (Z)"
368+ style = { { width : 18 , height : 18 , display : 'block' } }
342369 />
343- < RVColumn
344- label = { < Trans > Z Order</ Trans > }
345- dataKey = "zOrder"
346- width = { Math . max (
347- width * 0.1 ,
348- minimumWidths . numberProperty
349- ) }
350- className = { 'tableColumn' }
370+ }
371+ dataKey = "angle"
372+ width = { Math . max ( width * 0.1 , minimumWidths . numberProperty ) }
373+ className = { 'tableColumn tableColumnSecondary' }
374+ headerRenderer = { renderSortableHeader }
375+ />
376+ < RVColumn
377+ label = {
378+ < Layers
379+ titleAccess = "Layer"
380+ style = { { width : 18 , height : 18 , display : 'block' } }
351381 />
352- </ RVTable >
353- ) }
354- </ AutoSizer >
355- </ div >
356- </ div >
357- ) }
358- </ GDevelopThemeContext . Consumer >
382+ }
383+ dataKey = "layer"
384+ width = { Math . max ( width * 0.2 , minimumWidths . layerName ) }
385+ className = { 'tableColumn tableColumnSecondary' }
386+ headerRenderer = { renderSortableHeader }
387+ />
388+ < RVColumn
389+ label = ""
390+ dataKey = "locked"
391+ width = { Math . max ( width * 0.05 , minimumWidths . numberProperty ) }
392+ className = { 'tableColumn' }
393+ cellRenderer = { this . _renderLockCell }
394+ />
395+ </ RVTable >
396+ ) }
397+ </ AutoSizer >
398+ </ div >
399+ </ div >
359400 ) ;
360401 }
361402}
0 commit comments