Skip to content

Commit

Permalink
fixe right label alignment of a choice menu item that was not set at …
Browse files Browse the repository at this point in the history
…first popup
  • Loading branch information
plantec committed Feb 14, 2024
1 parent dafa575 commit 8e22bc5
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 73 deletions.
26 changes: 25 additions & 1 deletion src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,7 @@ ToSandBox class >> example_themeChoiceButton [
win := ToInnerWindow new title: 'Some host'.
themeSelect := ToChoiceMenu new.
themeSelect withStrictCheckingStrategy.
themeSelect defaultSelectedIndex: 3.
themeSelect defaultSelectedIndex: 4.
themeSelect dataToTextConverter: [ :assoc | assoc key ].
themeSelect data addAll: {
('Bee Light' -> ToBeeTheme new).
Expand All @@ -2862,6 +2862,30 @@ ToSandBox class >> example_themeChoiceButton [
space show
]

{ #category : #'choice menu' }
ToSandBox class >> example_themeChoiceButton2 [

| win themeSelect space |
space := BlSpace new.
win := ToInnerWindow new title: 'Some host'.
themeSelect := ToChoiceMenu new.
themeSelect withStrictCheckingStrategy.
themeSelect defaultSelectedIndex: 1.
themeSelect dataToTextConverter: [ :assoc | assoc key ].
themeSelect data addAll: {
"('Bee Light' -> ToBeeTheme new).
('Bee Dark' -> ToBeeDarkTheme new)."
('Raw Light' -> ToRawTheme new).
"('Raw Dark' -> ToRawDarkTheme new)" }.
themeSelect inspect.
themeSelect addEventHandler: (BlEventHandler
on: ToChoiceChangedEvent
do: [ space toTheme: themeSelect selectedData value ]).

space root addChild: themeSelect.
space show
]

{ #category : #checkbox }
ToSandBox class >> example_themeSelectPlusCheckbox [

Expand Down
80 changes: 80 additions & 0 deletions src/Toplo-Widget-Menu-Tests/ToChoiceMenuInSpaceTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Class {
#name : #ToChoiceMenuInSpaceTest,
#superclass : #ToParameterizedHostTest,
#category : #'Toplo-Widget-Menu-Tests-Choice menu'
}

{ #category : #tests }
ToChoiceMenuInSpaceTest >> testChoiceItemRightLabelAlignmentOnFirstPopup [

| win themeSelect choiceItem ralign |
win := ToInnerWindow new.
themeSelect := ToChoiceMenu new.
themeSelect withStrictCheckingStrategy.
themeSelect defaultSelectedIndex: 1.
themeSelect dataToTextConverter: [ :assoc | assoc key ].
themeSelect data addAll: {
('Raw Light' -> ToRawTheme new). }.
themeSelect addEventHandler: (BlEventHandler
on: ToChoiceChangedEvent
do: [ space toTheme: themeSelect selectedData value ]).
space root addChild: themeSelect.
BlSpace simulateClickOn: themeSelect.
self waitTestingSpaces.
space applyAllSkinInstallers.
self assert: themeSelect menuWindow notNil.
choiceItem := themeSelect menuWindow root firstChild.
self assert: choiceItem icon notNil.
ralign := choiceItem valueOfTokenNamed: #'menu-item-right-label-alignment'.
self assert: ralign notNil.
self assert: choiceItem rightLabelAlignment equals: ralign.

]

{ #category : #tests }
ToChoiceMenuInSpaceTest >> testWithStructuredDataWithStrictStrategy [

| cb d |
cb := ToChoiceMenu new.
cb withStrictCheckingStrategy.
cb defaultSelectedIndex: 2.
cb dataToTextConverter: [ :assoc | assoc key ].
cb data addAll: (d := {
('Bee Theme' -> ToBeeTheme).
('Raw Theme' -> ToRawTheme) }).
space root addChild: cb.

cb addEventHandler: (BlEventHandler
on: ToChoiceSelectedIndexChangeEvent
do: [ cb selectedData ifNotNil: [:data | space toTheme: (data value new) ] ] ).

cb selectIndex: 1.
self waitTestingSpaces.
self assert: cb selectedData value identicalTo: ToBeeTheme.
self assert: cb label text asString equals: d first key.
self should: [cb selectData: nil] raise: Error.
self assert: cb selectedIndex equals: 1.
self assert: cb label text asString equals: d first key.
self assert: (cb group buttons select: [ :b | b checked ]) size equals: 1
]

{ #category : #tests }
ToChoiceMenuInSpaceTest >> testWithStructuredDataWithUncheckingStrategy [

| cb d |
cb := ToChoiceMenu new.
cb withUncheckingStrategy.
space root addChild: cb.
cb dataToTextConverter: [ :assoc | assoc key ].
cb data addAll: (d := {
('Bee Theme' -> ToBeeTheme).
('Raw Theme' -> ToRawTheme) }).
cb selectIndex: 1.
self waitTestingSpaces.
self assert: cb selectedData value identicalTo: ToBeeTheme.
self assert: cb label text asString equals: d first key.
cb selectData: nil.
self assert: cb selectedData isNil.
self assert: cb label isNil.
self assert: (cb group buttons noneSatisfy: [ :b | b checked ])
]
48 changes: 0 additions & 48 deletions src/Toplo-Widget-Menu-Tests/ToChoiceMenuTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -398,54 +398,6 @@ ToChoiceMenuTest >> testWithStrictStrategy [
self assert: cb group buttons first checked
]

{ #category : #tests }
ToChoiceMenuTest >> testWithStructuredDataWithStrictStrategy [

| space cb d |
space := BlSpace new.
cb := ToChoiceMenu new.
cb withStrictCheckingStrategy.
cb defaultSelectedIndex: 2.
cb dataToTextConverter: [ :assoc | assoc key ].
cb data addAll: (d := {
('Bee Theme' -> ToBeeTheme).
('Raw Theme' -> ToRawTheme) }).
space root addChild: cb.

cb addEventHandler: (BlEventHandler
on: ToChoiceSelectedIndexChangeEvent
do: [ cb selectedData ifNotNil: [:data | space toTheme: (data value new) ] ] ).

cb selectIndex: 1.
self assert: cb selectedData value identicalTo: ToBeeTheme.
self assert: cb label text asString equals: d first key.
self should: [cb selectData: nil] raise: Error.
self assert: cb selectedIndex equals: 1.
self assert: cb label text asString equals: d first key.
self assert: (cb group buttons select: [ :b | b checked ]) size equals: 1
]

{ #category : #tests }
ToChoiceMenuTest >> testWithStructuredDataWithUncheckingStrategy [

| space cb d |
space := BlSpace new.
cb := ToChoiceMenu new.
cb withUncheckingStrategy.
space root addChild: cb.
cb dataToTextConverter: [ :assoc | assoc key ].
cb data addAll: (d := {
('Bee Theme' -> ToBeeTheme).
('Raw Theme' -> ToRawTheme) }).
cb selectIndex: 1.
self assert: cb selectedData value identicalTo: ToBeeTheme.
self assert: cb label text asString equals: d first key.
cb selectData: nil.
self assert: cb selectedData isNil.
self assert: cb label isNil.
self assert: (cb group buttons noneSatisfy: [ :b | b checked ])
]

{ #category : #tests }
ToChoiceMenuTest >> testWithUncheckStrategy [

Expand Down
4 changes: 3 additions & 1 deletion src/Toplo-Widget-Menu/ToCheckMenuItemSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ ToCheckMenuItemSkin >> installLookEvent: anEvent [
anEvent elementDo: [ :e |
e iconImage: ((e valueOfTokenNamed: #'checkbox-image-builder') value).
e icon geometry: (self iconGeometryIn: e).
e button rightLabelAlignment: (e valueOfTokenNamed: #'menu-item-right-label-alignment').
e border: (e valueOfTokenNamed: #'color-border-checkable').
e icon border: (e valueOfTokenNamed: #'color-border') ]
e icon border: (e valueOfTokenNamed: #'color-border') ].


]

Expand Down
7 changes: 0 additions & 7 deletions src/Toplo-Widget-Menu/ToChoiceItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,3 @@ ToChoiceItem >> data: anObject [

data := anObject
]

{ #category : #skin }
ToChoiceItem >> installRawStyle [

super installRawStyle.
self button rightLabelAlignment: 30
]
10 changes: 5 additions & 5 deletions src/Toplo-Widget-Menu/ToChoiceMenuSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#category : #'Toplo-Widget-Menu-Choice menu'
}

{ #category : #'as yet unclassified' }
{ #category : #'event handling' }
ToChoiceMenuSkin >> disabledLookEvent: anEvent [

super disabledLookEvent: anEvent.
Expand All @@ -14,7 +14,7 @@ ToChoiceMenuSkin >> disabledLookEvent: anEvent [
width: (e valueOfTokenNamed: #'line-width')) ]
]

{ #category : #'as yet unclassified' }
{ #category : #'event handling' }
ToChoiceMenuSkin >> enabledLookEvent: anEvent [

super enabledLookEvent: anEvent.
Expand All @@ -24,7 +24,7 @@ ToChoiceMenuSkin >> enabledLookEvent: anEvent [
width: (e valueOfTokenNamed: #'line-width')) ]
]

{ #category : #'as yet unclassified' }
{ #category : #'event handling' }
ToChoiceMenuSkin >> hoveredLookEvent: anEvent [

super hoveredLookEvent: anEvent.
Expand All @@ -46,7 +46,7 @@ ToChoiceMenuSkin >> installLookEvent: anEvent [
e icon: (ToImage inner: (self iconNamed: #bottom)) ]
]

{ #category : #'as yet unclassified' }
{ #category : #'event handling' }
ToChoiceMenuSkin >> leavedLookEvent: anEvent [

super leavedLookEvent: anEvent.
Expand All @@ -56,7 +56,7 @@ ToChoiceMenuSkin >> leavedLookEvent: anEvent [
width: (e valueOfTokenNamed: #'line-width')) ]
]

{ #category : #'as yet unclassified' }
{ #category : #'event handling' }
ToChoiceMenuSkin >> pressedLookEvent: anEvent [

super pressedLookEvent: anEvent.
Expand Down
9 changes: 5 additions & 4 deletions src/Toplo-Widget-Menu/ToMenuItemSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ ToMenuItemSkin >> installLookEvent: anEvent [
e isTopMenu ifFalse: [
e parentMenuDo: [ :pm |
(pm items anySatisfy: [ :mi | mi hasIcon ]) ifTrue: [
e button rightLabelAlignment: 25 ] ] ].
e iconDo: [ :ic | ic formColor: (e valueOfTokenNamed: #'color-text') ].
e button rightLabelAlignment:
(e valueOfTokenNamed: #'menu-item-right-label-alignment') ] ] ].
e iconDo: [ :ic |
ic formColor: (e valueOfTokenNamed: #'color-text') ].
e labelDo: [ :lab |
lab text attributes:
{ (BlTextForegroundAttribute paint:
lab text attributes: { (BlTextForegroundAttribute paint:
(e valueOfTokenNamed: #'color-text')) }.
lab textChanged ] ]
]
Expand Down
6 changes: 6 additions & 0 deletions src/Toplo/TToElementWithLabeledIcon.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ TToElementWithLabeledIcon >> labeledIcon [
^ self explicitRequirement
]

{ #category : #'t - element with labeled icon - accessing' }
TToElementWithLabeledIcon >> rightLabelAlignment [

^ self labeledIcon rightLabelAlignment
]

{ #category : #'t - element with labeled icon - accessing' }
TToElementWithLabeledIcon >> rightLabelAlignment: anInteger [

Expand Down
3 changes: 1 addition & 2 deletions src/Toplo/ToAnchoredWindow.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ ToAnchoredWindow >> popupEvent: anEvent [
Error signal:
'Can''t popup an anchored window if the element is not attached to a space' ].
"self visibility: BlVisibility hidden. "
self localTheme ifNil: [
self localTheme: self element toTheme ].
self localTheme ifNil: [ self localTheme: self element toTheme ].
self anchorRoot addChild: self.
popupTimestamp := DateAndTime now.
self toFront.
Expand Down
6 changes: 6 additions & 0 deletions src/Toplo/ToLabeledIcon.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ ToLabeledIcon >> layoutStrategy [
^ self layout
]

{ #category : #accessing }
ToLabeledIcon >> rightLabelAlignment [

^ self iconContainerWidth
]

{ #category : #accessing }
ToLabeledIcon >> rightLabelAlignment: anInteger [

Expand Down
11 changes: 6 additions & 5 deletions src/Toplo/ToTheme.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ToTheme class >> defaultTokenProperties [
(ToTokenProperty name: #'border-radius-LG' value: 8).
(ToTokenProperty name: #'border-radius-SM' value: 4).

(ToTokenProperty
(ToTokenProperty
name: #'double-click-delay'
value: 250 milliSeconds).

Expand Down Expand Up @@ -132,8 +132,7 @@ ToTheme class >> defaultTokenProperties [
value: self defaultColorPrimary darker darker).
(ToTokenProperty
name: #'color-primary-hover'
value:
(self defaultColorPrimary lighter lighter)).
value: self defaultColorPrimary lighter lighter).

(ToTokenProperty
name: #'color-success'
Expand Down Expand Up @@ -220,7 +219,9 @@ ToTheme class >> defaultTokenProperties [

(ToTokenProperty name: #'text-editor-padding-H' value: 3).
(ToTokenProperty name: #'text-editor-padding-V' value: 2).

(ToTokenProperty
name: #'menu-item-right-label-alignment'
value: 25).
(ToTokenProperty
name: #'checkbox-image-builder'
value: [ self defaultCheckboxBlankImage ]).
Expand Down Expand Up @@ -254,7 +255,7 @@ ToTheme class >> defaultTokenProperties [
(ToTokenProperty
name: #'border-color-primary-selection'
value: self defaultColorPrimary).
(ToTokenProperty
(ToTokenProperty
name: #'list-context-menu-selection-border-gap'
value: 1.0) }
]
Expand Down

0 comments on commit 8e22bc5

Please sign in to comment.