Skip to content

Commit f68c63f

Browse files
committed
fixture: buttons now resizable. example works. needs adjsutments on behaviour
1 parent 7117b01 commit f68c63f

5 files changed

Lines changed: 264 additions & 187 deletions

File tree

CoypuIDE/ICButton.class.st

Lines changed: 116 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ Class {
55
#name : 'ICButton',
66
#superclass : 'BlElement',
77
#instVars : [
8-
'widgetSize',
98
'button',
10-
'isOn',
11-
'currentValue',
12-
'callbackDown',
13-
'callBackUp',
9+
'buttonEventHandlers',
1410
'callback',
11+
'currentValue',
12+
'fitsContent',
13+
'id',
14+
'inputLabel',
15+
'inputText',
1516
'isToggleable',
16-
'onColor',
1717
'offColor',
18-
'id',
19-
'fitsContent',
20-
'buttonEventHandlers'
18+
'onColor',
19+
'widgetSize'
2120
],
2221
#category : 'CoypuIDE-button',
2322
#package : 'CoypuIDE',
@@ -63,6 +62,41 @@ container openInSpace.
6362

6463
]
6564

65+
{ #category : 'as yet unclassified' }
66+
ICButton class >> exampleFamilyAtThreeSizes [
67+
<script>
68+
| container |
69+
container := BlElement new
70+
layout: (BlGridLayout new
71+
columnCount: 3;
72+
cellSpacing: 20;
73+
yourself);
74+
padding: (BlInsets all: 20);
75+
background: Color veryVeryDarkGray;
76+
constraintsDo: [ :c |
77+
c horizontal fitContent.
78+
c vertical fitContent ];
79+
yourself.
80+
81+
#( 40 80 160 ) do: [ :each |
82+
container addChild: (ICIndicatorButton new widgetSize: each) ].
83+
#( 40 80 160 ) do: [ :each |
84+
container addChild: (ICOnOffButton new widgetSize: each) ].
85+
#( 40 80 160 ) do: [ :each |
86+
container addChild: (ICLabelButton new
87+
inputText: 'MONO';
88+
widgetSize: each;
89+
yourself) ].
90+
#( 40 80 160 ) do: [ :each |
91+
container addChild: (ICCheckBox new
92+
inputText: 'SYNC';
93+
widgetSize: each;
94+
yourself) ].
95+
96+
container openInSpace
97+
98+
]
99+
66100
{ #category : 'api - events' }
67101
ICButton >> addButtonEventHandler: aHandler [
68102
self buttonEventHandlers add: aHandler.
@@ -74,8 +108,13 @@ ICButton >> applyButtonSize [
74108
"Everything my button wears that depends on size. Subclasses add corner
75109
radius, border, shadow and label size by overriding me and sending super."
76110

77-
button size: self buttonSize
111+
button extent: self buttonSize
112+
]
78113

114+
{ #category : 'size' }
115+
ICButton >> applyLabelSize [
116+
inputLabel ifNotNil: [
117+
inputLabel text: (self labelText: self labelString) ]
79118
]
80119

81120
{ #category : 'size' }
@@ -143,18 +182,6 @@ ICButton >> buttonSize [
143182
^ widgetSize - (self sizeUnit * self buttonInsetRatio) asPoint
144183
]
145184

146-
{ #category : 'accessing' }
147-
ICButton >> callBackUp [
148-
149-
^ callBackUp
150-
]
151-
152-
{ #category : 'accessing' }
153-
ICButton >> callBackUp: aBlock [
154-
155-
callBackUp := aBlock
156-
]
157-
158185
{ #category : 'accessing' }
159186
ICButton >> callback [
160187

@@ -167,18 +194,6 @@ ICButton >> callback: aBlock [
167194
callback := aBlock
168195
]
169196

170-
{ #category : 'accessing' }
171-
ICButton >> callbackDown [
172-
173-
^ callbackDown
174-
]
175-
176-
{ #category : 'accessing' }
177-
ICButton >> callbackDown: aBlock [
178-
179-
callbackDown := aBlock
180-
]
181-
182197
{ #category : 'size' }
183198
ICButton >> cornerRadius [
184199
^ self sizeUnit * self cornerRadiusRatio
@@ -268,6 +283,21 @@ ICButton >> fontSizeRatio [
268283

269284
]
270285

286+
{ #category : 'size' }
287+
ICButton >> glowBorderWidth [
288+
^ ((self borderWidth * 3 / 4) max: 1) rounded
289+
]
290+
291+
{ #category : 'size' }
292+
ICButton >> glowWidth [
293+
^ self sizeUnit * self glowWidthRatio
294+
]
295+
296+
{ #category : 'defaults' }
297+
ICButton >> glowWidthRatio [
298+
^ 1 / 4
299+
]
300+
271301
{ #category : 'accessing' }
272302
ICButton >> id [
273303
^ id
@@ -324,6 +354,20 @@ ICButton >> initializeEvents [
324354
(BlEventHandler on: BlMouseUpEvent do: [ :anEvent | self fire ]) ]
325355
]
326356

357+
{ #category : 'initialization' }
358+
ICButton >> initializeLabel [
359+
"Idempotent: safe to send whenever the text changes."
360+
361+
inputLabel ifNil: [
362+
inputLabel := BlTextElement new
363+
constraintsDo: [ :c |
364+
c frame horizontal alignCenter.
365+
c frame vertical alignCenter ];
366+
yourself.
367+
self labelHost addChild: inputLabel ].
368+
self applyLabelSize
369+
]
370+
327371
{ #category : 'initialization' }
328372
ICButton >> initializeWidget [
329373
"No extent, no padding: applySize owns both."
@@ -332,21 +376,17 @@ ICButton >> initializeWidget [
332376
self layout: BlFrameLayout new
333377
]
334378

335-
{ #category : 'evaluating' }
336-
ICButton >> initializeWidgetSize [
337-
widgetSize:= 200@200.
338-
]
339-
340379
{ #category : 'accessing' }
341-
ICButton >> isOn [
380+
ICButton >> inputText [
381+
^ inputText
342382

343-
^ isOn
344383
]
345384

346385
{ #category : 'accessing' }
347-
ICButton >> isOn: anObject [
386+
ICButton >> inputText: aString [
387+
inputText := aString.
388+
self initializeLabel
348389

349-
isOn := anObject
350390
]
351391

352392
{ #category : 'accessing' }
@@ -361,6 +401,39 @@ ICButton >> isToggleable: aBoolean [
361401
self eventTarget ifNotNil: [ self initializeEvents ]
362402
]
363403

404+
{ #category : 'accessing' }
405+
ICButton >> labelColor [
406+
^ Color white
407+
]
408+
409+
{ #category : 'initialization' }
410+
ICButton >> labelHost [
411+
"The element my label lives in."
412+
413+
^ button
414+
]
415+
416+
{ #category : 'accessing' }
417+
ICButton >> labelString [
418+
"What my label displays. Subclasses that derive it from state override me."
419+
420+
^ inputText
421+
]
422+
423+
{ #category : 'size' }
424+
ICButton >> labelText: aString [
425+
^ self labelText: aString color: self labelColor
426+
427+
]
428+
429+
{ #category : 'size' }
430+
ICButton >> labelText: aString color: aColor [
431+
^ aString asRopedText attributes: {
432+
(BlTextForegroundAttribute paint: aColor).
433+
BlFontWeightAttribute bold.
434+
(BlFontSizeAttribute size: self fontSize) }
435+
]
436+
364437
{ #category : 'accessing' }
365438
ICButton >> offColor [
366439

CoypuIDE/ICCheckBox.class.st

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,35 @@ Class {
1313
#tag : 'button'
1414
}
1515

16+
{ #category : 'examples' }
17+
ICCheckBox class >> exampleThreeSizes [
18+
<script>
19+
| container |
20+
container := BlElement new
21+
layout: (BlGridLayout new
22+
columnCount: 3;
23+
cellSpacing: 20;
24+
yourself);
25+
padding: (BlInsets all: 20);
26+
background: Color veryVeryDarkGray;
27+
constraintsDo: [ :c |
28+
c horizontal fitContent.
29+
c vertical fitContent ];
30+
yourself.
31+
32+
#( 40 80 160 ) do: [ :each |
33+
| box |
34+
box := self new
35+
inputText: 'SYNC';
36+
widgetSize: each;
37+
yourself.
38+
each = 80 ifTrue: [ box toggle ].
39+
container addChild: box ].
40+
41+
container openInSpace
42+
43+
]
44+
1645
{ #category : 'evaluating' }
1746
ICCheckBox >> clickBox [
1847

@@ -42,7 +71,7 @@ ICCheckBox >> initializeClickBox [
4271
geometry: (BlRoundedRectangleGeometry cornerRadius: 8);
4372
background: Color white;
4473
layout: BlFrameLayout new;
45-
size: 30 @ 32;
74+
extent: 30 @ 32;
4675
border: (BlBorder paint: Color darkGray width: 4)).
4776
self initializeClickSymbol.
4877
self addChild: clickBox
@@ -63,27 +92,6 @@ ICCheckBox >> initializeClickSymbol [
6392
c frame vertical alignCenter ]
6493
]
6594

66-
{ #category : 'evaluating' }
67-
ICCheckBox >> initializeEvents [
68-
69-
clickBox addEventHandler: (BlEventHandler
70-
on: BlMouseDownEvent
71-
do: [ :anEvent |
72-
self toggle.
73-
self callback value: self value ]).
74-
75-
76-
]
77-
78-
{ #category : 'evaluating' }
79-
ICCheckBox >> initializeWidget [
80-
81-
self size: self widgetSize.
82-
self background: self backColor.
83-
self layout: BlLinearLayout horizontal .
84-
self padding: (BlInsets all: 10)
85-
]
86-
8795
{ #category : 'evaluating' }
8896
ICCheckBox >> toggle [
8997

CoypuIDE/ICIndicatorButton.class.st

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@ Class {
3232
#tag : 'button'
3333
}
3434

35+
{ #category : 'examples' }
36+
ICIndicatorButton class >> exampleThreeSizes [
37+
<script>
38+
| container |
39+
container := BlElement new
40+
layout: (BlGridLayout new
41+
columnCount: 3;
42+
cellSpacing: 20;
43+
yourself);
44+
padding: (BlInsets all: 20);
45+
background: Color veryVeryDarkGray;
46+
constraintsDo: [ :c |
47+
c horizontal fitContent.
48+
c vertical fitContent ];
49+
yourself.
50+
51+
#( 40 80 160 ) do: [ :each |
52+
| indicator |
53+
indicator := self new widgetSize: each.
54+
each = 80 ifTrue: [ indicator toggle ].
55+
container addChild: indicator ].
56+
57+
container openInSpace
58+
59+
]
60+
3561
{ #category : 'initialization' }
3662
ICIndicatorButton >> applyButtonSize [
3763
super applyButtonSize.

0 commit comments

Comments
 (0)