The Trunk: Morphic-mt.1579.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Morphic-mt.1579.mcz

commits-2
Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.1579.mcz

==================== Summary ====================

Name: Morphic-mt.1579
Author: mt
Time: 16 October 2019, 1:21:29.709451 pm
UUID: bcb586f2-39da-6249-9e9c-545af09d044b
Ancestors: Morphic-mt.1578

Make the lazy list morph also lazy in terms of the icon extent. Only probe the extent of the first icon and then use that for the entire list. This matches the use of a single font to determine the height of the entire list. See #maxHeight.

=============== Diff against Morphic-mt.1578 ===============

Item was changed:
  Morph subclass: #LazyListMorph
+ instanceVariableNames: 'listItems listIcons listFilterOffsets font selectedRow selectedRows preSelectedRow listSource maxWidth columnIndex iconExtent'
- instanceVariableNames: 'listItems listIcons listFilterOffsets font selectedRow selectedRows preSelectedRow listSource maxWidth columnIndex'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Morphic-Widgets'!
 
  !LazyListMorph commentStamp: 'mt 10/13/2019 19:44' prior: 0!
  The morph that displays the list in a PluggableListMorph.  It is "lazy" because it will only request the list items that it actually needs to display.
 
  I will cache the maximum width of my items in maxWidth to avoid this potentially expensive and frequent computation.
 
  The following layout properties are supported:
  - #cellPositioning: #leftCenter [default], #center, #rightCenter
  - #cellInset: [default: 3@0 corner: 3@0]!

Item was changed:
  ----- Method: LazyListMorph>>display:atRow:on: (in category 'drawing') -----
  display: item atRow: row on: canvas
  "display the given item at row row"
 
  | drawBounds emphasized rowColor itemAsText alignment |
  itemAsText := item asStringOrText.
  alignment := self cellPositioning.
 
  "If it is a text, we will only use the first character's emphasis."
  emphasized := itemAsText isText
  ifTrue: [font emphasized: (itemAsText emphasisAt: 1)]
  ifFalse: [font].
 
  rowColor := itemAsText isText
  ifTrue: [itemAsText colorAt: 1 ifNone: [self colorForRow: row]]
  ifFalse: [self colorForRow: row].
 
  drawBounds := self drawBoundsForRow: row.
 
  alignment ~= #leftCenter ifTrue: [
  | itemWidth |
  itemWidth := self widthToDisplayItem: item. "includes left/right margins"
  alignment == #center ifTrue: [
  drawBounds := (self center x - (itemWidth / 2) floor) @ drawBounds top corner: (self center x + (itemWidth / 2) ceiling) @ drawBounds bottom].
  alignment == #rightCenter ifTrue: [
  drawBounds := (self right - itemWidth) @ drawBounds top corner: self right @ drawBounds bottom]].
 
  "Draw icon if existing. Adjust draw bounds in that case."
  drawBounds := drawBounds translateBy: (self cellInset left @ 0).
  (self icon: row) ifNotNil: [ :icon || top |
+ top := drawBounds top + ((drawBounds height - self iconExtent y) // 2).
- top := drawBounds top + ((drawBounds height - icon height) // 2).
  canvas translucentImage: icon at: drawBounds left @ top.
+ drawBounds := drawBounds left: drawBounds left + self iconExtent x + 2 ].
- drawBounds := drawBounds left: drawBounds left + icon width + 2 ].
 
  "We will only draw strings here."
  drawBounds := drawBounds translateBy: (0 @ self cellInset top).
  canvas
  drawString: itemAsText asString
  in: drawBounds
  font: emphasized
  color: rowColor.
 
  "Draw filter matches if any."
  self
  displayFilterOn: canvas
  for: row
  in: drawBounds
  font: emphasized.!

Item was changed:
  ----- Method: LazyListMorph>>icon: (in category 'list access - cached') -----
  icon: row
  "Do inst-var access on listIcons here to initialize it as late as possible."
 
  self listSource canHaveIcons ifFalse: [^ nil].
 
  listIcons ifNil: [listIcons := Array new: self getListSize].
 
  ^ (listIcons at: row) ifNil: [
  | icon |
  icon := (self getListIcon: row) ifNotNil: [:form | form scaleIconToDisplay].
+ "Update cache for uniform icon extent."
+ iconExtent ifNil: [iconExtent := icon ifNotNil: [icon extent]].
  listIcons at: row put: icon.
  icon]!

Item was added:
+ ----- Method: LazyListMorph>>iconExtent (in category 'layout') -----
+ iconExtent
+
+ ^ iconExtent ifNil: [
+ self getListSize = 0
+ ifTrue: [((14@14) * RealEstateAgent scaleFactor) truncated]
+ ifFalse: [(self icon: 1) ifNil: [0@0] ifNotNil: [:form | form extent]]]!

Item was changed:
  ----- Method: LazyListMorph>>layoutChanged (in category 'layout') -----
  layoutChanged
  "See #item:. We have to invalidate listItems or maxWidth will not be updated if you switch hResizing to #shrinkWrap."
 
  listItems := nil.
  maxWidth := nil.
+ iconExtent := nil.
 
  super layoutChanged.!

Item was changed:
  ----- Method: LazyListMorph>>widthToDisplayItem: (in category 'layout') -----
  widthToDisplayItem: item
 
  | labelWidth iconWidth leftMargin rightMargin |
  labelWidth := self font widthOfStringOrText: item asStringOrText.
+ iconWidth := self listSource canHaveIcons ifTrue: [self iconExtent x] ifFalse: [0].
- iconWidth := self listSource canHaveIcons
- ifTrue: [(16 * RealEstateAgent scaleFactor) truncated]
- ifFalse: [0].
  leftMargin := self cellInset left.
  rightMargin := self cellInset right.
  ^ leftMargin + iconWidth + labelWidth + rightMargin!