@@ -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' }
67101ICButton >> 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' }
159186ICButton >> 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' }
183198ICButton >> 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' }
272302ICButton >> 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' }
328372ICButton >> 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' }
365438ICButton >> offColor [
366439
0 commit comments