Skip to content

Commit fa4aabe

Browse files
committed
fixture: ICKnob is not fixed anymore
1 parent 8dc2e59 commit fa4aabe

2 files changed

Lines changed: 134 additions & 68 deletions

File tree

CoypuIDE/ICKnob.class.st

Lines changed: 126 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ Class {
3535
'centerPosition',
3636
'minLabel',
3737
'maxLabel',
38-
'currentLabel'
38+
'currentLabel',
39+
'outerRing',
40+
'marker'
3941
],
4042
#category : 'CoypuIDE-slider',
4143
#package : 'CoypuIDE',
@@ -94,6 +96,41 @@ ICKnob class >> basicExample [
9496
"knob callBack: [ :v | v inspect ]"
9597
]
9698

99+
{ #category : 'defaults' }
100+
ICKnob class >> defaultDiameter [
101+
"Overridden by subclasses that want a different natural size."
102+
^ 60
103+
]
104+
105+
{ #category : 'examples' }
106+
ICKnob class >> differentSizesExample [
107+
108+
<script>
109+
| knobs container space |
110+
knobs := #( 48 96 144 ) collect: [ :d |
111+
((self label: d printString , ' px') diameter: d)
112+
constraintsDo: [ :c | c margin: (BlInsets all: 12) ];
113+
yourself ].
114+
115+
container := BlElement new
116+
layout: BlLinearLayout horizontal alignCenter;
117+
constraintsDo: [ :c |
118+
c horizontal matchParent.
119+
c vertical matchParent ];
120+
background: Color black;
121+
addChildren: knobs;
122+
yourself.
123+
124+
space := BlSpace new.
125+
space extent: 860 @ 440.
126+
space title: 'ICKnob - three sizes'.
127+
space root
128+
background: Color black;
129+
addChild: container.
130+
space show
131+
132+
]
133+
97134
{ #category : 'instance creation' }
98135
ICKnob class >> fromDictionary: aDictionary [
99136
]
@@ -196,7 +233,42 @@ ICKnob >> angleToValue [
196233
^ mapped asFloat
197234
]
198235

199-
{ #category : 'initialization' }
236+
{ #category : 'size' }
237+
ICKnob >> applyLabelSizes [
238+
| inset |
239+
inset := self diameter / 3.
240+
minLabel transformDo: [ :t | t translateBy: inset @ inset negated ].
241+
maxLabel transformDo: [ :t | t translateBy: inset negated @ inset negated ].
242+
currentLabel transformDo: [ :t | t translateBy: 0 @ (self diameter / 6) negated ].
243+
{ minLabel. maxLabel. currentLabel. inputLabel } do: [ :l |
244+
l ifNotNil: [ l text fontSize: self fontSz ] ]
245+
]
246+
247+
{ #category : 'size' }
248+
ICKnob >> applyMarkerSize [
249+
| w h |
250+
w := self diameter / 6.
251+
h := self diameter / 3.
252+
marker
253+
extent: w @ h;
254+
geometry: (BlRoundedRectangleGeometry cornerRadius: w / 2);
255+
position: ((self knobSize - w) / 2) @ (self diameter / 12)
256+
]
257+
258+
{ #category : 'size' }
259+
ICKnob >> applySize [
260+
self extent: self widgetSize asPoint.
261+
self padding: (BlInsets all: self diameter / 8).
262+
knob extent: self knobSize asPoint.
263+
disk extent: self diskSize asPoint.
264+
outerRing extent: self outerRingSize asPoint.
265+
self applyMarkerSize.
266+
self applyLabelSizes.
267+
self whenLayoutedDoOnce: [
268+
self centerPosition: self positionInSpace + (self extent / 2) ]
269+
]
270+
271+
{ #category : 'accessing' }
200272
ICKnob >> backColor [
201273
^ (Color veryVeryDarkGray)
202274
]
@@ -282,8 +354,8 @@ ICKnob >> diameter [
282354

283355
{ #category : 'accessing' }
284356
ICKnob >> diameter: aNumber [
285-
286-
diameter := aNumber
357+
diameter := aNumber.
358+
knob ifNotNil: [ self applySize ] "no-op during initialize, before elements exist"
287359
]
288360

289361
{ #category : 'accessing' }
@@ -298,15 +370,14 @@ ICKnob >> disk: anElement [
298370
disk := anElement
299371
]
300372

301-
{ #category : 'initialization' }
373+
{ #category : 'accessing' }
302374
ICKnob >> diskColor [
303375
^ (Color cyan)
304376
]
305377

306-
{ #category : 'initialization' }
307-
ICKnob >> diskSize [
308-
309-
^ self diameter + 40
378+
{ #category : 'accessing' }
379+
ICKnob >> diskSize [
380+
^ self outerRingSize
310381
]
311382

312383
{ #category : 'api - operations' }
@@ -320,8 +391,8 @@ ICKnob >> doOperations [
320391
]
321392

322393
{ #category : 'accessing' }
323-
ICKnob >> fontSz [
324-
^12
394+
ICKnob >> fontSz [
395+
^ self diameter / 5
325396
]
326397

327398
{ #category : 'initialization' }
@@ -334,9 +405,7 @@ ICKnob >> initialize [
334405
self initializeOuterRing.
335406
self initializeValueLabels.
336407
self initializeDisks.
337-
"self initializeLabel."
338-
339-
"Here to define the centerPosition once layouted"
408+
self applySize. "<- new: first sizing pass"
340409
self setValue: self minValue.
341410
self position: 0 @ 0
342411
]
@@ -357,16 +426,14 @@ ICKnob >> initializeDisk [
357426

358427
self disk: (BlElement new
359428
background: self diskColor;
360-
extent: self diskSize asPoint;
361429
geometry: (BlAnnulusSectorGeometry new
362430
startAngle: -225;
363431
endAngle: -210;
364432
innerRadius: 0.83;
365433
outerRadius: 1);
366434
constraintsDo: [ :c |
367-
c frame horizontal alignCenter.
368-
c frame vertical alignCenter ]). "background: (Color r:63 g:162 b:227 range:255);"
369-
435+
c frame horizontal alignCenter.
436+
c frame vertical alignCenter ]).
370437

371438
self addChild: self disk
372439
]
@@ -406,33 +473,23 @@ ICKnob >> initializeEvents [
406473
{ #category : 'initialization' }
407474
ICKnob >> initializeGeometry [
408475

409-
| marker |
410-
self extent: (diameter + 100) asPoint.
411476
self background: self backColor.
412477
self clipChildren: false.
413478
self layout: BlFrameLayout new.
414-
self padding: (BlInsets all: 7).
415-
416479

417480
self knob: (BlElement new
418481
geometry: BlCircleGeometry new;
419-
extent: self knobSize asPoint;
420482
clipChildren: false;
421483
background: self knobColor;
422484
constraintsDo: [ :c |
423-
c frame horizontal alignCenter.
424-
c frame vertical alignCenter ]).
485+
c frame horizontal alignCenter.
486+
c frame vertical alignCenter ]).
425487

426488
self addChild: self knob.
427489

428-
429490
marker := BlElement new
430-
extent: 10 @ 20;
431-
transformDo: [ :t | t translateBy: -2 @ 0 ];
432-
geometry: (BlRoundedRectangleGeometry cornerRadius: 5);
433491
background: self markerColor;
434-
position: self knobSize / 2 @ 5.
435-
marker zIndex: 100.
492+
zIndex: 100.
436493

437494
self knob addChild: marker
438495
]
@@ -455,48 +512,47 @@ ICKnob >> initializeLabel [
455512
{ #category : 'initialization' }
456513
ICKnob >> initializeOuterRing [
457514

458-
| outerRing |
459515
outerRing := BlElement new
460516
background: self outerRingColor;
461-
extent: self outerRingSize asPoint;
462-
"effect: (BlGaussianShadowEffect color: Color white offset: 0@ -10 width: 10);"geometry:
463-
(BlAnnulusSectorGeometry new
517+
geometry: (BlAnnulusSectorGeometry new
464518
startAngle: 135;
465519
endAngle: 45;
466520
innerRadius: 0.83;
467521
outerRadius: 1);
468522
constraintsDo: [ :c |
469523
c frame horizontal alignCenter.
470524
c frame vertical alignCenter ].
525+
471526
self addChild: outerRing
472527
]
473528

474529
{ #category : 'initialization' }
475530
ICKnob >> initializeValueLabels [
476531

477-
minLabel := BlTextElement new text: (self minValue asRopedText attributes: { (BlTextForegroundAttribute
478-
paint: self textColor) });
479-
transformDo: [ :t | t translateBy: 20 @ -20];
480-
constraintsDo: [ :c |c frame horizontal alignLeft. c frame vertical alignBottom.].
481-
482-
maxLabel := BlTextElement new text: (self maxValue asRopedText attributes: { (BlTextForegroundAttribute
483-
paint: self textColor) });
484-
transformDo: [ :t | t translateBy: -20 @ -20];
485-
constraintsDo: [ :c |c frame horizontal alignRight. c frame vertical alignBottom.].
486-
487-
currentLabel := BlTextElement new text: (self currentValue asRopedText attributes:{(BlTextForegroundAttribute
488-
paint: self valueColor) });
489-
transformDo: [ :t | t translateBy: 0 @ -10];
490-
constraintsDo: [ :c |c frame horizontal alignCenter. c frame vertical alignBottom.].
532+
minLabel := BlTextElement new
533+
text: (self minValue asRopedText attributes:
534+
{ (BlTextForegroundAttribute paint: self textColor) });
535+
constraintsDo: [ :c |
536+
c frame horizontal alignLeft.
537+
c frame vertical alignBottom ].
538+
539+
maxLabel := BlTextElement new
540+
text: (self maxValue asRopedText attributes:
541+
{ (BlTextForegroundAttribute paint: self textColor) });
542+
constraintsDo: [ :c |
543+
c frame horizontal alignRight.
544+
c frame vertical alignBottom ].
545+
546+
currentLabel := BlTextElement new
547+
text: (self currentValue asRopedText attributes:
548+
{ (BlTextForegroundAttribute paint: self valueColor) });
549+
constraintsDo: [ :c |
550+
c frame horizontal alignCenter.
551+
c frame vertical alignBottom ].
491552

492553
self addChild: minLabel.
493554
self addChild: currentLabel.
494-
self addChild: maxLabel.
495-
496-
self callBack: [ :v |
497-
currentLabel text: (v rounded asRopedText attributes:{(BlTextForegroundAttribute
498-
paint: self valueColor) })].
499-
555+
self addChild: maxLabel
500556
]
501557

502558
{ #category : 'accessing' }
@@ -523,18 +579,17 @@ ICKnob >> knob: anElement [
523579
knob := anElement
524580
]
525581

526-
{ #category : 'initialization' }
582+
{ #category : 'accessing' }
527583
ICKnob >> knobColor [
528584
^(Color veryDarkGray)
529585
]
530586

531-
{ #category : 'initialization' }
532-
ICKnob >> knobSize [
533-
534-
^ self diameter
587+
{ #category : 'accessing' }
588+
ICKnob >> knobSize [
589+
^ self diameter
535590
]
536591

537-
{ #category : 'initialization' }
592+
{ #category : 'accessing' }
538593
ICKnob >> markerColor [
539594
^(Color white)
540595
]
@@ -626,15 +681,14 @@ ICKnob >> openForParam: aString dsp: aDsp [
626681
space show ]
627682
]
628683

629-
{ #category : 'initialization' }
684+
{ #category : 'accessing' }
630685
ICKnob >> outerRingColor [
631686
^(Color darkGray )
632687
]
633688

634-
{ #category : 'initialization' }
635-
ICKnob >> outerRingSize [
636-
637-
^self diameter + 40
689+
{ #category : 'accessing' }
690+
ICKnob >> outerRingSize [
691+
^ self diameter * 5 / 3
638692
]
639693

640694
{ #category : 'api - bounds' }
@@ -676,12 +730,12 @@ ICKnob >> stepValue: aNumber [
676730
stepValue := aNumber
677731
]
678732

679-
{ #category : 'initialization' }
733+
{ #category : 'accessing' }
680734
ICKnob >> textColor [
681735
^Color white.
682736
]
683737

684-
{ #category : 'initialization' }
738+
{ #category : 'accessing' }
685739
ICKnob >> valueColor [
686740
^Color white.
687741
]
@@ -696,3 +750,7 @@ ICKnob >> valueToAngle: aNumber [
696750
+ self minAngle.
697751
^ mapped
698752
]
753+
754+
{ #category : 'accessing' }
755+
ICKnob >> widgetSize [ ^ self diameter * 8 / 3
756+
]

CoypuIDE/ICReferenceBrowser.class.st

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ ICReferenceBrowser >> initializeDetailPanes [
196196
exampleBody := ToPane vertical hMatchParent vFitContent
197197
]
198198

199+
{ #category : 'initialization' }
200+
ICReferenceBrowser >> initializeLayout [
201+
202+
self layout: BlLinearLayout vertical.
203+
self matchParent.
204+
self padding: (BlInsets all: 6)
205+
]
206+
199207
{ #category : 'initialization' }
200208
ICReferenceBrowser >> initializeMessageList [
201209

0 commit comments

Comments
 (0)