From 92a5aa04222cea3d13df3f9417c315e142c0742c Mon Sep 17 00:00:00 2001 From: Alain Plantec Date: Wed, 1 Nov 2023 10:48:03 +0100 Subject: [PATCH] removed skin related stuffs in ToLabeledIcon fixed ToElementState>>applyOn: to work well with stillPressed and stillHover --- src/Toplo-Examples/ToSandBox.class.st | 6 +- src/Toplo-Tests/ToElementTest.class.st | 14 +- .../ToLabeledIconEventHandlerTest.class.st | 168 ------------------ src/Toplo-Theme/ToElementState.class.st | 5 +- src/Toplo-Widget-Button/ToButton.class.st | 4 + src/Toplo-Widget-Menu/ToMenuItem.class.st | 10 ++ src/Toplo-Widget-Menu/ToMenuWindow.class.st | 1 + src/Toplo/ToElement.class.st | 5 +- src/Toplo/ToLabeledIcon.class.st | 32 +--- src/Toplo/ToLabeledIconEventHandler.class.st | 34 ---- 10 files changed, 35 insertions(+), 244 deletions(-) delete mode 100644 src/Toplo-Tests/ToLabeledIconEventHandlerTest.class.st delete mode 100644 src/Toplo/ToLabeledIconEventHandler.class.st diff --git a/src/Toplo-Examples/ToSandBox.class.st b/src/Toplo-Examples/ToSandBox.class.st index 2dc2984ea..25497b5b8 100644 --- a/src/Toplo-Examples/ToSandBox.class.st +++ b/src/Toplo-Examples/ToSandBox.class.st @@ -947,7 +947,7 @@ ToSandBox class >> example_ListWithEditableAndContextMenu [ lab beMultiLine. lab beEditable. lab stillPressedStartDelay: 800 milliSeconds. - lab when: ToStillPressedLookEvent do: [ :event | event sourceEvent consumed: true. lab editor ifNotNil: [ :ed | self halt ]. lab addEditorEvent: event]. + lab when: ToStillPressedLookEvent do: [ :event | event consumed: true. lab addEditorEvent: event]. lab whenTextReplacedDo: [ l data at: holder position put: lab text asString ]. node addChild: (ToLabeledIcon new @@ -2347,7 +2347,7 @@ ToSandBox class >> example_stillHoveredEvent [ lab text: count asString asRopedText. count := count + 1. count > 50 ifTrue: [ - event sourceEvent consumed: true. + event consumed: true. count := 0 ] ]. e openInSpace ] @@ -2374,7 +2374,7 @@ ToSandBox class >> example_stillPressedEvent [ count := count + 1. color := color darker. count > 50 ifTrue: [ - event sourceEvent consumed: true. + event consumed: true. count := 0. color := Color white alpha: 0.3] ]. e openInSpace diff --git a/src/Toplo-Tests/ToElementTest.class.st b/src/Toplo-Tests/ToElementTest.class.st index 8c33a3bd9..a3d004b77 100644 --- a/src/Toplo-Tests/ToElementTest.class.st +++ b/src/Toplo-Tests/ToElementTest.class.st @@ -213,9 +213,9 @@ ToElementTest >> testWithoutSkin [ ] { #category : 'test initialize' } -ToElementTest >> testWithoutSkinContamination [ +ToElementTest >> testWithoutSkinNonContamination [ - " NullSkin is contaminant: check if children are correctly impacted (withoutSkin must be applied recursively)" + " NullSkin is not contaminant: check if children are not impacted " | e child childchild | @@ -238,13 +238,13 @@ ToElementTest >> testWithoutSkinContamination [ self assert: e skinInstaller isNil. self assert: e installedSkin isNullSkin. self assert: child skinInstaller isNil. - self assert: child installedSkin isNullSkin. + self assert: child installedSkin isNil. self assert: childchild skinInstaller isNil. - self assert: childchild installedSkin isNullSkin + self assert: childchild installedSkin isNil ] { #category : 'test initialize' } -ToElementTest >> testWithoutSkinContamination2 [ +ToElementTest >> testWithoutSkinNonContamination2 [ " check if children are correctly impacted when they are added as child of their parent (withoutSkin must be applied when a child is added )" @@ -267,7 +267,7 @@ ToElementTest >> testWithoutSkinContamination2 [ child applySkinInstaller. childchild applySkinInstaller. self assert: child skinInstaller isNil. - self assert: child installedSkin isNullSkin. + self assert: child installedSkin isNil. self assert: childchild skinInstaller isNil. - self assert: childchild installedSkin isNullSkin + self assert: childchild installedSkin isNil ] diff --git a/src/Toplo-Tests/ToLabeledIconEventHandlerTest.class.st b/src/Toplo-Tests/ToLabeledIconEventHandlerTest.class.st deleted file mode 100644 index 65c6ffd9a..000000000 --- a/src/Toplo-Tests/ToLabeledIconEventHandlerTest.class.st +++ /dev/null @@ -1,168 +0,0 @@ -" -A ToLabeledIconEventHandlerTest is a test class for testing the behavior of ToLabeledIconEventHandler -" -Class { - #name : 'ToLabeledIconEventHandlerTest', - #superclass : 'TestCase', - #category : 'Toplo-Tests-Core', - #package : 'Toplo-Tests', - #tag : 'Core' -} - -{ #category : 'layout constraints' } -ToLabeledIconEventHandlerTest >> testDirection [ - - | li | - li := ToLabeledIcon new. - li beLeftToRight. - li skinInstaller: nil. - li direction: BlLayoutDirection rightToLeft. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li direction: BlLayoutDirection rightToLeft. - self assert: li skinInstaller isNil. - - li skinInstaller: nil. - li direction: BlLayoutDirection leftToRight. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li direction: BlLayoutDirection leftToRight. - self assert: li skinInstaller isNil. - - -] - -{ #category : 'layout constraints' } -ToLabeledIconEventHandlerTest >> testLayoutDirectionChangedEvent [ - - | li | - li := ToLabeledIcon new. - li beLeftToRight. - li beRightToLeft. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li beLeftToRight. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li leftToRight: false. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li leftToRight: true. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li rightToLeft: true. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li rightToLeft: false. - self assert: li skinInstaller notNil. - li skinInstaller: nil - -] - -{ #category : 'layout constraints' } -ToLabeledIconEventHandlerTest >> testLayoutOrientationChangedEvent [ - - | li | - li := ToLabeledIcon new. - li beHorizontal. - li beVertical. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li beHorizontal. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li vertical: true. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li vertical: false. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li horizontal: false. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li horizontal: true. - self assert: li skinInstaller notNil. - li skinInstaller: nil - -] - -{ #category : 'layout constraints' } -ToLabeledIconEventHandlerTest >> testOrientation [ - - | li | - li := ToLabeledIcon new. - li beLeftToRight. - li skinInstaller: nil. - li orientation: BlLinearLayoutVerticalOrientation new. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li orientation: BlLinearLayoutVerticalOrientation new. - self assert: li skinInstaller isNil. - - li skinInstaller: nil. - li orientation: BlLinearLayoutHorizontalOrientation new. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - li orientation: BlLinearLayoutHorizontalOrientation new. - self assert: li skinInstaller isNil. - - -] - -{ #category : 'layout constraints' } -ToLabeledIconEventHandlerTest >> testlayoutConstraintsChangedEvent [ - - | li | - li := ToLabeledIcon new. - li exact: 10@10. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li fitContent. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li fitContentLimited. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li hExact:20. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li hFitContent. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li hFitContentLimited. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li hMatchParent. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li matchParent. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li vExact: 20. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li vFitContent. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li vFitContentLimited. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - li vMatchParent. - self assert: li skinInstaller notNil. - li skinInstaller: nil. - self assert: li skinInstaller isNil. - - - -] diff --git a/src/Toplo-Theme/ToElementState.class.st b/src/Toplo-Theme/ToElementState.class.st index 01e0618f5..c118e7df8 100644 --- a/src/Toplo-Theme/ToElementState.class.st +++ b/src/Toplo-Theme/ToElementState.class.st @@ -18,7 +18,10 @@ ToElementState class >> sourceEvent: anEvent [ { #category : 'look event sending' } ToElementState >> applyOn: anElement [ - anElement dispatchLookEvent: (self newLookEventFromSourceEvent: self sourceEvent) + | lookEvent | + lookEvent := self newLookEventFromSourceEvent: self sourceEvent. + anElement dispatchLookEvent: lookEvent. + lookEvent isConsumed ifTrue: [ self sourceEvent consumed: true ] ] { #category : 'skin state engine' } diff --git a/src/Toplo-Widget-Button/ToButton.class.st b/src/Toplo-Widget-Button/ToButton.class.st index c5629238b..dd1024236 100644 --- a/src/Toplo-Widget-Button/ToButton.class.st +++ b/src/Toplo-Widget-Button/ToButton.class.st @@ -15,6 +15,10 @@ Class { ToButton >> initialRawStyle [ super initialRawStyle. + self labeledIcon childrenDo: [ :child | + child constraintsDo: [ :c | + c linear vertical alignCenter. + c linear horizontal alignCenter ] ]. ((self parent isKindOf: ToMenuItem) and: [ self parent isTopMenu not ]) ifTrue: [ ^ self ]. (self hasIcon and: [ self hasLabel ]) ifFalse: [ diff --git a/src/Toplo-Widget-Menu/ToMenuItem.class.st b/src/Toplo-Widget-Menu/ToMenuItem.class.st index c67e0a44b..eefb0fc19 100644 --- a/src/Toplo-Widget-Menu/ToMenuItem.class.st +++ b/src/Toplo-Widget-Menu/ToMenuItem.class.st @@ -30,6 +30,16 @@ ToMenuItem >> filler [ ^ filler ] +{ #category : 'skin' } +ToMenuItem >> initialRawStyle [ + + super initialRawStyle. + self labeledIcon childrenDo: [ :child | + child constraintsDo: [ :c | + c linear vertical alignCenter. + c linear horizontal alignCenter ] ]. +] + { #category : 'initialization' } ToMenuItem >> initialize [ diff --git a/src/Toplo-Widget-Menu/ToMenuWindow.class.st b/src/Toplo-Widget-Menu/ToMenuWindow.class.st index 31b3472fd..2a36dc617 100644 --- a/src/Toplo-Widget-Menu/ToMenuWindow.class.st +++ b/src/Toplo-Widget-Menu/ToMenuWindow.class.st @@ -13,6 +13,7 @@ Class { ToMenuWindow >> close [ openedSubmenuWindow ifNotNil: [ :w | w close ]. + self root removeChildren. super close ] diff --git a/src/Toplo/ToElement.class.st b/src/Toplo/ToElement.class.st index 967031747..ccd6b276c 100644 --- a/src/Toplo/ToElement.class.st +++ b/src/Toplo/ToElement.class.st @@ -86,10 +86,7 @@ ToElement >> onAddedToParent [ super onAddedToParent. self hasEnablementFlag ifFalse: [ - self enabled: self parent isEnabled ]. - self parent isWithoutSkin - ifFalse: [ self parent requestSkin ] - ifTrue: [ self withoutSkin ] + self enabled: self parent isEnabled ] ] { #category : 'hooks - children' } diff --git a/src/Toplo/ToLabeledIcon.class.st b/src/Toplo/ToLabeledIcon.class.st index c12f09d2b..750052395 100644 --- a/src/Toplo/ToLabeledIcon.class.st +++ b/src/Toplo/ToLabeledIcon.class.st @@ -31,12 +31,6 @@ ToLabeledIcon >> beLabelFirst [ self requestLayout ] -{ #category : 'accessing' } -ToLabeledIcon >> defaultEventHandler [ - - ^ ToLabeledIconEventHandler new -] - { #category : 'initialization' } ToLabeledIcon >> defaultLayout [ @@ -94,9 +88,7 @@ ToLabeledIcon >> icon: anElement [ self icon ifNotNil: [ :s | self icon removeFromParent ]. icon := anElement. anElement ifNil: [ ^ self ]. - self iconHolder addChild: anElement. - self requestSkin - + self iconHolder addChild: anElement ] { #category : 'configurating' } @@ -180,18 +172,7 @@ ToLabeledIcon >> initialize [ self addChild: filler. self addChild: labelHolder. self beIconFirst. - self fitContent. - self addEventHandler: self defaultEventHandler -] - -{ #category : 'skin' } -ToLabeledIcon >> installRawStyle [ - - super installRawStyle. - self childrenDo: [ :child | - child constraintsDo: [ :c | - c linear vertical alignCenter. - c linear horizontal alignCenter ] ] + self fitContent ] { #category : 'accessing' } @@ -211,8 +192,7 @@ ToLabeledIcon >> interspace: aPoint [ self filler constraints minWidth: size x; minHeight: size y. - self filler requestLayout. - self requestSkin + self filler requestLayout ] { #category : 'testing' } @@ -246,8 +226,7 @@ ToLabeledIcon >> label: anElement [ self label ifNotNil: [ :s | s removeFromParent]. label := anElement. anElement ifNil: [ ^ self ]. - self labelHolder addChild: anElement. - self requestSkin + self labelHolder addChild: anElement ] { #category : 'configurating' } @@ -277,6 +256,5 @@ ToLabeledIcon >> layoutStrategy [ { #category : 'accessing' } ToLabeledIcon >> rightLabelAlignment: anInteger [ - self iconHolderWidth: anInteger. - self requestSkin + self iconHolderWidth: anInteger ] diff --git a/src/Toplo/ToLabeledIconEventHandler.class.st b/src/Toplo/ToLabeledIconEventHandler.class.st deleted file mode 100644 index 174a4eb0d..000000000 --- a/src/Toplo/ToLabeledIconEventHandler.class.st +++ /dev/null @@ -1,34 +0,0 @@ -Class { - #name : 'ToLabeledIconEventHandler', - #superclass : 'BlCustomEventHandler', - #category : 'Toplo-Core', - #package : 'Toplo', - #tag : 'Core' -} - -{ #category : 'api - accessing' } -ToLabeledIconEventHandler >> eventsToHandle [ - - ^ { - ToLayoutDirectionChangedEvent. - ToLayoutOrientationChangedEvent. - ToLayoutConstraintsChangedEvent } -] - -{ #category : 'events handling' } -ToLabeledIconEventHandler >> layoutConstraintsChangedEvent: anEvent [ - - anEvent currentTarget requestSkin -] - -{ #category : 'events handling' } -ToLabeledIconEventHandler >> layoutDirectionChangedEvent: anEvent [ - - anEvent currentTarget requestSkin -] - -{ #category : 'events handling' } -ToLabeledIconEventHandler >> layoutOrientationChangedEvent: anEvent [ - - anEvent currentTarget requestSkin -]