Skip to content

Commit

Permalink
I am making progress with the tree view morph.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronsaldo committed Nov 29, 2023
1 parent 2e744c1 commit 23d40d2
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 34 deletions.
9 changes: 9 additions & 0 deletions package-sources/Bootstrap.EnvironmentSetup/Function.sysmel
Expand Up @@ -92,4 +92,13 @@ Function
withSelector: #makeNoGC addMethod: {:(Function)self :: Function |
self addFlags: FunctionFlags::NoGC.
self
} withEagerAnalysis;
withSelector: #validPrimitiveName addMethod: {:(Function)self :: Symbol |
if: (self __slotNamedAt__: #captureEnvironment) == __pendingMemoizationValue__ then: {
let: #definition type: AnyValue with: (self __slotNamedAt__: #definition).
definition primitiveName
} else: {
self ensureAnalysis.
self __slotNamedAt__: #primitiveName
}.
} withEagerAnalysis.
4 changes: 2 additions & 2 deletions package-sources/Core.Runtime/BaseBootstrap/AST.sysmel
Expand Up @@ -254,8 +254,8 @@ ASTLiteralNode
else: false
} makeOverride;
withSelector: #literalFunctionPrimitiveName addMethod: {:(ASTLiteralNode)self :: Symbol |
if: (self value __type__ lookupSelector: #primitiveName) ~~ nil
then: (self value ensureAnalysis; primitiveName)
if: (self value __type__ lookupSelector: #validPrimitiveName) ~~ nil
then: (self value validPrimitiveName)
else: nil
} makeOverride.

Expand Down
6 changes: 6 additions & 0 deletions package-sources/Graphics.Font/FontFace.sysmel
Expand Up @@ -15,9 +15,15 @@ public abstract class FontFace definition: {
public virtual method measureWidthForString: (string: SequenceableCollection) from: (startIndex: Size) until: (endIndex: Size) ::=> Float32
:= startIndex < endIndex ifTrue: (endIndex - startIndex) asFloat32 * self width ifFalse: 0f32.

public virtual method measureWidthForString: (string: SequenceableCollection) ::=> Float32
:= self measureWidthForString: string from: 0sz until: string size.

public virtual method measureExtentForString: (string: SequenceableCollection) from: (startIndex: Size) until: (endIndex: Size) ::=> Float32x2
:= (self measureWidthForString: string from: startIndex until: endIndex) @ self height.

public virtual method measureExtentForString: (string: SequenceableCollection) ::=> Float32x2
:= self measureExtentForString: string from: 0sz until: string size.

public virtual method measureBoundsForString: (string: SequenceableCollection) from: (startIndex: Size) until: (endIndex: Size) ::=> RectangleF32
:= 0f32x2 extent: (self measureExtentForString: string from: startIndex until: endIndex).
}.
26 changes: 26 additions & 0 deletions package-sources/Morphic.Core/BasicDevelopmentEnvironment.sysmel
@@ -0,0 +1,26 @@
public class BasicDevelopmentEnvironment superclass: PanelMorph; definition: {
public override method initialize => Void := {
super initialize.

let workspaceButton := SimpleButtonMorph new
label: "Workspace";
when: MorphActivatedAnnouncement do: {:: Void | Workspace new openInWindowSystem};
yourself.

let systemBrowserButton := SimpleButtonMorph new
label: "System Browser";
when: MorphActivatedAnnouncement do: {:: Void | SystemBrowser new openInWindowSystem};
yourself.

self
addMorph: workspaceButton;
addMorph: systemBrowserButton;
layout: (MorphVerticalBoxLayout new
add: workspaceButton;
add: systemBrowserButton;
yourself
)
}.

public override method defaultExtent => Float32x2 := 150f32@100f32.
}.
4 changes: 1 addition & 3 deletions package-sources/Morphic.Core/BasicInspector.sysmel
Expand Up @@ -26,7 +26,7 @@ public class BasicInspectorListElement definition: {
}
}.

