[Cuis-dev] Toggleable halos debugging aids
Mariano Montone
marianomontone at gmail.com
Tue May 30 06:54:01 PDT 2023
Hi,
the current halos display code starts with this commented code for
"Debugging aids":
HaloMorph>>drawOn: aCanvas
| b |
target ifNil: [^super drawOn: aCanvas].
"Debugging aid"
"aCanvas
fillRectangle: haloBox
color: (Color red alpha: 0.2).
aCanvas
fillRectangle: self morphLocalBounds
color: (Color gray alpha: 0.4)."
I find that commented code useful as I often want to visualize the halos
morph bounds when developing GUI.
So, I would like to make that commented code toggleable.
I attach an implementation that uses Preferences to toggle halo's
debugging aids.
I don't care much about being done my way, but being done in some way (I
struggled with the name of preferences, or perhaps you prefer to do this
in a completely different way.)
What do you think?
Thanks,
Mariano
-------------- next part --------------
'From Cuis 6.0 [latest update: #5832] on 30 May 2023 at 10:41:16 am'!
!PreferenceSet class methodsFor: 'sys preference' stamp: 'MM 5/30/2023 10:35:14'!
installMiscPreferences
" Preference value defined with closure. We could insert in a dynamic array...
Preference with event handler "
self sysPreferences
name: #haloHandleSize
category: #gui
value: [(Preferences at: #standardListFont) pointSize * 5 // 3 max: 16];
name: #halosMorphBoundsFrameColor
description: 'When set, use this color for a rectangle on halos morph bounds. Useful for debugging morph sizes.'
category: #gui
type: Object "Using Object as type as the property value can be either nil or a Color."
value: nil;
name: #halosMorphBoundsFillColor
description: 'When set, use this color for filling a rectangle on halos morph bounds. Useful for debugging morph sizes.'
category: #gui
type: Object "Using Object as type as the property value can be either nil or a Color."
value: nil;
name: #roundedButtonRadius
category: #gui
value: [(Preferences at: #standardListFont) pointSize * 8 // 14];
name: #roundedWindowRadius
category: #gui
value: [(Preferences at: #standardListFont) pointSize] ;
name: #scrollbarThickness
category: #gui
value: [(Preferences at: #windowTitleFont) pointSize + 2];
name: #classFinder
category: #programming
value: [ BrowserWindow findClass ];
name: #defaultAuthorName
category: #programming
value: [Utilities authorName];
name: #worldMenu
category: #system
value: TheWorldMenu ! !
!HaloMorph methodsFor: 'drawing' stamp: 'MM 5/30/2023 10:37:04'!
drawOn: aCanvas
| b |
target ifNil: [^super drawOn: aCanvas].
"For debugging halos' morph bounds visually."
"Fill the bounds of halo's morph."
"To activate: Preferences at: #halosMorphBoundsFillColor put: (Color blue alpha: 0.2)"
(Preferences at: #halosMorphBoundsFillColor) ifNotNil: [:fillColor |
aCanvas
fillRectangle: self morphLocalBounds
color: fillColor].
"Draw a frame over halos morph bounds."
"To activate: Preferences at: #halosMorphBoundsFrameColor put: Color blue."
(Preferences at: #halosMorphBoundsFrameColor) ifNotNil: [:frameColor |
aCanvas frameRectangle: self morphLocalBounds
borderWidth: 1
color: frameColor].
target haloShowsCoordinateSystem ifTrue: [
target displayFullBounds ifNotNil: [ :fb |
aCanvas privateFrameGlobalRect: fb borderWidth: 3 color: `Color black alpha: 0.1`.
b := target displayBounds.
b = fb ifFalse: [
aCanvas privateFrameGlobalRect: b borderWidth: 3 color: `Color black alpha: 0.1` ].
self drawCoordinateSystemOn: aCanvas ]].! !
More information about the Cuis-dev
mailing list