Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SpSelectDialog for handling line splitting texts #1533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Spec2-Adapters-Morphic/SpStyle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ SpStyle class >> defaultStyleSheetData [
.lines8 [ Geometry { #minHeight: 160, #height: 160 } ] ],
.textInputField [ Geometry { #height: 24, #minHeight: 24 } ],
.textSearchField [ Geometry { #height: 24, #minHeight: 24 } ],
.textDisabled [ Draw { #backgroundColor: EnvironmentColor(#window) } ],
.code [ Font { #name: EnvironmentFont(#code) } ],
.codeLight [ Draw { #backgroundColor: #white } ],
.codeDark [ Draw { #backgroundColor: #212121 } ],
Expand Down
43 changes: 30 additions & 13 deletions src/Spec2-Dialogs/SpSelectDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ SpSelectDialog class >> defaultExtent [
^ 450@300
]

{ #category : 'layout' }
SpSelectDialog class >> defaultLayout [

^ SpBoxLayout newTopToBottom
borderWidth: 5;
spacing: 5;
add: #label expand: false;
add: #list;
yourself
]

{ #category : 'documentation' }
SpSelectDialog class >> documentFactoryMethodSelector [

Expand Down Expand Up @@ -84,6 +73,18 @@ SpSelectDialog >> acceptLabel: aString [
acceptLabel := aString
]

{ #category : 'private' }
SpSelectDialog >> calculateLabelHeight [

| labelText |
labelText := label text.

labelText ifEmpty: [ ^ TextStyle defaultFont height ].

^ (labelText lineHeightsWrappingAtWidth: self extent y - 20) sum + 20

]

{ #category : 'api' }
SpSelectDialog >> cancelLabel [

Expand All @@ -96,6 +97,17 @@ SpSelectDialog >> cancelLabel: aString [
cancelLabel := aString
]

{ #category : 'layout' }
SpSelectDialog >> defaultLayout [

^ SpBoxLayout newTopToBottom
borderWidth: 5;
spacing: 5;
add: #label height: self calculateLabelHeight;
add: #list;
yourself
]

{ #category : 'api' }
SpSelectDialog >> display: aBlock [

Expand Down Expand Up @@ -139,7 +151,12 @@ SpSelectDialog >> initializeDialogWindow: aDialogWindowPresenter [
{ #category : 'initialization' }
SpSelectDialog >> initializePresenters [

label := self newLabel.
label := self newText
beNotEditable;
withoutScrollBars;
addStyle: 'textDisabled';
yourself.

list := self newList.

list addStyle: 'spSelectList'.
Expand Down Expand Up @@ -172,7 +189,7 @@ SpSelectDialog >> items: aCollection [
{ #category : 'api' }
SpSelectDialog >> label: aString [

label label: aString
label text: aString asText trim
]

{ #category : 'api - showing' }
Expand Down
27 changes: 27 additions & 0 deletions src/Spec2-Dialogs/Text.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Extension { #name : 'Text' }

{ #category : '*Spec2-Dialogs' }
Text >> lineHeightsWrappingAtWidth: aMaxWidth [

| lineWidth maxLineHeight font |

lineWidth := 0.
maxLineHeight := 0.

^ Array streamContents: [ :stream |
self withIndexDo: [ :aCharacter :anIndex |
font := self fontAt: anIndex.
lineWidth := lineWidth + (font widthOf: aCharacter).

(lineWidth > aMaxWidth or: [ aCharacter = Character cr ])
ifTrue: [
stream nextPut: maxLineHeight.
lineWidth := font widthOf: aCharacter.
].

maxLineHeight := maxLineHeight max: font height.
].

stream nextPut: maxLineHeight
]
]
Loading