Skip to content

Commit

Permalink
Wardley Map: it is possible to create notes and nodes from a context …
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajKubelka committed May 21, 2024
1 parent 7d64655 commit 9986078
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 30 deletions.
128 changes: 102 additions & 26 deletions src/GToolkit-WardleyMap/GtWardleyMapEditorElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,115 @@ GtWardleyMapEditorElement >> canvas: aWardleyMapCanvasElement [
canvas := aWardleyMapCanvasElement
]

{ #category : #accessing }
GtWardleyMapEditorElement >> contextMenuHandlerPositionOnEvent: anEvent [
self
allParentsDo: [ :aParent |
(aParent isKindOf: BrAnchoredElement)
ifTrue: [ aParent
childWithId: #handle
ifFound: [ :aHandle | ^ aHandle bounds inSpace position ]
ifNone: [ ^ anEvent position ] ] ].

^ anEvent position
]

{ #category : #accessing }
GtWardleyMapEditorElement >> createNodeButtonElement [
^ BrButton new
beSmallSize;
aptitude: BrGlamorousButtonWithLabelAptitude new;
margin: (BlInsets
top: 10
left: 10
bottom: 10
right: 10);
label: 'Add node';
action: [ :aButtonElement :aButtonModel :anEvent | self onAddNodeEvent: anEvent ]
]

{ #category : #accessing }
GtWardleyMapEditorElement >> createNoteButtonElement [
^ BrButton new
beSmallSize;
aptitude: BrGlamorousButtonWithLabelAptitude new;
margin: (BlInsets
top: 10
left: 10
bottom: 10
right: 10);
label: 'Add note';
action: [ :aButtonElement :aButtonModel :anEvent | self onAddNoteEvent: anEvent ]
]

{ #category : #accessing }
GtWardleyMapEditorElement >> createSwitchSectionsButtonElement [
^ BrButton new
beSmallSize;
aptitude: BrGlamorousButtonWithLabelAptitude new;
margin: (BlInsets
top: 10
left: 10
bottom: 10
right: 10);
label: 'Switch sections';
action: [ canvas parent hasEvolutionAxisLayer
ifFalse: [ canvas parent
evolutionSections: {'genesis'.
'custom built'.
'product (+rental)'.
'commodity'} ]
ifTrue: [ canvas parent removeChildAt: 1 ] ]
]

{ #category : #accessing }
GtWardleyMapEditorElement >> initialize [
| aContainer |
super initialize.
self

self
hFitContent;
vFitContentLimited;
padding: (BlInsets all: 3).

aContainer := BrVerticalPane new
hFitContent
vFitContentLimited.

aContainer := BrVerticalPane new hFitContent vFitContentLimited.

aContainer addChildren: {

BrButton new
beSmallSize;
aptitude: (BrGlamorousButtonWithLabelAptitude new);
margin: (BlInsets top: 10 left: 10 bottom: 10 right: 10);
label: 'Switch sections';
action: [
canvas parent hasEvolutionAxisLayer ifFalse: [
canvas parent evolutionSections: {
'genesis'.
'custom built'.
'product (+rental)'.
'commodity'}] ifTrue: [
canvas parent removeChildAt: 1] ] }.

self addChild: (BrScrollPane new
aptitude: BrScrollPaneAptitude + BrGlamorousWithVerticalScrollbarAptitude;
vFitContentLimited;
hFitContent;
content: aContainer)
self createNoteButtonElement.
self createNodeButtonElement.
self createSwitchSectionsButtonElement}.

self
addChild: (BrScrollPane new
aptitude: BrScrollPaneAptitude + BrGlamorousWithVerticalScrollbarAptitude;
vFitContentLimited;
hFitContent;
content: aContainer)
]

{ #category : #accessing }
GtWardleyMapEditorElement >> normalizedItemPositionOnEvent: anEvent [
| aGlobalPosition |
aGlobalPosition := self contextMenuHandlerPositionOnEvent: anEvent.
^ (canvas globalPointToLocal: aGlobalPosition) / canvas extent
]

{ #category : #'private - event handling' }
GtWardleyMapEditorElement >> onAddNodeEvent: anEvent [
| aNormalizedPosition |
anEvent consumed: true.
(canvas width isZero or: [ canvas height isZero ]) ifTrue: [ ^ self ].
aNormalizedPosition := self normalizedItemPositionOnEvent: anEvent.
canvas wardleyMapViewModel addNewNodeAt: aNormalizedPosition.
^ self fireEvent: BrContextMenuHideWish new
]

{ #category : #'private - event handling' }
GtWardleyMapEditorElement >> onAddNoteEvent: anEvent [
| aNormalizedPosition |
anEvent consumed: true.
(canvas width isZero or: [ canvas height isZero ]) ifTrue: [ ^ self ].
aNormalizedPosition := self normalizedItemPositionOnEvent: anEvent.
canvas wardleyMapViewModel addNewNoteAt: aNormalizedPosition.
self fireEvent: BrContextMenuHideWish new
]
31 changes: 27 additions & 4 deletions src/GToolkit-WardleyMap/GtWardleyMapViewModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,37 @@ GtWardleyMapViewModel >> addNewEdgeFrom: aFromNodeViewModel to: aToNodeViewModel
{ #category : #'api - map' }
GtWardleyMapViewModel >> addNewNodeAt: aNormalizedPosition [
| aNewNode |

self
assert: [ 0 <= aNormalizedPosition x and: [ aNormalizedPosition x <= 1.0 ] ]
description: [ 'Note x-position must be between 0 and 1: {1}' format: {aNormalizedPosition x} ].
self
assert: [ 0 <= aNormalizedPosition y and: [ aNormalizedPosition y <= 1.0 ] ]
description: [ 'Note y-position must be between 0 and 1: {1}' format: {aNormalizedPosition y} ].

aNewNode := GtWardleyMapNodeModel new
coordinate: aNormalizedPosition;
color: self defaultColor.
coordinate: aNormalizedPosition;
color: self defaultColor.

self wardleyMapModel addNode: aNewNode
]

{ #category : #'api - map' }
GtWardleyMapViewModel >> addNewNoteAt: aNormalizedPosition [
| aNewNote |
self
assert: [ 0 <= aNormalizedPosition x and: [ aNormalizedPosition x <= 1.0 ] ]
description: [ 'Note x-position must be between 0 and 1: {1}' format: {aNormalizedPosition x} ].
self
assert: [ 0 <= aNormalizedPosition y and: [ aNormalizedPosition y <= 1.0 ] ]
description: [ 'Note y-position must be between 0 and 1: {1}' format: {aNormalizedPosition y} ].

aNewNote := GtWardleyMapNoteModel new
coordinate: aNormalizedPosition;
color: self defaultColor.

self wardleyMapModel addNote: aNewNote
]

{ #category : #announcer }
GtWardleyMapViewModel >> announcer [
<return: #Announcer>
Expand Down

0 comments on commit 9986078

Please sign in to comment.