Skip to content

Commit

Permalink
polished skin management
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Oct 31, 2023
1 parent f3d8622 commit 1648fb3
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 95 deletions.
32 changes: 9 additions & 23 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1114,12 +1114,11 @@ ToSandBox class >> example_OpenSaveSaveAsCloseWithSubmenu [
size: 400 @ 200;
yourself.
menu := ToMenu new.
menu label: (ToLabel text: 'Menu').
"menu label: (ToLabel text: 'Menu')."
menu icon: (ToImage inner: (self iconNamed: #solidMenu)).
menu addItem: (ToMenuItem new
icon: (ToImage inner: (self iconNamed: #solidMenu));
label: (ToLabel text: 'Open')).
menu items last rightLabelAlignment: 20.
lbl := ToLabel new text: ('Save stuffs' asRopedText
fontSize: 12;
foreground: (Color black alpha: 0.7)).
Expand All @@ -1129,31 +1128,26 @@ ToSandBox class >> example_OpenSaveSaveAsCloseWithSubmenu [
menu addItem: (ToMenuItem new
icon: (ToImage inner: (self iconNamed: #solidMenu));
label: (ToLabel text: 'Save')).
menu items last rightLabelAlignment: 20.
saveAs := ToMenu new label: (ToLabel text: 'Save as').
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.pdf')).
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.doc')).
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.xml')).
menu addItem: saveAs.
"menu items last when: BlMouseDownEvent do: [ :event | event currentTarget inspect ]."

menu items last rightLabelAlignment: 20.
saveAs := ToMenu new label: (ToLabel text: 'Save as').
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.pdf')).
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.doc')).
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.xml')).
menu addItem: saveAs.
menu items last rightLabelAlignment: 20.
saveAs := ToMenu new label: (ToLabel text: 'Save as').
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.pdf')).
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.doc')).
saveAs addItem: (ToMenuItem new label: (ToLabel text: '.xml')).
menu addItem: (ToMenu new label: (ToLabel text: 'Save as again...')).
menu items last addItem: saveAs.
menu items last rightLabelAlignment: 20.
menu addSeparator.
menu addItem: (ToMenuItem new label: (ToLabel text: 'Close')).
menu items last rightLabelAlignment: 20.
container pane addChild: menu.
"menu window inspect."
container openInSpace
Expand Down Expand Up @@ -1366,23 +1360,19 @@ ToSandBox class >> example_SimpleOpenSaveSaveAsClose [
menu addItem: (ToMenuItem new
icon: ((ToImage inner: (self iconNamed: #solidMenu)));
label: (ToLabel text: 'Open')).
menu items last rightLabelAlignment: 40.
menu addItem: (ToMenuItem new
icon: ((ToImage inner: (self iconNamed: #solidMenu)));
label: (ToLabel text: 'Save');
background: Color random).
menu items last rightLabelAlignment: 40.
menu addItem: (ToMenuItem new
icon: ((ToImage inner: (self iconNamed: #solidMenu)));
label: (ToLabel text: 'Save as');
background: Color random).
menu items last rightLabelAlignment: 40.
menu items last whenClickedDo: [ :event | event currentTarget inspect ].
menu addSeparator.
menu addItem: (ToMenuItem new
label: (ToLabel text: 'Close');
background: Color random).
menu items last rightLabelAlignment: 40.
menu items last whenClickedDo: [ :event | event currentTarget inspect ].
container pane addChild: menu.

Expand Down Expand Up @@ -2129,18 +2119,17 @@ ToSandBox class >> example_menuBar2 [
| stream selector |
stream := String streamContents: [ :out |
out
nextPutAll: 'Level';
nextPutAll: 'Level ';
space;
print: i ].
selector := String streamContents: [ :out |
out
nextPutAll: 'level';
nextPutAll: 'level ';
print: index;
nextPutAll: 'Grid';
nextPutAll: ' Grid ';
print: i ].
subMenu addItem: ((ToMenuItem new labelText: stream)
when: BlPrimaryMouseUpEvent do: [ :event | self inform: selector asSymbol ]) ].
"subMenu defaultColumnWidth: 0."
menu addItem: subMenu ].

bar addMenu: menu ].
Expand Down Expand Up @@ -2203,6 +2192,7 @@ ToSandBox class >> example_rootFrameWithContextMenu [

win pane contextMenu: [ :menu :element |
menu addItem: (ToMenuItem new
id: #openFile;
labelText: 'Open file';
icon: (ToImage inner: (Smalltalk ui icons iconNamed: #config))).
menu addItem: (ToMenuItem new labelText: 'Export').
Expand All @@ -2218,7 +2208,9 @@ ToSandBox class >> example_rootFrameWithContextMenu [
(ToImage inner:
(Smalltalk ui icons iconNamed: #solidMenu)).

subsub addItem: (ToMenuItem new id: #here; labelText: 'Here').
subsub addItem: (ToMenuItem new
id: #here;
labelText: 'Here').

sub addItem: subsub.

Expand Down Expand Up @@ -3138,10 +3130,8 @@ ToSandBox class >> example_withCheckBox [
menu := ToMenu new.
menu labelText: 'File'.
menu addItem: (ToMenuItem new labelText: 'Open file').
menu items last rightLabelAlignment: 20.
menu items last icon: ((ToImage inner: (self iconNamed: #solidMenu))).
menu addItem: (ToMenuItem new labelText: 'Export').
menu items last rightLabelAlignment: 20.
grp := ToCheckableGroup new.
right := ToCheckMenuItem new
labelText: 'Right';
Expand All @@ -3162,23 +3152,19 @@ ToSandBox class >> example_withCheckBox [
grp add: left.

menu addSeparator.
menu addAllItems: (grp buttons collect: [:b | b rightLabelAlignment: 20; yourself]).
menu addAllItems: (grp buttons).
.
menu addSeparator.

sub := ToMenu new labelText: 'Save All'.
sub addItem: (ToMenuItem new labelText: 'Locally').
sub items last rightLabelAlignment: 20.

subsub := ToMenu new labelText: 'Externally'.
subsub addItem: (ToMenuItem new labelText: 'Here').
subsub items last rightLabelAlignment: 20.

sub addItem: subsub.
sub items last rightLabelAlignment: 20.

menu addItem: sub.
menu items last rightLabelAlignment: 20.
menu position: 10 @ 10.
menu openInInnerWindow
]
Expand Down
5 changes: 2 additions & 3 deletions src/Toplo-Theme/ToSkinStateQueue.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ToSkinStateQueue >> enqueueState: aState [
ToSkinStateQueue >> enqueueState: aState in: anElement [

" declare the element as dirty "
anElement spaceDo: [ :space | space elementWithUnappliedStates: anElement ].
anElement spaceDo: [ :space | space requestSkinApplicationFor: anElement ].
self enqueueState: aState
]

Expand Down Expand Up @@ -86,8 +86,7 @@ ToSkinStateQueue >> skinChangedEvent: anEvent [
installed ifTrue: [ Error signal: 'A skin can be installed only once.' ].
target := anEvent currentTarget.
installed := true.
self enqueueState: (ToInstallState sourceEvent: anEvent) in: target.
target requestSkin
self enqueueState: (ToInstallState sourceEvent: anEvent) in: target
]

{ #category : 'initialization' }
Expand Down
3 changes: 2 additions & 1 deletion src/Toplo-Widget-Album/ToLabelMonoLineInnerElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ToLabelMonoLineInnerElement >> initialize [
super initialize.
" Need Label measurement to ensure right vertical alignement with labels/menus "
self labelMeasurement.
self preventMouseEvents
self preventMouseEvents.
self withoutSkin.
]

{ #category : 'api - editor' }
Expand Down
3 changes: 2 additions & 1 deletion src/Toplo-Widget-Album/ToLabelMultiLineInnerElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ ToLabelMultiLineInnerElement >> initialize [
self fitContent.
self layout: BlLinearLayout vertical.
self whenTextReplacedDo: [ :t | self textReplaced ].
self preventMouseEvents
self preventMouseEvents.
self withoutSkin.
]

{ #category : 'api - editor' }
Expand Down
4 changes: 2 additions & 2 deletions src/Toplo-Widget-Button/ToButton.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Class {
ToButton >> initialRawStyle [

super initialRawStyle.
"((self parent isKindOf: ToMenuItem) and: [ self parent isTopMenu not ])
ifTrue: [ ^ self ]."
((self parent isKindOf: ToMenuItem) and: [ self parent isTopMenu not ])
ifTrue: [ ^ self ].
(self hasIcon and: [ self hasLabel ]) ifFalse: [
self interspace: 0.
^ self ].
Expand Down
2 changes: 2 additions & 0 deletions src/Toplo-Widget-Button/ToCheckbox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ToCheckbox >> defaultBlankCheckboxImage [

| bar im |
bar := ToElement new id: #bar.
bar withoutSkin.
bar constraintsDo: [ :c |
c horizontal matchParent.
c vertical exact: 3.
Expand All @@ -25,6 +26,7 @@ ToCheckbox >> defaultBlankCheckboxImage [
im size: 16 asPoint.
im addChild: bar.
im geometry: self iconGeometry.
im withoutSkin.
^ im
]

Expand Down
1 change: 0 additions & 1 deletion src/Toplo-Widget-Button/ToCheckboxSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ ToCheckboxSkin >> initialLookEvent: anEvent [

super initialLookEvent: anEvent.
anEvent elementDo: [ :e |
e hasLabel ifTrue: [ e interspace: 10 ].
e icon border: e iconDefaultBorder ]
]

Expand Down
6 changes: 6 additions & 0 deletions src/Toplo-Widget-Menu/ToContextMenu.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ ToContextMenu >> openedEventClass [
^ ToContextMenuOpenedEvent
]

{ #category : 'api - displaying' }
ToContextMenu >> popupEvent: anEvent [

^ super popupEvent: anEvent
]

{ #category : 't - menu window model' }
ToContextMenu >> rootMenu [

Expand Down
21 changes: 11 additions & 10 deletions src/Toplo-Widget-Menu/ToGeneralButtonMenuItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ ToGeneralButtonMenuItem >> defaultLayout [
^ BlLinearLayout horizontal
]

{ #category : 'skin' }
ToGeneralButtonMenuItem >> initialRawStyle [
super initialRawStyle.
self isTopMenu ifTrue: [ ^ self ].
self parentMenu ifNil: [ ^ self ].
(self parentMenu items anySatisfy: [ :mi | mi hasIcon ]) ifFalse: [ ^ self ].
self button rightLabelAlignment: 30

]

{ #category : 'initialization' }
ToGeneralButtonMenuItem >> initialize [

Expand All @@ -64,6 +54,17 @@ ToGeneralButtonMenuItem >> initialize [
self layout: self defaultLayout
]

{ #category : 'skin' }
ToGeneralButtonMenuItem >> installRawStyle [

super installRawStyle.
self isTopMenu ifTrue: [ ^ self ].
self parentMenu ifNil: [ ^ self ].
(self parentMenu items anySatisfy: [ :mi | mi hasIcon ]) ifFalse: [
^ self ].
self button rightLabelAlignment: 25
]

{ #category : 't - clickable - click behavior' }
ToGeneralButtonMenuItem >> whenClickedDo: aBlock [
"Inform that the widget has been clicked."
Expand Down
15 changes: 4 additions & 11 deletions src/Toplo-Widget-Menu/ToMenu.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ ToMenu >> includes: anElement [
^ super includes: anElement
]

{ #category : 'skin' }
ToMenu >> initialRawStyle [

super initialRawStyle.
'initialRawStyle' traceCr.
self isSubmenu ifFalse: [ ^ self ].
self parentMenu items do: [ :mi |
(mi isKindOf: ToMenuItem) ifTrue: [ mi filler width: 15] ]
]

{ #category : 'initialization' }
ToMenu >> initialize [

Expand All @@ -76,9 +66,12 @@ ToMenu >> installRawStyle [

super installRawStyle.
self isSubmenu ifFalse: [ ^ self ].
self parentMenu items do: [ :mi |
(mi isKindOf: ToMenuItem) ifTrue: [ mi filler width: 15] ].
self rightHandSide addChild: (ToLabel new
text: '...';
yourself)
yourself).

]

{ #category : 'testing' }
Expand Down
2 changes: 2 additions & 0 deletions src/Toplo-Widget-Menu/ToMenuItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ToMenuItem >> initialize [
self withStamp: #'menu-item'.
filler := self newFiller.
rightHandSide := self newRightHandSide.
filler withoutSkin.
rightHandSide withoutSkin.
self button addChild: filler.
self button addChild: rightHandSide
]
Expand Down
4 changes: 3 additions & 1 deletion src/Toplo-Widget-Menu/ToMenuItemElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Class {
{ #category : 'adding-removing' }
ToMenuItemElement >> addedInMenu: aMenu [

self parentMenu: aMenu
self parentMenu: aMenu.
aMenu requestLayout.
aMenu requestSkin
]

{ #category : 'testing' }
Expand Down
4 changes: 3 additions & 1 deletion src/Toplo-Widget-Menu/ToMenuWindow.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ ToMenuWindow >> popupEvent: anEvent [
Error signal: 'Can''t popup a menu if the element is not attached to a space' ].

self items ifEmpty: [ ^ self ].
self requestSkin.
self items do: [ :it |
self root addChild: it ].
self root addChild: it.
it requestSkin ].
super popupEvent: anEvent
]
4 changes: 3 additions & 1 deletion src/Toplo-Widget-Pane/ToDivider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ ToDivider >> installRawStyle [
self geometry: self defaultGeometry.
self margin: self defaultMargins.
self padding: self defaultPadding

]

{ #category : 'testing' }
Expand Down Expand Up @@ -305,7 +306,8 @@ ToDivider >> thickness [
{ #category : 'accessing' }
ToDivider >> thickness: aNumber [

thickness := aNumber
thickness := aNumber.
self requestSkin
]

{ #category : 'accessing' }
Expand Down
17 changes: 14 additions & 3 deletions src/Toplo/BlElement.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,22 @@ BlElement >> holder [
^ self constraints infinite holder
]

{ #category : '*Toplo' }
BlElement >> ifNotWithNullSkinDo: aBlock [

(self userData at: #localDefaultSkin ifAbsent: [ ]) ifNotNil: [ :s |
s isNullSkin ifTrue: [ ^ self ] ].
aBlock value
]

{ #category : '*Toplo' }
BlElement >> initialRawStyle [
]

{ #category : '*Toplo' }
BlElement >> installRawStyle [

self requestSkin
]

{ #category : '*Toplo' }
Expand Down Expand Up @@ -289,9 +299,10 @@ BlElement >> requestDefaultSkin: aSkin [
{ #category : '*Toplo' }
BlElement >> requestSkin [

self skinInstaller ifNotNil: [ ^ self ].
self skinInstaller: ToSkinInstaller new.
self spaceDo: [ :space | space elementWithSkinInstaller: self ]
self ifNotWithNullSkinDo: [
self skinInstaller ifNotNil: [ ^ self ].
self skinInstaller: ToSkinInstaller new.
self spaceDo: [ :space | space elementWithSkinInstaller: self ] ]
]

{ #category : '*Toplo' }
Expand Down
Loading

0 comments on commit 1648fb3

Please sign in to comment.