Skip to content

Commit

Permalink
Display other displays in exploriants
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Feb 19, 2024
1 parent 4a804e7 commit acfd17c
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 42 deletions.
20 changes: 16 additions & 4 deletions packages/Sandblocks-Babylonian/SBCluster.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ Class {
SBCluster >> compressedMorphsForDisplay: aSBWatchView [

| displayedMorphs |
displayedMorphs := aSBWatchView watchValues collect: [:aWatchValue |
aWatchValue morphResizer: self morphResizer.
aWatchValue asValueMorph].
aSBWatchView isDisplayingWatchValues
ifTrue: [displayedMorphs := self gatherAndCopyWatchValuesFrom: aSBWatchView]
ifFalse: [ | display |
display := aSBWatchView selectedDisplay submorphs
ifEmpty: [aSBWatchView selectedDisplay]
ifNotEmpty: [:submorphs | submorphs last].
displayedMorphs := {self morphResizer applyOn: display}].
^ (displayedMorphs size = 1)
ifTrue: [displayedMorphs first]
ifFalse: [self newCellMorph
Expand All @@ -24,6 +28,14 @@ SBCluster >> compressedMorphsForDisplay: aSBWatchView [
addAllMorphsBack: displayedMorphs]
]

{ #category : #visualisation }
SBCluster >> gatherAndCopyWatchValuesFrom: aSBWatchView [

^ aSBWatchView watchValues collect: [:aWatchValue |
aWatchValue morphResizer: self morphResizer.
aWatchValue asValueMorph]
]

{ #category : #initialization }
SBCluster >> initialize [

Expand Down Expand Up @@ -177,7 +189,7 @@ SBCluster >> wrapInCell: aMorph flexVertically: aVBoolean flexHorizontally: aHBo

self flag: #todo. "Another way besides turning into an image to keep interactions.-jb"
cell addMorph: (ImageMorph new
newForm: (aMorph iconOrThumbnailOfSize: targetExtent);
newForm: (aMorph imageForm scaledIntoFormOfSize: targetExtent);
when: #clicked send: #triggerEvent: to: aMorph with: #clicked).
cell on: #click send: #value to: [cell submorphs first triggerEvent: #clicked].
^ cell
Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBExampleCluster.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ SBExampleCluster >> displayedIndex: aNumber [
{ #category : #visualisation }
SBExampleCluster >> extractRowsFrom: aUniverse [

^ aUniverse watches collect: [:anExample | | display |
display := (anExample exampleToDisplay associations at: self displayedIndex) value display.
^ aUniverse watches collect: [:aWatch | | display |
display := (aWatch exampleToDisplay associations at: self displayedIndex) value display.
self compressedMorphsForDisplay: display]
]

Expand Down
40 changes: 31 additions & 9 deletions packages/Sandblocks-Babylonian/SBExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,34 @@ SBExampleWatch >> asInactiveCopy [
modifyExpression: self modifyExpression veryDeepCopy;
dimensionOptions: self dimensionOptions veryDeepCopy.

exampleToValues keys do: [:anExample | copy exampleStarting: anExample;
reportValues: (self valuesForExample: anExample) for: anExample;
exampleFinished: anExample ].
exampleToValues keys do: [:anExample |
copy exampleStarting: anExample;
reportValues: (self valuesForExample: anExample) for: anExample].

"Keep switched views consistent"
exampleToDisplay keys do: [:anExample |
(copy exampleToDisplay at: anExample) display
selectedDisplayIndex: (exampleToDisplay at: anExample) display selectedDisplayIndex].

exampleToValues keys do: [:anExample | copy exampleFinished: anExample].


^ copy
saveObjectsActivePermutations;
yourself
]

{ #category : #initialization }
SBExampleWatch >> buildDefaultDisplayFor: anExample [

| valueDisplay |
valueDisplay := SBExampleValueDisplay new.
valueDisplay display fallbackResizer: self selectedMorphResizer.
self addMorph: (exampleToDisplay at: anExample put: valueDisplay) atIndex: 2.
anExample when: #outOfWorld send: #exampleStopped: to: self with: anExample.
^ valueDisplay
]

{ #category : #accessing }
SBExampleWatch >> cleanedExpression [

Expand Down Expand Up @@ -169,6 +188,14 @@ SBExampleWatch >> color [
^ self parentSandblock color
]

{ #category : #copying }
SBExampleWatch >> copySelectedDisplayIndicesFrom: other [

other exampleToDisplay associationsDo: [:exampleToDisplayAss |
(exampleToDisplay at: exampleToDisplayAss key ifAbsentPut: [self buildDefaultDisplayFor: exampleToDisplayAss key])
display selectedDisplayIndex: exampleToDisplayAss value display selectedDisplayIndex]
]

{ #category : #'insert/delete' }
SBExampleWatch >> deleteCommandFor: aBlock [

Expand Down Expand Up @@ -220,12 +247,7 @@ SBExampleWatch >> exampleStarting: anExample [

exampleToValues at: anExample put: OrderedCollection new.

(exampleToDisplay at: anExample ifAbsentPut: [ | valueDisplay |
valueDisplay := SBExampleValueDisplay new.
valueDisplay display fallbackResizer: self selectedMorphResizer.
self addMorph: (exampleToDisplay at: anExample put: valueDisplay) atIndex: 2.
anExample when: #outOfWorld send: #exampleStopped: to: self with: anExample.
valueDisplay])
(exampleToDisplay at: anExample ifAbsentPut: [self buildDefaultDisplayFor: anExample])
exampleStarting: anExample;
name: anExample label
]
Expand Down
28 changes: 23 additions & 5 deletions packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ SBMultiverse >> asyncKaboom [
SBMultiverse >> cleanUp [

watches do: #resumeGraphicalUpdates.
(watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete
(watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete.
watches select: #isInEditor thenDo: [:aWatch | aWatch exampleToDisplay values do: #updateDisplay].
]

{ #category : #collecting }
Expand All @@ -123,6 +124,20 @@ SBMultiverse >> findExistingOrConvertToBlocks: aCollectionOfCompiledMethods [
ifClosed: [aCompiledMethod asSandblock]]
]

{ #category : #collecting }
SBMultiverse >> findExistingOrConvertToBlocksMaintainingWatches: aCollectionOfCompiledMethods [

^ aCollectionOfCompiledMethods
collect: [:aCompiledMethod | | sandBlock |
sandBlock := aCompiledMethod asSandblock.
sandBlock setProperty: #originals toValue: WeakOrderedCollection new.
self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod)
ifOpen: [:existingMethodBlock |
(sandBlock valueOfProperty: #originals) addAll: existingMethodBlock containedExampleWatches.
sandBlock]
ifClosed: [sandBlock]]
]

{ #category : #'initialize-release' }
SBMultiverse >> gatherElements [

Expand All @@ -131,17 +146,20 @@ SBMultiverse >> gatherElements [
have consistency between changes."
allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants.

allMethodBlocksContainingWatches := self allCompiledMethodsContainingExampleWatches collect: #asSandblock.
allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches.

universes := OrderedCollection new.
activeExamples := self allActiveExamples.

variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten.
variants := variants select: #isActive.

watches := (self allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten.
watches do: [:aWatch | activeExamples do: [:anExample | aWatch exampleStarting: anExample].
aWatch hide. aWatch extent: 1@1].
watches := (allMethodBlocksContainingWatches collect: [:aMethodBlock | | copies |
copies := aMethodBlock containedExampleWatches.
(aMethodBlock valueOfProperty: #originals) withIndexDo: [:original :i | (copies at: i) copySelectedDisplayIndicesFrom: original].
copies ]) flatten.
watches do: [:aWatch | activeExamples do: [:anExample | aWatch exampleStarting: anExample]].
watches reject: #isInEditor thenDo: [:aWatch | aWatch hide. aWatch extent: 1@1]

]

Expand Down
11 changes: 5 additions & 6 deletions packages/Sandblocks-Watch/SBLineChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ SBLineChart >> datapointExtent [
SBLineChart >> extent: aPoint [

super extent: aPoint.
self targetHeight: aPoint y.
self targetHeight: aPoint y- 6.
self scaleY range: (self scaleY range start to: aPoint y).
self visualize
]
Expand Down Expand Up @@ -91,13 +91,12 @@ SBLineChart >> newDatapointFor: aValue at: positionIndex [
color: self datapointDefaultColor;
borderWidth: 0;
left: positionIndex * self spaceBetweenPoints;
top: self targetHeight - (self scaleY scaledValueOf: aValue) - (self datapointExtent y / 2);
top: ((self targetHeight - (self scaleY scaledValueOf: aValue))
clampLow: 0
high: (targetHeight - (self datapointExtent y / 2)));
setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue);
yourself);
yourself



yourself
]

{ #category : #visualization }
Expand Down
61 changes: 45 additions & 16 deletions packages/Sandblocks-Watch/SBWatchView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Class {
'count',
'shouldUpdateDisplay',
'selectedDisplayIndex',
'displayOptionsCache',
'fallbackResizer',
'clear',
'updateScheduled'
Expand All @@ -24,20 +25,16 @@ SBWatchView >> addValue: aWatchValue sized: aSBMorphResizer [
]

{ #category : #display }
SBWatchView >> buildCustomDisplayWith: aCollectionOfWatchValues [
SBWatchView >> buildCustomDisplay [

| options |
options := Array streamContents: [:stream |
(aCollectionOfWatchValues collect: #watchedValue)
allConversionsFor: SBInterfaces topLevel do: [:pair | stream nextPut: pair]].
^ self watchValuesContainer
addMorphBack: (self fallbackResizer applyOn: ((options atWrap: selectedDisplayIndex) second))
addMorphBack: (self displayOptionsCache at: selectedDisplayIndex) second
]

{ #category : #display }
SBWatchView >> buildDefaultDisplayWith: aCollectionOfWatchValues [
SBWatchView >> buildDefaultDisplay [

^ self watchValuesContainer addAllMorphsBack: (aCollectionOfWatchValues collect: #asValueMorph)
^ self watchValuesContainer addAllMorphsBack: (watchValues collect: #asValueMorph)
]

{ #category : #display }
Expand All @@ -47,7 +44,7 @@ SBWatchView >> buildDisplayOptions [
options := Array streamContents: [:stream |
self values allConversionsFor: SBInterfaces topLevel do: [:pair | stream nextPut: pair]].
options := options do: [:aPair | aPair at: 2 put: (self watchValuesContainer addMorphBack: (self fallbackResizer applyOn: aPair second))].
options := options, {{'default'. self buildDefaultDisplayWith: watchValues}}.
options := options, {{'default'. self buildDefaultDisplay}}.
^ options
]

Expand All @@ -67,16 +64,15 @@ SBWatchView >> canDeleteChild: aBlock [
SBWatchView >> changeDisplay [
<action>

| index options |
options := self buildDisplayOptions.
index := UIManager default chooseFrom: (options collect: #first).
| index |
index := UIManager default chooseFrom: (self displayOptionsCache collect: #first).
index = 0 ifTrue: [^ self].

(options at: index) first = 'default'
(displayOptionsCache at: index) first = 'default'
ifTrue: [selectedDisplayIndex := 0]
ifFalse: [selectedDisplayIndex := index].

self displayOnScrollPane: (options at: index) second.
self displayOnScrollPane: (displayOptionsCache at: index) second.
]

{ #category : #actions }
Expand Down Expand Up @@ -148,13 +144,19 @@ SBWatchView >> displayOnScrollPane: aMorph [
ifFalse: [self maxWidth])
]

{ #category : #accessing }
SBWatchView >> displayOptionsCache [

^ displayOptionsCache ifNil: [displayOptionsCache := self buildDisplayOptions]
]

{ #category : #display }
SBWatchView >> displayWatchValues [

| valuesMorph |
valuesMorph := self isDisplayingWatchValues
ifTrue: [self buildDefaultDisplayWith: watchValues]
ifFalse: [self buildCustomDisplayWith: watchValues].
ifTrue: [self buildDefaultDisplay]
ifFalse: [self buildCustomDisplay].
"Will sometimes not update size otherwise when rushing through runs"
valuesMorph doLayoutSafely.
self displayOnScrollPane: valuesMorph.
Expand Down Expand Up @@ -352,6 +354,25 @@ SBWatchView >> scroller [
^ self scrollPane scroller
]

{ #category : #display }
SBWatchView >> selectedDisplay [

^ (self displayOptionsCache atWrap: selectedDisplayIndex) second
]

{ #category : #accessing }
SBWatchView >> selectedDisplayIndex [

^ selectedDisplayIndex
]

{ #category : #accessing }
SBWatchView >> selectedDisplayIndex: aNumber [

"Private, no side effects! Call updateDisplay if an update is desired"
selectedDisplayIndex := aNumber
]

{ #category : #accessing }
SBWatchView >> shouldUpdateDisplay [

Expand All @@ -375,6 +396,13 @@ SBWatchView >> storeAsExample [
self sandblockEditor open: class >> name asSymbol
]

{ #category : #accessing }
SBWatchView >> updateCache [

self isDisplayingWatchValues ifTrue: [^ self].
displayOptionsCache := self buildDisplayOptions
]

{ #category : #display }
SBWatchView >> updateDisplay [

Expand All @@ -388,6 +416,7 @@ SBWatchView >> updateDisplay [
disableLayout: false;
visible: true].

self updateCache.
self displayWatchValues
]

Expand Down

0 comments on commit acfd17c

Please sign in to comment.