diff --git a/src/Spec2-Adapters-Morphic/SpMorphicTableCellBuilder.class.st b/src/Spec2-Adapters-Morphic/SpMorphicTableCellBuilder.class.st index 0d175c1b..fc0d568b 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicTableCellBuilder.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicTableCellBuilder.class.st @@ -22,12 +22,31 @@ SpMorphicTableCellBuilder class >> on: aDataSource [ { #category : 'private' } SpMorphicTableCellBuilder >> addAlignmentColumn: aTableColumn item: item to: content [ + | block containerMorph alignment | - aTableColumn displayAlignment ifNotNil: [ :block | - ^ content asText addAttribute: (block cull: item) asTextAlignment ]. - - ^ content + (block := aTableColumn displayAlignment) ifNil: [ ^ content ]. + + alignment := (block cull: item) asTextAlignment. + containerMorph := Morph new + color: Color transparent; + layoutPolicy: TableLayout new; + hResizing: #spaceFill; + vResizing: #spaceFill; + borderWidth: 0; + yourself. + + alignment = TextAlignment rightFlush ifTrue: [ + containerMorph listDirection: #rightToLeft ]. + alignment = TextAlignment leftFlush ifTrue: [ + containerMorph listDirection: #leftToRight ]. + + alignment = TextAlignment centered + ifTrue: [ containerMorph addMorphBack: self newFillerMorph ]. + containerMorph addMorphBack: content asMorph asReadOnlyMorph. + alignment = TextAlignment centered + ifTrue: [ containerMorph addMorphBack: self newFillerMorph ]. + ^ containerMorph ] { #category : 'private' } @@ -146,6 +165,17 @@ SpMorphicTableCellBuilder >> item [ ^ self dataSource elementAt: self rowIndex ] +{ #category : 'private' } +SpMorphicTableCellBuilder >> newFillerMorph [ + "This is used as a helper to center text when applying alignment=centered" + + ^ Morph new + color: Color transparent; + hResizing: #spaceFill; + vResizing: #spaceFill; + yourself +] + { #category : 'accessing' } SpMorphicTableCellBuilder >> rowIndex [ ^ rowIndex @@ -268,7 +298,6 @@ SpMorphicTableCellBuilder >> visitStringColumn: aTableColumn [ content := aTableColumn readObject: item. "add properties" - content := self addAlignmentColumn: aTableColumn item: item to: content. content := self addColorColumn: aTableColumn item: item to: content. content := self addItalicColumn: aTableColumn item: item to: content. content := self addBoldColumn: aTableColumn item: item to: content. @@ -277,9 +306,12 @@ SpMorphicTableCellBuilder >> visitStringColumn: aTableColumn [ aTableColumn isEditable ifTrue: [ self visitStringColumnEditable: aTableColumn on: content ] ifFalse: [ "add cell" + "I need to calculate here alignement because I will wrap the content + into a container morph, so it needs to be the last one before applying" + content := self addAlignmentColumn: aTableColumn item: item to: content. self addCell: content column: aTableColumn. "add background (this is a special case of properties, - since background needs to be applied to the cell and not to the text)" + since background needs to be applied to the cell and not to the text)" self addBackgroundColorColumn: aTableColumn item: item toMorph: cell ] ] diff --git a/src/Spec2-Examples/SpTablePresenter.extension.st b/src/Spec2-Examples/SpTablePresenter.extension.st index 2d863414..c05797a8 100644 --- a/src/Spec2-Examples/SpTablePresenter.extension.st +++ b/src/Spec2-Examples/SpTablePresenter.extension.st @@ -96,6 +96,23 @@ SpTablePresenter class >> exampleSorting [ open ] +{ #category : '*Spec2-Examples' } +SpTablePresenter class >> exampleWithColumnAlignment [ + "Shows how we can align columns" + | column | + + column := SpStringTableColumn new + title: 'Alignments'; + evaluated: [ :object | object ]; + displayAlignment: [ :object | SpColumnAlignment perform: object ]; + yourself. + + SpTablePresenter new + items: { #right. #center. #left }; + addColumn: column; + open +] + { #category : '*Spec2-Examples' } SpTablePresenter class >> exampleWithColumnHeaders [