Skip to content

Commit

Permalink
Working on a first cleaned version of ToAccordionElement (not ready t…
Browse files Browse the repository at this point in the history
…o be used but cleaned enough)
  • Loading branch information
plantec committed Jan 28, 2025
1 parent f671f01 commit 268bac4
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 394 deletions.
128 changes: 61 additions & 67 deletions src/Toplo-Widget-Accordion/ToAccordionElement.class.st
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
Class {
#name : #ToAccordionElement,
#superclass : #ToElement,
#traits : 'TToClickable',
#classTraits : 'TToClickable classTrait',
#instVars : [
'header',
'body',
'headerBuilder',
'clickHandler',
'clickEventClass',
'isCollapsed',
'header',
'headerContainer',
'iconContainer'
'bodyBuilder'
],
#category : #'Toplo-Widget-Accordion-Core'
}
Expand All @@ -22,59 +16,82 @@ ToAccordionElement class >> exampleWithLabel [
<script>
| inst |
inst := self new.
inst builder: [ :header | header addChild: (ToLabel text: 'coucou') ].
inst headerBuilder: [ :header |
header addChild: (ToLabel text: 'Header') ].
inst bodyBuilder: [ :body |
body addChild:
(ToLabel new text: 'Body with random background color').
body
hMatchParent;
height: 100;
background: Color random ].
inst openInSpace.
^ inst
]

