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

Added Collapse Widget example + other examples #675

Merged
merged 14 commits into from
Jan 9, 2025
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
1 change: 1 addition & 0 deletions src/BaselineOfBloc/BaselineOfBloc.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ BaselineOfBloc >> baseline: spec [

spec package: #'Bloc-Demo' with: [
spec requires: #(#'Bloc-Layout' #'Bloc-Spec2' #'Bloc-Text-Elements') ].
spec package: #'Bloc-DragNDrop'.

"SVG"
self declareXMLParserOn: spec.
Expand Down
167 changes: 167 additions & 0 deletions src/Bloc-Demo/BlCollapseWidget.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
Class {
#name : #BlCollapseWidget,
#superclass : #BlElement,
#instVars : [
'bar',
'container',
'collapsed'
],
#category : #'Bloc-Demo-Collapse'
}

{ #category : #'as yet unclassified' }
BlCollapseWidget class >> exampleSimpleCollapse [

<script>
| collapse bgPaint collapsed collapsedChild |
collapse := self new.
collapse position: 50 asPoint.

bgPaint := BlLinearGradientPaint vertical
from: Color lightGreen
to: Color lightRed.

collapsed := BlElement new
background: bgPaint;
size: 250 @ 150;
border: (BlBorderBuilder new
paint: Color red;
width: 3;
dashed;
build);
addEventHandlerOn: BlClickEvent do: [ :e | e traceCr ];
yourself.

collapsedChild := BlElement new
background: Color purple;
size: 50 @ 100;
position: 50 asPoint;
yourself.

collapsed addChild: collapsedChild.

collapse container addChild: collapsed.

collapse openInSpace
]

{ #category : #accessing }
BlCollapseWidget >> bar [

^ bar
]

{ #category : #accessing }
BlCollapseWidget >> bar: aBlElement [

bar := aBlElement
]

{ #category : #'expanding-collapsing' }
BlCollapseWidget >> collapse [

| closedAnimation |
closedAnimation := (BlTransformAnimation translate: 0@ (0- container height)) duration: 0.2 second.

container addAnimation: closedAnimation.
]

{ #category : #accessing }
BlCollapseWidget >> collapsed [

^ collapsed
]

{ #category : #accessing }
BlCollapseWidget >> container [

^ container
]

{ #category : #accessing }
BlCollapseWidget >> container: aBlElement [

container := aBlElement
]

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

super initialize.
collapsed := true.
self layout: BlLinearLayout vertical.
self constraintsDo: [ :c |
c vertical fitContent.
c horizontal fitContent ].
self initializeBar.
self initializeContainer.
]

{ #category : #initialization }
BlCollapseWidget >> initializeBar [

| arrow geometry opened rotateCWAnimation rotateACWAnimation |
bar := BlElement new
background: Color veryVeryLightGray;
size: 250 @ 50;
border: (BlBorder paint: Color lightGray width: 2);
layout: BlFrameLayout new;
padding: (BlInsets all: 10);
zIndex: 1;
"has to be 'above' the container"yourself.

geometry := BlPolygonGeometry vertices: {
(0 @ 0).
(20 @ 0).
(10 @ 10) }.

arrow := BlElement new
size: geometry extent;
geometry: geometry;
constraintsDo: [ :c |
c frame vertical alignCenter.
c frame horizontal alignLeft ];
background: Color lightGray.

bar addChild: arrow.
bar clipChildren: false.

rotateCWAnimation := (BlTransformAnimation rotate: 90) duration:
0.2 second.
rotateACWAnimation := (BlTransformAnimation rotate: -90) duration:
0.2 second.


bar addEventHandlerOn: BlClickEvent do: [ :e |
e consume.
collapsed := collapsed not.
collapsed
ifTrue: [ self show.
arrow addAnimation: rotateCWAnimation copy]
ifFalse: [ self collapse.
arrow addAnimation: rotateACWAnimation copy] ].

self addChild: bar
]

{ #category : #initialization }
BlCollapseWidget >> initializeContainer [

container := BlElement new
constraintsDo: [ :c |
c vertical exact: 150.
c horizontal matchParent ];
border: (BlBorder paint: Color veryLightGray width: 1);
yourself.

self addChild: container
]

{ #category : #'host space - displaying' }
BlCollapseWidget >> show [

| openedAnimation |
openedAnimation := (BlTransformAnimation translate: 0@ container height) duration: 0.2 second.

container addAnimation: openedAnimation.
]
Loading
Loading