Skip to content

Commit 5485521

Browse files
committed
ToListSelectionElement skins
1 parent 15a82de commit 5485521

15 files changed

+243
-213
lines changed

src/Toplo-Widget-List/ToInfiniteElement.class.st

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ ToInfiniteElement >> initialize [
183183

184184
self class initializeSlots: self.
185185
super initialize.
186+
self skinStateGeneratorClass ifNotNil: [ :cls |
187+
self addEventHandler: cls new ].
186188
selectionStrategy := self defaultSelectionStrategy.
187189
self privateData: ToObservableCollection new.
188190

@@ -322,17 +324,6 @@ ToInfiniteElement >> offsetPositionRecordsForRemove: aStartPosition itemCount: a
322324
to: self ]
323325
]
324326

325-
{ #category : 'private - focus' }
326-
ToInfiniteElement >> onGotFocus [
327-
328-
329-
]
330-
331-
{ #category : 'private - focus' }
332-
ToInfiniteElement >> onLostFocus [
333-
334-
]
335-
336327
{ #category : 'accessing' }
337328
ToInfiniteElement >> preserveSelectionOnFocused [
338329

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Class {
22
#name : 'ToListContextMenuSelectionElement',
33
#superclass : 'ToListSelectionElement',
4+
#instVars : [
5+
'inner'
6+
],
47
#category : 'Toplo-Widget-List-core',
58
#package : 'Toplo-Widget-List',
69
#tag : 'core'
@@ -9,15 +12,22 @@ Class {
912
{ #category : 'initialization' }
1013
ToListContextMenuSelectionElement >> initialize [
1114

12-
| inner |
1315
super initialize.
14-
self outskirts: BlOutskirts outside.
1516
inner := ToElement new
1617
id: #inner;
1718
yourself.
1819
inner matchParent.
19-
inner layout: BlFrameLayout new.
20-
inner geometry: self defaultGeometry.
21-
inner border: (BlBorder paint: Color white width: 2).
2220
self addChild: inner
2321
]
22+
23+
{ #category : 'accessing' }
24+
ToListContextMenuSelectionElement >> inner [
25+
26+
^ inner
27+
]
28+
29+
{ #category : 'skin' }
30+
ToListContextMenuSelectionElement >> newRawSkin [
31+
32+
^ ToListContextMenuSelectionElementSkin new
33+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Class {
2+
#name : 'ToListContextMenuSelectionElementSkin',
3+
#superclass : 'ToRawSkin',
4+
#category : 'Toplo-Widget-List-core',
5+
#package : 'Toplo-Widget-List',
6+
#tag : 'core'
7+
}
8+
9+
{ #category : 'event handling' }
10+
ToListContextMenuSelectionElementSkin >> installLookEvent: anEvent [
11+
12+
super installLookEvent: anEvent.
13+
anEvent elementDo: [ :e |
14+
e geometry:
15+
((e tokenValueNamed: #'primary-selection-geometry-class')
16+
cornerRadius: (e tokenValueNamed: #'border-radius-SM')).
17+
e inner geometry:
18+
((e tokenValueNamed: #'primary-selection-geometry-class')
19+
cornerRadius: (e tokenValueNamed: #'border-radius-SM')).
20+
e inner border: (BlBorder paint: Color white width: 2).
21+
e border: (BlBorder
22+
paint: (e tokenValueNamed: #'border-color-primary-selection')
23+
width: (e tokenValueNamed: #'border-width-primary-selection')).
24+
e padding: (BlInsets
25+
horizontal: (e tokenValueNamed: #'list-padding-H')
26+
vertical: (e tokenValueNamed: #'list-padding-V')) ]
27+
]

src/Toplo-Widget-List/ToListElement.class.st

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,12 @@ ToListElement >> dataSourceSharedEvents [
3737
ToDataFilterRequest }
3838
]
3939

40-
{ #category : 'initialization' }
41-
ToListElement >> defaultBackground [
42-
43-
^ BlBackground paint: Color white
44-
]
45-
4640
{ #category : 'initialization' }
4741
ToListElement >> defaultLayout [
4842

4943
^ BlFrameLayout new
5044
]
5145

52-
{ #category : 'initialization' }
53-
ToListElement >> defaultMargin [
54-
55-
^ BlInsets all: 0
56-
]
57-
58-
{ #category : 'initialization' }
59-
ToListElement >> defaultPadding [
60-
61-
" Must be 1 to see the focus frame AND to draw selection decoration correctly (not outside infinite bounds) "
62-
^ BlInsets all: 1
63-
64-
]
65-
6646
{ #category : 'orientation' }
6747
ToListElement >> horizontal: aBoolean [
6848

@@ -89,7 +69,7 @@ ToListElement >> initialize [
8969

9070
self layout: self defaultLayout.
9171
self next: ToListInfiniteElement new.
92-
self next padding: (BlInsets top: 1 left: 4 bottom: 1 right: 4).
72+
9373
self addEventHandler: ToListElementEventHandler new.
9474

9575
"Also installs shared event distributors between the list element,
@@ -109,11 +89,7 @@ ToListElement >> initialize [
10989
self addChild: self next.
11090
self infinite elevation: (BlRelativeElevation elevation: 10).
11191

112-
self matchParent.
113-
self background: self defaultBackground.
114-
self margin: self defaultMargin.
115-
self padding: self defaultPadding.
116-
92+
self matchParent
11793
]
11894

11995
{ #category : 'orientation' }
@@ -128,6 +104,12 @@ ToListElement >> isVertical [
128104
^ self infinite layout isVertical
129105
]
130106

107+
{ #category : 'skin' }
108+
ToListElement >> newRawSkin [
109+
110+
^ ToListElementSkin new
111+
]
112+
131113
{ #category : 't - element with placeholder' }
132114
ToListElement >> placeholderElevation [
133115

src/Toplo-Widget-List/ToListElementContextMenuSelectionEventHandler.class.st

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,19 @@ ToListElementContextMenuSelectionEventHandler >> listElementContextMenuRequest:
104104
{ #category : 'element handlers' }
105105
ToListElementContextMenuSelectionEventHandler >> listElementContextMenuSelectionChangedEvent: anEvent [
106106

107-
| node target |
107+
| node target pos targetChildren infinite childNode |
108108
target := anEvent currentTarget.
109109
anEvent selectedIndexes ifEmpty: [
110110
self removeContextMenuSelectionIn: target.
111111
^ self ].
112-
node := target nodeAt: anEvent selectedIndexes first.
113-
node holder isSelected
112+
pos := target globalPointToLocal: anEvent sourceEvent position.
113+
targetChildren := (target infinite withAllChildrenAt: pos) allButLast.
114+
targetChildren ifEmpty: [ ^ self ].
115+
childNode := targetChildren last.
116+
childNode holder isSelected
114117
ifTrue: [ self contextMenuSelectionOverPrimaryIn: target ]
115118
ifFalse: [
116-
self addContextMenuSelectionIn: target onNode: node ]
119+
self addContextMenuSelectionIn: target onNode: childNode ]
117120
]
118121

119122
{ #category : 'element handlers' }

src/Toplo-Widget-List/ToListElementSelectionEventHandler.class.st

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ ToListElementSelectionEventHandler >> adjacentSelectedNodesGroupsIn: aListElemen
2626
{ #category : 'element handlers' }
2727
ToListElementSelectionEventHandler >> blurEvent: anEvent [
2828

29-
(self selectionElementsIn: anEvent currentTarget) do: [ :d | d blurEvent: anEvent ]
29+
(self selectionElementsIn: anEvent currentTarget) do: [ :d |
30+
d focused: false.
31+
d dispatchEvent: (anEvent copy consumed: false) ]
3032
]
3133

3234
{ #category : 'element handlers' }
@@ -49,13 +51,16 @@ ToListElementSelectionEventHandler >> eventsToHandle [
4951
BlBlurEvent.
5052
BlElementExtentChangedEvent.
5153
BlElementScrolledEvent.
52-
ToListElementSelectionChangedEvent }
54+
ToListElementSelectionChangedEvent.
55+
ToListSelectionElementUpdatedEvent }
5356
]
5457

5558
{ #category : 'element handlers' }
5659
ToListElementSelectionEventHandler >> focusEvent: anEvent [
5760

58-
(self selectionElementsIn: anEvent currentTarget) do: [ :d | d focusEvent: anEvent ]
61+
(self selectionElementsIn: anEvent currentTarget) do: [ :d |
62+
d focused: true.
63+
d dispatchEvent: (anEvent copy consumed: false) ]
5964
]
6065

6166
{ #category : 'element handlers' }
@@ -64,6 +69,20 @@ ToListElementSelectionEventHandler >> listElementSelectionChangedEvent: anEvent
6469
self updatePrimarySelectionFromEvent: anEvent
6570
]
6671

72+
{ #category : 'element handlers' }
73+
ToListElementSelectionEventHandler >> listSelectionElementUpdatedEvent: anEvent [
74+
75+
| target focusEventClass |
76+
target := anEvent currentTarget.
77+
focusEventClass := target infinite isFocused
78+
ifTrue: [ BlFocusEvent ]
79+
ifFalse: [ BlBlurEvent ].
80+
(self selectionElementsIn: target) do: [ :d |
81+
d focused: target infinite isFocused.
82+
d dispatchEvent: (focusEventClass new
83+
yourself) ]
84+
]
85+
6786
{ #category : 'selection managing' }
6887
ToListElementSelectionEventHandler >> newPrimarySelectionFromEvent: anEvent [
6988
" return a collection with instances of ListSelectionDecorationElement "
@@ -93,8 +112,17 @@ ToListElementSelectionEventHandler >> selectionElementsIn: aListElement [
93112
ToListElementSelectionEventHandler >> updatePrimarySelectionFromEvent: anEvent [
94113
"add a ListDecorationElement for each group of adjacent selected nodes "
95114

96-
(self selectionElementsIn: anEvent currentTarget) do: [ :d | d removeFromParent ].
97-
anEvent currentTarget addChildren: (self newPrimarySelectionFromEvent: anEvent).
98-
anEvent currentTarget dispatchEvent: ToListSelectionElementUpdatedEvent new
99-
115+
| prevSelection newSelection background |
116+
prevSelection := self selectionElementsIn: anEvent currentTarget.
117+
prevSelection do: [ :d | d removeFromParent ].
118+
newSelection := self newPrimarySelectionFromEvent: anEvent.
119+
" optimization: because selection element can be added/removed very intensively
120+
one have to anticipate its background to avoid a disturbing flash effect due to
121+
separate styling phases "
122+
anEvent currentTarget installedSkin ifNotNil: [
123+
background := anEvent currentTarget tokenValueNamed: #'color-primary-selection-focused'.
124+
newSelection do: [ :sel | sel background: background ] ].
125+
anEvent currentTarget addChildren: newSelection.
126+
anEvent currentTarget dispatchEvent:
127+
ToListSelectionElementUpdatedEvent new
100128
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Class {
2+
#name : 'ToListElementSkin',
3+
#superclass : 'ToRawSkin',
4+
#category : 'Toplo-Widget-List-core',
5+
#package : 'Toplo-Widget-List',
6+
#tag : 'core'
7+
}
8+
9+
{ #category : 'event handling' }
10+
ToListElementSkin >> installLookEvent: anEvent [
11+
12+
super installLookEvent: anEvent.
13+
anEvent elementDo: [ :e |
14+
e outskirts: BlOutskirts outside.
15+
e border: (e tokenValueNamed: #'color-border').
16+
e background: (e tokenValueNamed: #'color-bg-container').
17+
e padding: (BlInsets
18+
horizontal: (e tokenValueNamed: #'list-padding-H')
19+
vertical: (e tokenValueNamed: #'list-padding-V')) ]
20+
]

src/Toplo-Widget-List/ToListInfiniteElement.class.st

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,6 @@ Class {
66
#tag : 'infinite'
77
}
88

9-
{ #category : 'initialization' }
10-
ToListInfiniteElement >> defaultBackground [
11-
12-
^ Color transparent
13-
]
14-
15-
{ #category : 'initialization' }
16-
ToListInfiniteElement >> defaultBlurBorder [
17-
18-
^ BlBorder
19-
paint: self defaultBorderColor
20-
width: self defaultBorderWidth
21-
]
22-
23-
{ #category : 'initialization' }
24-
ToListInfiniteElement >> defaultBorderColor [
25-
26-
^ self theme editor borderColor
27-
]
28-
29-
{ #category : 'initialization' }
30-
ToListInfiniteElement >> defaultBorderWidth [
31-
32-
^ 1
33-
]
34-
359
{ #category : 'initialization' }
3610
ToListInfiniteElement >> defaultDataSource [
3711

@@ -44,38 +18,12 @@ ToListInfiniteElement >> defaultEventHandler [
4418
^ ToListInfiniteElementEventHandler new
4519
]
4620

47-
{ #category : 'initialization' }
48-
ToListInfiniteElement >> defaultFocusBorder [
49-
50-
^ BlBorder
51-
paint: self defaultFocusBorderColor
52-
width: self defaultBorderWidth
53-
]
54-
55-
{ #category : 'initialization' }
56-
ToListInfiniteElement >> defaultFocusBorderColor [
57-
58-
^ self theme editor focusedBorderColor
59-
]
60-
6121
{ #category : 'initialization' }
6222
ToListInfiniteElement >> defaultListNodeFactory [
6323

6424
^ [ :node :holder | node addChild: ((ToLabel text: holder data asString) hMatchParent) ]
6525
]
6626

67-
{ #category : 'initialization' }
68-
ToListInfiniteElement >> defaultMargin [
69-
70-
^ BlInsets empty
71-
]
72-
73-
{ #category : 'initialization' }
74-
ToListInfiniteElement >> defaultPadding [
75-
76-
^ BlInsets empty
77-
]
78-
7927
{ #category : 'initialization' }
8028
ToListInfiniteElement >> holderClass [
8129

@@ -86,11 +34,11 @@ ToListInfiniteElement >> holderClass [
8634
ToListInfiniteElement >> initialize [
8735

8836
super initialize.
89-
self outskirts: BlOutskirts outside.
90-
self padding: self defaultPadding.
91-
self margin: self defaultMargin.
92-
self clipChildren: true.
93-
self border: self defaultBorder.
94-
self background: self defaultBackground.
9537
self addEventHandler: self defaultEventHandler
9638
]
39+
40+
{ #category : 'skin' }
41+
ToListInfiniteElement >> newRawSkin [
42+
43+
^ ToListInfiniteElementSkin new
44+
]

0 commit comments

Comments
 (0)