{ #category : #accessing }
ToAccordionElement >> builder: aValuable [
"With an header as argument"

aValuable value: header
]

{ #category : #'t - clickable' }
ToAccordionElement >> clickHandler [
{ #category : #'as yet unclassified' }
ToAccordionElement class >> exampleWithLabelAndAlbumInBody [

^ clickHandler
<script>
| inst |
inst := self new.
inst headerBuilder: [ :header |
header addChild: (ToLabel text: 'Header') ].
inst bodyBuilder: [ :body |
| album |
album := ToAlbum new
withSaveCapability;
whenSaveRequestedDo: [ :saveRequested |
saveRequested accepted: true ];
whenCancelRequestedDo: [ :cancelRequested |
cancelRequested editorElement text: '' ];
yourself.
album hMatchParent.
album vFitContent.
album next vFitContent.
album infinite vFitContent.
album text: 'AAAAAAAA'.
body addChild: album ].
inst openInSpace.
^ inst
]

{ #category : #'t - clickable' }
ToAccordionElement >> clickHandler: anHandler [

clickHandler := anHandler
{ #category : #accessing }
ToAccordionElement >> bodyBuilder: aValuable [
"With a body as argument"

bodyBuilder := aValuable
]

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

body removeChildren.
body removeFromParent
]

{ #category : #'expanding-collapsing' }
ToAccordionElement >> expand [

bodyBuilder ifNil: [ ^ self ].
bodyBuilder value: body.
self addChild: body
]

{ #category : #accessing }
ToAccordionElement >> icon: aToImage [

iconContainer removeChildren.
iconContainer addChild: aToImage
ToAccordionElement >> headerBuilder: aValuable [
"With an header as argument"

header builder: aValuable
]

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

super initialize.
isCollapsed := true.
self height: 30.
self layout: BlLinearLayout vertical.
self hMatchParent.
self vFitContent.
self background: Color random.
self initializeHeader.
self initializeClick.
self initializeBody.
Expand All @@ -89,64 +106,41 @@ ToAccordionElement >> initializeBody [
c vertical fitContent.
c horizontal matchParent ];
border: (BlBorder paint: Color veryLightGray width: 1);
yourself.
body addChild: (BlElement new
border: Color black;
background: Color black;
size: 50 @ 50)
yourself
]

{ #category : #initialization }
ToAccordionElement >> initializeClick [

self whenClickedDo: [ :e |
header whenClickedDo: [ :e |
e consume.
isCollapsed := isCollapsed not.
isCollapsed
header isCollapsed: header isCollapsed not.
header isCollapsed
ifFalse: [ self expand ]
ifTrue: [ self collapse ] ]
]

{ #category : #initialization }
ToAccordionElement >> initializeHeader [

headerContainer := ToElement new.
headerContainer layout: BlLinearLayout horizontal.
headerContainer hMatchParent.
headerContainer vFitContent.
self addChild: headerContainer.

header := ToElement new.
header hMatchParent.
header vFitContent.

iconContainer := ToElement new.
iconContainer fitContent.
headerContainer addChild: iconContainer.

headerContainer addChild: header
header := ToAccordionHeaderElement new.
self addChild: header
]

{ #category : #initialization }
{ #category : #testing }
ToAccordionElement >> isCollapsed [

^ isCollapsed
^ header isCollapsed
]

{ #category : #accessing }
ToAccordionElement >> isCollapsed: aBoolean [

header isCollapsed: aBoolean
]

{ #category : #skin }
ToAccordionElement >> newRawSkin [

^ ToAccordionElementSkin new
]

{ #category : #'t - clickable' }
ToAccordionElement >> rawClickEventClass [

^ clickEventClass
]

{ #category : #'t - clickable' }
ToAccordionElement >> rawClickEventClass: aClass [

clickEventClass := aClass
]
19 changes: 1 addition & 18 deletions src/Toplo-Widget-Accordion/ToAccordionElementSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@ Class {
#category : #'Toplo-Widget-Accordion-Core'
}

{ #category : #'event handling' }
ToAccordionElementSkin >> clickedSkinEvent: anEvent [

super clickedSkinEvent: anEvent.
anEvent elementDo: [ :e |
| arrowTk |
arrowTk := e isCollapsed
ifTrue: [ #'submenu-arrow-up' ]
ifFalse: [ #'submenu-arrow-down' ].
e icon: (e valueOfTokenNamed: arrowTk) value ]
]

{ #category : #'event handling' }
ToAccordionElementSkin >> installSkinEvent: anEvent [

super installSkinEvent: anEvent.
anEvent elementDo: [ :e |
| arrowTk |
arrowTk := e isCollapsed
ifTrue: [ #'submenu-arrow-up' ]
ifFalse: [ #'submenu-arrow-down' ].
e icon: (e valueOfTokenNamed: arrowTk) value ]
anEvent elementDo: [ :e | ]
]
107 changes: 107 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionHeaderElement.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Class {
#name : #ToAccordionHeaderElement,
#superclass : #ToElement,
#traits : 'TToClickable',
#classTraits : 'TToClickable classTrait',
#instVars : [
'builder',
'clickHandler',
'clickEventClass',
'isCollapsed',
'iconContainer',
'content'
],
#category : #'Toplo-Widget-Accordion-Core'
}

{ #category : #examples }
ToAccordionHeaderElement class >> exampleWithLabel [

<script>
| inst |
inst := self new.
inst builder: [ :header | header addChild: (ToLabel text: 'header') ].
inst openInSpace.
^ inst
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> builder: aValuable [
"With an header as argument"

aValuable value: content
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> clickHandler [

^ clickHandler
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> clickHandler: anHandler [

clickHandler := anHandler
]

{ #category : #accessing }
ToAccordionHeaderElement >> content [

^ content
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> icon: aToImage [

iconContainer removeChildren.
iconContainer addChild: aToImage
]

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

super initialize.
isCollapsed := true.
self layout: BlLinearLayout horizontal.
self hMatchParent.
self vFitContent.
content := ToElement new.
content layout: BlLinearLayout horizontal.
content hMatchParent.
content vFitContent.

iconContainer := ToElement new.
iconContainer fitContent.
self addChild: iconContainer.
self addChild: content
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> isCollapsed [

^ isCollapsed
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> isCollapsed: aBoolean [

isCollapsed := aBoolean
]

{ #category : #skin }
ToAccordionHeaderElement >> newRawSkin [

^ ToAccordionHeaderElementSkin new
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> rawClickEventClass [

^ clickEventClass
]

{ #category : #'as yet unclassified' }
ToAccordionHeaderElement >> rawClickEventClass: aClass [

clickEventClass := aClass
]
29 changes: 29 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionHeaderElementSkin.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class {
#name : #ToAccordionHeaderElementSkin,
#superclass : #ToRawSkin,
#category : #'Toplo-Widget-Accordion-Core'
}

{ #category : #'as yet unclassified' }
ToAccordionHeaderElementSkin >> clickedSkinEvent: anEvent [

super clickedSkinEvent: anEvent.
anEvent elementDo: [ :e |
| arrowTk |
arrowTk := e isCollapsed
ifTrue: [ #'submenu-arrow-up' ]
ifFalse: [ #'submenu-arrow-down' ].
e icon: (e valueOfTokenNamed: arrowTk) value ]
]

{ #category : #'event handling' }
ToAccordionHeaderElementSkin >> installSkinEvent: anEvent [

super installSkinEvent: anEvent.
anEvent elementDo: [ :e |
| arrowTk |
arrowTk := e isCollapsed
ifTrue: [ #'submenu-arrow-up' ]
ifFalse: [ #'submenu-arrow-down' ].
e icon: (e valueOfTokenNamed: arrowTk) value ]
]
Loading

0 comments on commit 268bac4

Please sign in to comment.