Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live View of Permutations #136

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/Sandblocks-Babylonian/SBDiffTabView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ Class {
#category : #'Sandblocks-Babylonian'
}

{ #category : #nil }
SBDiffTabView >> addButton [

^ SBButton new
icon: (SBIcon iconPlus
size: 7.0 sbScaled;
color: (Color green))
do: [self addTab];
makeSmall;
cornerStyle: #squared;
vResizing: #spaceFill;
balloonText: 'Add';
cellGap: -1.0 sbScaled;
layoutInset: (4.0 @ 4.0) sbScaled
]

{ #category : #callbacks }
SBDiffTabView >> artefactSaved: aMethodBlock [

Expand Down Expand Up @@ -54,13 +70,14 @@ SBDiffTabView >> buildView [
SBDiffTabView >> diffButton [

^ SBButton new
icon: (SBIcon iconCodeFork size: 12.0 sbScaled)
icon: (SBIcon iconCodeFork size: 12.0)
do: [self toggleDiffView];
makeSmall;
balloonText: 'Toggle diff to others';
vResizing: #spaceFill;
cornerStyle: #squared;
cellGap: -1.0 sbScaled;
layoutInset: (4.0 @ 3.0) sbScaled
layoutInset: (4.0 @ 3.0)
]

{ #category : #diffing }
Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBExampleGridsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ SBExampleGridsView >> buildExampleFor: aNumber [
]

{ #category : #updating }
SBExampleGridsView >> gridObjects [
SBExampleGridsView >> gridSize [

^ self multiverse activeExamples
^ self multiverse activeExamples size
]

{ #category : #initialization }
Expand Down
37 changes: 37 additions & 0 deletions packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,43 @@ SBExploriants >> = other [
^ self class = other class
]

{ #category : #'ast helpers' }
SBExploriants >> binding: aString for: block class: aClass ifPresent: aBlock [

"See SBStContainer >> binding: for: class: ifPresent: "
| outer |
Symbol hasInterned: aString ifTrue: [:sym | | binding |
binding := aClass bindingOf: sym environment: UndefinedObject environment.
binding ifNotNil: [^ aBlock value: ((SBStName poolDeclaration: aString binding: binding) binding: binding)]].

outer := self outerArtefact.
(outer notNil and: [outer isSmalltalk]) ifTrue: [^ self outerArtefact binding: aString for: block class: aClass ifPresent: aBlock].

^ nil
]

{ #category : #ui }
SBExploriants >> buildView [

self addMorphBack: (self activeBlock hResizing: #shrinkWrap)
]

{ #category : #testing }
SBExploriants >> cacheType: aClass for: aBlock [
]

{ #category : #testing }
SBExploriants >> evaluationContext [

^ nil
]

{ #category : #testing }
SBExploriants >> evaluationReceiver [

^ self object
]

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

Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Babylonian/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SBExploriantsView class >> block: aSBBlock named: aString [
{ #category : #'instance creation' }
SBExploriantsView class >> getTabsInMultiverse: aSBMultiverse [

^ {SBPermutationGridsView. SBExampleGridsView. SBPlainResultsView. SBVariantsView}
^ {SBPermutationGridsView. SBExampleGridsView. SBPlainResultsView. SBLiveView. SBVariantsView}
collect: [:mySubclass | mySubclass newMultiverse: aSBMultiverse]
]

Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBGridResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SBGridResultsView >> clean [
]

{ #category : #updating }
SBGridResultsView >> gridObjects [
SBGridResultsView >> gridSize [

self subclassResponsibility
]
Expand Down Expand Up @@ -50,7 +50,7 @@ SBGridResultsView >> newGridContainer [
SBGridResultsView >> updateContainerWidth [

gridContainer width:
self gridObjects size safeSquareRoot ceiling
self gridSize safeSquareRoot ceiling
* (gridContainer lastSubmorph fullBounds width
+ (2 * gridContainer cellInset)
+ (2 * gridContainer cellGap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ SBInactiveExampleWatch >> saveObjectsActivePermutations [
"Force morphs to persist their permutation even when on the UI process"
exampleToDisplay associationsDo: [:anExampleDisplayPair |
anExampleDisplayPair value displayedWatchValueBlocks do: [:aValueMorph |
SBExploriants objectToPermutation
at: aValueMorph lastSubmorph
put: SBActiveVariantPermutation value]].
aValueMorph lastSubmorph allMorphsDo: [:aSubMorph |
SBExploriants objectToPermutation
at: aSubMorph
put: SBActiveVariantPermutation value]]].
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ SBInactiveExampleWatch >> saveObjectsActivePermutations [
"Force morphs to persist their permutation even when on the UI process"
exampleToDisplay associationsDo: [:anExampleDisplayPair |
anExampleDisplayPair value displayedWatchValueBlocks do: [:aValueMorph |
SBExploriants objectToPermutation
at: aValueMorph lastSubmorph
put: SBActiveVariantPermutation value]].
aValueMorph lastSubmorph allMorphsDo: [:aSubMorph |
SBExploriants objectToPermutation
at: aSubMorph
put: SBActiveVariantPermutation value]]].
]
203 changes: 203 additions & 0 deletions packages/Sandblocks-Babylonian/SBInputBroadcaster.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
Class {
#name : #SBInputBroadcaster,
#superclass : #SBBlock,
#instVars : [
'listeners',
'mice',
'miceContainers',
'stateHands'
],
#category : #'Sandblocks-Babylonian'
}

{ #category : #input }
SBInputBroadcaster >> absorbsInput: anEvent [

^ true
]

{ #category : #accessing }
SBInputBroadcaster >> addListener: aMorph [

self listeners add: aMorph.
self mice add: CircleMorph newPin hide.
self stateHands add: HandMorph new.

"adding mice as our own morphs will cause rattling"
self containers add: (Morph new
color: Color transparent;
extent: aMorph extent;
setProperty: #sbListener toValue: aMorph;
yourself).
self containers last addAllMorphsBack: {mice last. aMorph.}.

^ self containers last

]

{ #category : #accessing }
SBInputBroadcaster >> containers [

^ miceContainers
]

{ #category : #events }
SBInputBroadcaster >> eventProcessMouse: aMouse goingTo: aPosition in: aMorph [

aMouse position: aPosition.
(aMorph containsPoint: aPosition)
ifTrue: [aMouse show]
ifFalse: [aMouse hide]
]

{ #category : #events }
SBInputBroadcaster >> filterEvent: anEvent for: aMorph [

self listeners withIndexDo: [:aListener :i |
| localTarget newEvent delta |
localTarget := self translatedPositionOf: anEvent from: aMorph to: aListener.
delta := localTarget - anEvent position.
newEvent := anEvent copy translateBy: delta.

(self needsHandHandling: newEvent)
ifTrue: [
self simulateGlobalHand: (self stateHands at: i)
for: newEvent
in: aListener
pos: self activeHand position + delta.]
ifFalse: [aListener processEvent: newEvent.].

self eventProcessMouse: (self mice at: i)
goingTo: localTarget
in: aListener.].

^ anEvent
]

{ #category : #'events-processing' }
SBInputBroadcaster >> handleMouseOver: anEvent [

super handleMouseOver: anEvent.
anEvent hand newKeyboardFocus: self.
self sandblockEditor selectNoInput: self.
]

{ #category : #'event handling' }
SBInputBroadcaster >> handlesKeyboard: evt [

^ true

]

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

super initialize.

listeners := OrderedCollection new.
mice := OrderedCollection new.
miceContainers := OrderedCollection new.
stateHands := OrderedCollection new.

self
addEventCaptureFilter: self;
addKeyboardCaptureFilter: self;
addMouseCaptureFilter: self;
canDrag: false;
color: Color veryLightGray

]

{ #category : #accessing }
SBInputBroadcaster >> insertListener: aListener into: aContainer [

| index |
index := self containers indexOf: aContainer ifAbsent: [^ self].

(self containers at: index)
addMorphBack: aListener;
extent: aListener extent;
setProperty: #sbListener toValue: aListener.

aListener topLeft: (self containers at: index) topLeft.
self listeners at: index put: aListener.

]

{ #category : #accessing }
SBInputBroadcaster >> listeners [

^ listeners
]

{ #category : #accessing }
SBInputBroadcaster >> mice [

^ mice
]

{ #category : #'events-processing' }
SBInputBroadcaster >> mouseEnter: anEvent [

super mouseEnter: anEvent.
anEvent hand newKeyboardFocus: self.
]

{ #category : #events }
SBInputBroadcaster >> needsHandHandling: anEvent [

^ anEvent isMouse
and: [anEvent isMouseDown or: [anEvent isMouseUp]]
and: [(SBPreferences rightClickContextMenu and: [anEvent yellowButtonPressed]) not]
]

{ #category : #accessing }
SBInputBroadcaster >> replaceListener: oldListener with: newListener [

| index |
index := self listeners indexOf: oldListener ifAbsent: [^ self].

(self containers at: index)
replaceSubmorph: (self listeners at: index)
by: newListener;
extent: newListener extent;
setProperty: #sbListener toValue: newListener.
self listeners at: index put: newListener.
]

{ #category : #events }
SBInputBroadcaster >> simulateGlobalHand: aHand for: anEvent in: aMorph pos: aPosition [

aMorph owner ifNotNil: [:theOwner | theOwner addMorphBack: aHand].

anEvent
position: aPosition;
setHand: aHand.
aHand handleEvent: anEvent.

aHand delete.
]

{ #category : #accessing }
SBInputBroadcaster >> stateHands [

^ stateHands
]

{ #category : #events }
SBInputBroadcaster >> translatedPositionOf: anEvent from: anOriginMorph to: aTargetMorph [

| localAbsPoint localRelPoint targetAbsPoint |
localAbsPoint := anEvent position - anOriginMorph position.
localRelPoint := localAbsPoint / anOriginMorph extent.
localRelPoint := (localRelPoint x clampLow: 0 high: 1)@(localRelPoint y clampLow: 0 high: 1).
targetAbsPoint := (localRelPoint * aTargetMorph extent) + aTargetMorph position.

^ targetAbsPoint rounded
]

{ #category : #'event handling' }
SBInputBroadcaster >> wantsKeyboardFocus [

^ true
]
Loading
Loading