Skip to content

Commit

Permalink
cleaned ToWidgetSkin
Browse files Browse the repository at this point in the history
fixed popup menu
  • Loading branch information
plantec committed Jul 20, 2023
1 parent 3a72178 commit d453795
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 129 deletions.
12 changes: 11 additions & 1 deletion src/Toplo/BlElement.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ BlElement >> dispatchLookEvent: anEvent [
self childrenDo: [ :child | child dispatchLookEvent: anEvent ]
]

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

self dispatchEvent: ToElementSkinChangedEvent new.
self childrenDo: [ :child | child dispatchSkinChangedEvent ]

]

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

Expand Down Expand Up @@ -76,5 +84,7 @@ BlElement >> toTheme: aTheme [
BlElement >> toThemeChanged [

self dispatchEvent: ToThemeChangedEvent new.
self childrenDo: [ :c | c toThemeChanged ]
self childrenDo: [ :c | c toThemeChanged ].


]
7 changes: 7 additions & 0 deletions src/Toplo/TToCheckable.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ TToCheckable >> group: aCheckableGroup [
group := aCheckableGroup
]

{ #category : #initialization }
TToCheckable >> initialize [

self class initializeSlots: self.
super initialize.
]

{ #category : #'t - checkable initializing' }
TToCheckable >> initializeCheckable [

Expand Down
6 changes: 3 additions & 3 deletions src/Toplo/TToSkinable.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ TToSkinable >> withSkin: aSkin [
self withoutSkin.
privateSkin := aSkin.
Toplo useLookAndFeel ifTrue: [ ^ self ].
privateSkin ifNotNil: [ self addEventHandler: privateSkin ].


privateSkin ifNotNil: [
self addEventHandler: privateSkin.
self dispatchSkinChangedEvent ]
]

{ #category : #'t - skin accessing' }
Expand Down
4 changes: 2 additions & 2 deletions src/Toplo/ToButtonImageSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ ToButtonImageSkin >> buttonType: aButtonType [
]

{ #category : #'api - install/uninstall hook' }
ToButtonImageSkin >> whenAddedToSpace: anEvent in: anElement [
ToButtonImageSkin >> onSkinInstalledIn: anElement [

| iconLook |
iconLook := self buttonType iconLookIn: anElement.
self addLook: iconLook.
super whenAddedToSpace: anEvent in: anElement.
super onSkinInstalledIn: anElement

]
28 changes: 14 additions & 14 deletions src/Toplo/ToButtonLabelSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ ToButtonLabelSkin >> buttonType: aButtonType [
buttonType := aButtonType
]

{ #category : #'api - install/uninstall hook' }
ToButtonLabelSkin >> onSkinInstalledIn: anElement [

| labelLook attrBuilder |

attrBuilder := self textAttributesBuilderFromElement: anElement.
labelLook := self buttonType labelLookIn: anElement.
labelLook attrBuilder: attrBuilder.
self addLook: labelLook.

super onSkinInstalledIn: anElement

]

{ #category : #accessing }
ToButtonLabelSkin >> textAttributesBuilderFromElement: anElement [

Expand All @@ -32,17 +46,3 @@ ToButtonLabelSkin >> textAttributesBuilderFromElement: anElement [

^ builder
]

{ #category : #'api - install/uninstall hook' }
ToButtonLabelSkin >> whenAddedToSpace: anEvent in: anElement [

| labelLook attrBuilder |

attrBuilder := self textAttributesBuilderFromElement: anElement.
labelLook := self buttonType labelLookIn: anElement.
labelLook attrBuilder: attrBuilder.
self addLook: labelLook.

super whenAddedToSpace: anEvent in: anElement.

]
35 changes: 18 additions & 17 deletions src/Toplo/ToButtonSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ ToButtonSkin >> eventsToHandle [
^ super eventsToHandle, { ToButtonIconChanged. ToButtonLabelChanged }
]

{ #category : #'api - install/uninstall hook' }
ToButtonSkin >> onSkinInstalledIn: anElement [

" must send to super ** after ** the look is initialize from type "
self type onSkinInstalled: self in: anElement.
super onSkinInstalledIn: anElement

]

{ #category : #'api - install/uninstall hook' }
ToButtonSkin >> onSkinUninstalledIn: anElement [

self type onSkinUninstalled: self in: anElement.
super onSkinUninstalledIn: anElement


]

{ #category : #accessing }
ToButtonSkin >> type [

Expand All @@ -66,20 +84,3 @@ ToButtonSkin >> type: aSkinType [
"#default, #primary, #link or #text"
type := aSkinType
]

{ #category : #'api - install/uninstall hook' }
ToButtonSkin >> whenAddedToSpace: anEvent in: anElement [

" must send to super ** after ** the look is initialize from type "
self type whenAddedToSpace: anEvent in: anElement fromSkin: self.
super whenAddedToSpace: anEvent in: anElement.

]

{ #category : #'api - install/uninstall hook' }
ToButtonSkin >> whenRemovedFromSpace: anEvent in: anElement [

self type whenRemovedFromSpace: anEvent in: anElement fromSkin: self.
super whenRemovedFromSpace: anEvent in: anElement.

]
28 changes: 14 additions & 14 deletions src/Toplo/ToButtonType.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,7 @@ ToButtonType >> labelLookIn: anElement [
]

{ #category : #'api - install/uninstall hook' }
ToButtonType >> regularFormLookIn: anElement [

self subclassResponsibility
]

{ #category : #'api - install/uninstall hook' }
ToButtonType >> regularLabelLookIn: anElement [

self subclassResponsibility
]

{ #category : #'api - install/uninstall hook' }
ToButtonType >> whenAddedToSpace: anEvent in: anElement fromSkin: aSkin [
ToButtonType >> onSkinInstalled: aSkin in: anElement [

| borderLook backgroundLook |
anElement geometry: (BlRoundedRectangleGeometry cornerRadius: anElement toTheme borderRadius).
Expand All @@ -108,7 +96,19 @@ ToButtonType >> whenAddedToSpace: anEvent in: anElement fromSkin: aSkin [
]

{ #category : #'api - install/uninstall hook' }
ToButtonType >> whenRemovedFromSpace: anEvent in: anElement fromSkin: aSkin [
ToButtonType >> onSkinUninstalled: aSkin in: anElement [


]

{ #category : #'api - install/uninstall hook' }
ToButtonType >> regularFormLookIn: anElement [

self subclassResponsibility
]

{ #category : #'api - install/uninstall hook' }
ToButtonType >> regularLabelLookIn: anElement [

self subclassResponsibility
]
21 changes: 10 additions & 11 deletions src/Toplo/ToCheckableSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@ ToCheckableSkin >> indeterminateImageIn: anElement [
^ self subclassResponsibility
]

{ #category : #accessing }
ToCheckableSkin >> uncheckedImageIn: anElement [

^ self subclassResponsibility
]

{ #category : #'api - install/uninstall hook' }
ToCheckableSkin >> whenAddedToSpace: anEvent in: anElement [
ToCheckableSkin >> onSkinInstalledIn: anElement [

super whenAddedToSpace: anEvent in: anElement.
anElement spacingWidth:
anElement toTheme paddingContentHorizontal / 2.
anElement spacingWidth: anElement toTheme paddingContentHorizontal / 2.
anElement icon: (ToImage inner: (anElement isChecked
ifTrue: [ self checkedImageIn: anElement ]
ifFalse: [ self uncheckedImageIn: anElement ])).
Expand All @@ -42,5 +34,12 @@ ToCheckableSkin >> whenAddedToSpace: anEvent in: anElement [
checkedImage: (self checkedImageIn: anElement);
uncheckedImage: (self uncheckedImageIn: anElement);
indeterminateImage: (self indeterminateImageIn: anElement);
yourself)
yourself).
super onSkinInstalledIn: anElement
]

{ #category : #accessing }
ToCheckableSkin >> uncheckedImageIn: anElement [

^ self subclassResponsibility
]
4 changes: 2 additions & 2 deletions src/Toplo/ToCheckboxImageSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
}

{ #category : #'api - install/uninstall hook' }
ToCheckboxImageSkin >> whenAddedToSpace: anEvent in: anElement [
ToCheckboxImageSkin >> onSkinInstalledIn: anElement [

| borderLook |

Expand All @@ -17,6 +17,6 @@ ToCheckboxImageSkin >> whenAddedToSpace: anEvent in: anElement [
width: 1.
self addLook: borderLook.

super whenAddedToSpace: anEvent in: anElement.
super onSkinInstalledIn: anElement

]
11 changes: 11 additions & 0 deletions src/Toplo/ToElementSkinChangedEvent.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToElementSkinChangedEvent,
#superclass : #BlEvent,
#category : #'Toplo-Core-Theme'
}

{ #category : #sending }
ToElementSkinChangedEvent >> sendTo: anObject [

anObject elementSkinChangedEvent: self
]
6 changes: 4 additions & 2 deletions src/Toplo/ToImage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ ToImage >> hasInnerImage [
ToImage >> initialize [

super initialize.

self fitContent.
self innerImage: self defaultInnerImage.
" I ** must be ** considered as a leaf of a UI element tree. Otherwise, click may not work on me. This is why my children are not allowed to manage mouse events. Related to https://github.com/plantec/Toplo/issues/41"
self preventChildrenMouseEvents.
self whenInnerImageChangedDo: [ :new :prev |
self dispatchEvent: (ToInnerImageChangedEvent current: new previous: prev) ]
]

{ #category : #'form accessing' }
Expand Down Expand Up @@ -75,7 +77,7 @@ ToImage >> innerImage: anImage [
]

{ #category : #'api - change hook' }
ToImage >> whenInnerImageReplacedDo: aBlock [
ToImage >> whenInnerImageChangedDo: aBlock [

"set a block to perform after that the image has been changed, and its action performed"

Expand Down
4 changes: 2 additions & 2 deletions src/Toplo/ToImageModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ ToImageModel >> privateWidgetClass [
]

{ #category : #'api - change hook' }
ToImageModel >> whenInnerImageReplacedDo: aBlock [
ToImageModel >> whenInnerImageChangedDo: aBlock [

"set a block to perform after that the image has been changed, and its action performed"

self widgetDo: [ :widget | widget whenInnerImageReplacedDo: aBlock ]
self widgetDo: [ :widget | widget whenInnerImageChangedDo: aBlock ]
]
11 changes: 11 additions & 0 deletions src/Toplo/ToInnerImageChangedEvent.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToInnerImageChangedEvent,
#superclass : #ToElementPropertyChanged,
#category : #'Toplo-Widget-Image'
}

{ #category : #sending }
ToInnerImageChangedEvent >> sendTo: anObject [

anObject innerImageChanged: self
]
2 changes: 1 addition & 1 deletion src/Toplo/ToLabelMultiLineInnerElement.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : #ToLabelMultiLineInnerElement,
#superclass : #BlElement,
#superclass : #ToElement,
#traits : 'TToLabelInnerElement + TObservable + TBlLayoutResizable',
#classTraits : 'TToLabelInnerElement classTrait + TObservable classTrait + TBlLayoutResizable classTrait',
#instVars : [
Expand Down
4 changes: 2 additions & 2 deletions src/Toplo/ToRadioImageSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
}

{ #category : #'api - install/uninstall hook' }
ToRadioImageSkin >> whenAddedToSpace: anEvent in: anElement [
ToRadioImageSkin >> onSkinInstalledIn: anElement [

| borderLook |

Expand All @@ -17,6 +17,6 @@ ToRadioImageSkin >> whenAddedToSpace: anEvent in: anElement [
width: 1.
self addLook: borderLook.

super whenAddedToSpace: anEvent in: anElement.
super onSkinInstalledIn: anElement

]
9 changes: 5 additions & 4 deletions src/Toplo/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,14 @@ ToSandBox class >> example_ToButtonSkins [

space root layout: (BlLinearLayout vertical cellSpacing: 10).

"themeSwitcher := ToChoiceBox new.
themeSwitcher := ToChoiceBox new.
themeSwitcher data addAll: { ToThemeLight. ToThemeDark }.

themeSwitcher whenSelectedIndexChangedDo: [ space toTheme: themeSwitcher selectedData new ].
themeSwitcher selectData: space toTheme class.
space root addChild: themeSwitcher."
space root addChild: themeSwitcher.

space switchThemeDarkOrLight.
"space switchThemeDarkOrLight."

butBuilder := [ ToImage new innerImage: ToThemeIcons iconSearchOutlined16x16 ].
buttonSpecsBuilder := [ {
Expand Down Expand Up @@ -1115,8 +1115,9 @@ ToSandBox class >> example_ToButtonWithPrimarySkin [
space root addChild: button1.
space root when: BlElementAddedToSceneGraphEvent do: [
button1 labelText: 'Primary button 3'.
button1 iconImage: (ToThemeIcons iconSearchOutlined16x16) ].
button1 icon: (ToImage inner: (ToThemeIcons iconSearchOutlined16x16)) ].
space show.

]

{ #category : #button }
Expand Down
28 changes: 14 additions & 14 deletions src/Toplo/ToToggleSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ ToToggleSkin >> buttonLabelChanged: anEvent [

]

{ #category : #'api - install/uninstall hook' }
ToToggleSkin >> onSkinInstalledIn: anElement [

anElement spacingWidth: anElement toTheme paddingContentHorizontal / 2.
anElement geometry: (BlRoundedRectangleGeometry cornerRadius: (self trackBorderRadiusIn: anElement)).
anElement padding: (BlInsets
top: anElement toTheme paddingXS / 2
left: anElement toTheme paddingContentHorizontal
bottom: anElement toTheme paddingXS / 2
right: anElement toTheme paddingContentHorizontal).
self setupTrackElementIn: anElement.
super onSkinInstalledIn: anElement
]

{ #category : #'api - install/uninstall hook' }
ToToggleSkin >> setupTrackElementIn: anElement [

Expand All @@ -58,17 +72,3 @@ ToToggleSkin >> trackBorderRadiusIn: anElement [

^ 26
]

{ #category : #'api - install/uninstall hook' }
ToToggleSkin >> whenAddedToSpace: anEvent in: anElement [

anElement spacingWidth: anElement toTheme paddingContentHorizontal / 2.
anElement geometry: (BlRoundedRectangleGeometry cornerRadius: (self trackBorderRadiusIn: anElement)).
anElement padding: (BlInsets
top: anElement toTheme paddingXS / 2
left: anElement toTheme paddingContentHorizontal
bottom: anElement toTheme paddingXS / 2
right: anElement toTheme paddingContentHorizontal).
self setupTrackElementIn: anElement.
super whenAddedToSpace: anEvent in: anElement
]
Loading

0 comments on commit d453795

Please sign in to comment.