"http://forum.world.st/Roassal2-Application-Matrix-tp4834451.html" "0. set up initial data and mapping" cols := { ''. '> Corporate Services'. '> Customer Relationship' }. rows := { 'Australia'. 'Brazil' }. colors := { 1 -> Color red. 2 -> Color yellow. 3 -> Color paleGreen. 4 -> Color green. } asDictionary. matrix := { { { 'Contract Management' -> 1 }. "1 1" { 'Bonus Card' -> 3. 'Mailsnake' -> 2. 'salesforce Light' -> 4. }. "2 1" }. "* 1 (first row)" { { }. "1 2" { 'Bonus Card' -> 1. 'Mailsnake2' -> 2 } "2 2" "I use lazy RTGroup>>elementsFromModels: so models must be unique, thus Mailsnake2" }. "* 2 (second row)" }. dimensions := matrix size @ matrix anyOne size. "matrix 2 x 2" v := RTView new. "cell sizes; width should be computed from size of the longest label...TRLabelShape>>widthOfText:fontSize:" height := 20. width := 200. "1. create table" boxShape := RTBox new height: 30; width: width. "1.1. create column headings" colHeadings := boxShape color: Color blue; elementsOn: cols. v addAll: colHeadings. colHeadings @ (RTLabelled new center; color: Color white). "1.2. create row headings" rowHeadings := boxShape color: Color lightBlue; elementsOn: rows. v addAll: rowHeadings. rowHeadings @ (RTLabelled new center; color: Color black). "1.3. create cells" cells := boxShape color: Color veryVeryLightGray; elementsOn: (1 to: dimensions x * dimensions y). v addAll: cells. "1.4. create items" items := boxShape height: height; width: width; color: [ :el | colors at: el value ]; elementsOn: matrix flattened. v addAll: items. items @ (RTLabelled new center; color: Color black; text: [ :el | el key ] ). "1.4. adjust height of rows and cells according to the number of elements... this is probably better to do with RTNest>>on:nest:" matrix withIndexDo: [ :line :i | |max| max := line max: [ :cell | cell size ]. (rowHeadings at: i) height: height * max. (((i-1) * dimensions x) + 1 to: (dimensions x * i)) do: [ :j | (cells at: j) height: height * max. ]. ]. "3. layout the table" "3.1. col headings" RTHorizontalLineLayout new gapSize: 1; on: colHeadings. "3.2. row headings" RTVerticalLineLayout new gapSize: 1; on: rowHeadings. rowHeadings translateBy: 0 @ (colHeadings first height + 2). "3.3. cells" RTCellLayout new lineItemsCount: dimensions x; gapSize: 1; on: cells. cells translateBy: 2@2 + (colHeadings first width @ colHeadings first height). "there's a reported bug for RTCellLayout but it probably fell under the radar" (1 to: 2) do: [ :i | (cells at: i) translateBy: -1 @ 0 ]. (2 to: cells size by: 2) do: [ :i | (cells at: i) translateBy: -2 @ 0 ]. (3 to: cells size) do: [ :i | (cells at: i) translateBy: 0 @ 2 ]. "3.4. elements" matrix withIndexDo: [ :line :y | line withIndexDo: [ :cell :x | |els| els := items elementsFromModels: cell. RTVerticalLineLayout new gapSize: 0; on: els. RTLayoutTranslator default translateTopLeftOf: els to: (cells at: ((y - 1) * dimensions x) + x) encompassingRectangle topLeft. ]. ]. v @ RTDraggableView @ RTZoomableView. "v elements @ RTDraggable." v