public class BasicInspector superclass: BorderedMorph; definition: {
public class BasicInspector superclass: PanelMorph; definition: {
protected field inspectedValue => Untyped.
protected field listView => ListViewMorph.
protected field sourceCodeEditor => SourceCodeEditorMorph.
Expand All @@ -53,8 +53,6 @@ public class BasicInspector superclass: BorderedMorph; definition: {
)
}.

public override method defaultColor => Color := Color transparent.

public override method defaultExtent => Float32x2 := 300f32@300f32.

public method onActivatedListViewElement: (element: BasicInspectorListElement) ::=> Void := {
Expand Down
14 changes: 14 additions & 0 deletions package-sources/Morphic.Core/DataSource.sysmel
@@ -1,7 +1,21 @@
public abstract class DataSource definition: {
public field onUpdate => (() => Void).

public abstract method numberOfElements => Size
:= self subclassResponsibility.

public abstract method elementModelAtRow: (rowIndex: Size) ::=> AnyValue
:= self subclassResponsibility.

public abstract method elementAtRow: (rowIndex: Size) ::=> AnyValue
:= self subclassResponsibility.

public virtual method depthOfRow: (rowIndex: Size) ::=> UInt32
:= 0u32.

public method notifyUpdates => Void := {
onUpdate ifNotNil: {
onUpdate()
}
}.
}.
3 changes: 3 additions & 0 deletions package-sources/Morphic.Core/PanelMorph.sysmel
@@ -0,0 +1,3 @@
public class PanelMorph superclass: BorderedMorph; definition: {
public override method defaultColor => Color := Color transparent.
}.
5 changes: 5 additions & 0 deletions package-sources/Morphic.Core/SimpleListDataSource.sysmel
Expand Up @@ -9,6 +9,11 @@ public class SimpleListDataSource superclass: DataSource; definition: {
public override method numberOfElements => Size
:= items size.

public override method elementModelAtRow: (rowIndex: Size) ::=> AnyValue
:= rowIndex < items size
ifTrue: (items at: rowIndex)
ifFalse: nil.

public override method elementAtRow: (rowIndex: Size) ::=> AnyValue
:= rowIndex < items size
ifTrue: (items at: rowIndex)
Expand Down
116 changes: 116 additions & 0 deletions package-sources/Morphic.Core/SimpleTreeDataSource.sysmel
@@ -0,0 +1,116 @@
public class SimpleTreeDataSource superclass: DataSource.

public class SimpleTreeDataSourceElement definition: {
public field depth => UInt32.
public field dataSource => SimpleTreeDataSource.
public field value => AnyValue.
public field isExpanded => Boolean.
public field children => OrderedCollection.

public method validExpandedChildrenWithBlock: (childrenBlock: (AnyValue) => Collection) ::=> OrderedCollection := {
children ifNotNil: {return: children}.

children := OrderedCollection new.
let childrenCollection := childrenBlock(value).
childrenCollection ifNotNil: {
childrenCollection do: {:eachChild :: Void |
children add: (SimpleTreeDataSourceElement new
depth: depth + 1u32;
dataSource: dataSource;
value: eachChild;
yourself)
}
}.

children
}.

public method expand => Void := {
isExpanded ifTrue: {return: void}.

isExpanded := true.
dataSource elementExpansionChanged: self.
}.

public method collapse => Void := {
isExpanded ifFalse: {return: void}.

isExpanded := false.
dataSource elementExpansionChanged: self.
}.

public method toggleExpansion => Void := {
isExpanded := isExpanded not.
dataSource elementExpansionChanged: self.
}.

public method hasChildren => Boolean
:= children isNil || children isNotEmpty.
}.

SimpleTreeDataSource definition: {
let ChildrenBlock := (AnyValue) => Collection.

protected field roots => OrderedCollection.
protected field expandedItems => OrderedCollection.
public field childrenBlock => ChildrenBlock.

public override method initialize => Void := {
super initialize.
roots := OrderedCollection new.
expandedItems := OrderedCollection new.
}.

public override method numberOfElements => Size
:= expandedItems size.

public override method elementModelAtRow: (rowIndex: Size) ::=> AnyValue
:= rowIndex < expandedItems size
ifTrue: (expandedItems at: rowIndex)
ifFalse: nil.

public override method elementAtRow: (rowIndex: Size) ::=> AnyValue
:= rowIndex < expandedItems size
ifTrue: (expandedItems at: rowIndex) value
ifFalse: nil.

public override method depthOfRow: (rowIndex: Size) ::=> UInt32
:= rowIndex < expandedItems size
ifTrue: (expandedItems at: rowIndex) depth
ifFalse: 0u32.

public method roots: (newRoots: Collection) ::=> Void := {
roots := OrderedCollection new.
newRoots do: {:element :: Void |
roots add: (SimpleTreeDataSourceElement new
depth: 0u32;
dataSource: self;
value: element;
yourself)
}.

self recomputeExpandedElements.
}.

public method recomputeExpandedElements => Void := {
expandedItems := OrderedCollection new.
roots do: {:(SimpleTreeDataSourceElement)each :: Void |
self addElementWithExpandedChildrenFrom: each
}.

self notifyUpdates
}.

public method elementExpansionChanged: (element: SimpleTreeDataSourceElement) ::=> Void := {
self recomputeExpandedElements
}.

public method addElementWithExpandedChildrenFrom: (element: SimpleTreeDataSourceElement) ::=> Void := {
expandedItems add: element.
element isExpanded ifFalse: {return: void}.

(element validExpandedChildrenWithBlock: childrenBlock) do: {:(SimpleTreeDataSourceElement)eachChild :: Void |
self addElementWithExpandedChildrenFrom: eachChild
}
}.
}.
5 changes: 3 additions & 2 deletions package-sources/Morphic.Core/StringTableViewColumn.sysmel
Expand Up @@ -5,13 +5,14 @@ public class StringTableViewColumn superclass: TableViewColumn; definition: {

public override method initialize => Void := {
super initialize.
proportion := 1f32.
display := {:element :: String | element asString }.
}.

public override method createCellMorphForElement: element ::=> Morph
public override method createCellMorphForElement: element model: elementModel ::=> Morph
:= display(element) asMorph.

public override method updateCellMorph: (morph: Morph) withElement: element ::=> Void := {
public override method updateCellMorph: (morph: Morph) withElement: element model: elementModel ::=> Void := {
(morph downCastTo: StringMorph) contents: display(element)
}.
}.
9 changes: 9 additions & 0 deletions package-sources/Morphic.Core/SystemBrowser.sysmel
@@ -0,0 +1,9 @@
public class SystemBrowser superclass: PanelMorph; definition: {
protected field sourceCodeEditor => SourceCodeEditorMorph.

public override method initialize => Void := {
super initialize.
}.

public override method defaultExtent => Float32x2 := 600f32@400f32.
}.
5 changes: 3 additions & 2 deletions package-sources/Morphic.Core/TableViewColumn.sysmel
@@ -1,6 +1,7 @@
public abstract class TableViewColumn definition: {
public field name => String.
public field width => Float32.
public field proportion => Float32.

__Meta__ definition: {
public method named: (name: String) ::=> self
Expand All @@ -10,10 +11,10 @@ public abstract class TableViewColumn definition: {
public virtual method minimalCellExtent ::=> Float32x2
:= 0f32 @ FontFace default height.

public virtual method createCellMorphForElement: element ::=> Morph
public virtual method createCellMorphForElement: element model: elementModel ::=> Morph
:= Morph new.

public virtual method updateCellMorph: (morph: Morph) withElement: element ::=> Void := {
public virtual method updateCellMorph: (morph: Morph) withElement: element model: elementModel ::=> Void := {
## By default do nothing.
}.
}.
28 changes: 26 additions & 2 deletions package-sources/Morphic.Core/TableViewMorph.sysmel
Expand Up @@ -55,18 +55,42 @@ public class TableViewMorph superclass: BorderedMorph; definition: {

public method dataSource: (newDataSource: DataSource) ::=> Void := {
dataSource := newDataSource.
dataSource onUpdate: {:: Void |
self onDataUpdate
}.
self changed.
}.

public method isRowSelected: (rowIndex: Size) ::=> Boolean
:= selectedRows isNotNil && (selectedRows includesRowIndex: rowIndex).

public method onDataUpdate => Void := {
contentMorph updateContent.
self changed
}.

public method computeNewColumnWidths => Void := {
columns isEmpty ifTrue: {return: void}.

let columnFixedWidth := self extent x / columns size asFloat32.
let totalProportion mutable := 0f32.
let fixedWidth mutable := 0f32.
columns do: {:(TableViewColumn)eachColumn :: Void |
let columnProportion := eachColumn proportion.
columnProportion = 0f32 ifTrue: {
fixedWidth := fixedWidth + eachColumn minimalCellExtent x
} ifFalse: {
totalProportion := totalProportion + columnProportion
}.
}.

let availableWidth := self extent x - fixedWidth max: 0f32.
columns do: {:(TableViewColumn)eachColumn :: Void |
eachColumn width: columnFixedWidth
let columnProportion := eachColumn proportion.
columnProportion = 0f32 ifTrue: {
eachColumn width: eachColumn minimalCellExtent x
} ifFalse: {
eachColumn width: (availableWidth * columnProportion / totalProportion) floor
}.
}
}.

Expand Down
11 changes: 8 additions & 3 deletions package-sources/Morphic.Core/TableViewRowMorph.sysmel
Expand Up @@ -30,8 +30,9 @@ TableViewRowMorph definition: {
dataSource ifNil: {return: void}.

let element := dataSource elementAtRow: rowIndex.
let elementModel := dataSource elementModelAtRow: rowIndex.
cells := self columns collect: {:(TableViewColumn)eachColumn :: Morph |
let cellMorph := eachColumn createCellMorphForElement: element.
let cellMorph := eachColumn createCellMorphForElement: element model: elementModel.
self addMorph: cellMorph.
cellMorph
} as: Array.
Expand All @@ -43,14 +44,18 @@ TableViewRowMorph definition: {

let columns := self columns.
let element := dataSource elementAtRow: rowIndex.
let elementModel := dataSource elementModelAtRow: rowIndex.
cells doWithIndex: {:(Morph)cellMorph :(Size)cellIndex :: Void |
let viewColumn => TableViewColumn := columns at: cellIndex.
viewColumn updateCellMorph: cellMorph withElement: element
viewColumn updateCellMorph: cellMorph withElement: element model: elementModel
}.
}.

public override method updateLayout => Void := {
let cellX mutable := 0f32.
let rowDepth := self dataSource depthOfRow: rowIndex.
let spaceWidth := FontFace default measureWidthForString: " ".

let cellX mutable := rowDepth asFloat32 * spaceWidth.
let cellHeight := self extent y.

let columns := self columns.
Expand Down

0 comments on commit 23d40d2

Please sign in to comment.