Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Jan 13, 2025
1 parent 19079ff commit c310cf3
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 0 deletions.
152 changes: 152 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionElement.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Class {
#name : #ToAccordionElement,
#superclass : #ToElement,
#traits : 'TToClickable',
#classTraits : 'TToClickable classTrait',
#instVars : [
'body',
'headerBuilder',
'clickHandler',
'clickEventClass',
'isCollapsed',
'header',
'headerContainer',
'iconContainer'
],
#category : #'Toplo-Widget-Accordion-Core'
}

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

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

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

aValuable value: header
]

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

^ clickHandler
]

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

clickHandler := anHandler
]

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

body removeFromParent
]

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

self addChild: body
]

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

iconContainer removeChildren.
iconContainer addChild: aToImage
]

{ #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.

]

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

body := ToElement new
constraintsDo: [ :c |
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)
]

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

self whenClickedDo: [ :e |
e consume.
isCollapsed := isCollapsed not.
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
]

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

^ isCollapsed
]

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

^ ToAccordionElementSkin new
]

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

^ clickEventClass
]

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

clickEventClass := aClass
]
29 changes: 29 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionElementSkin.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class {
#name : #ToAccordionElementSkin,
#superclass : #ToRawSkin,
#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 ]
]
67 changes: 67 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionListElement.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Class {
#name : #ToAccordionListElement,
#superclass : #ToAbstractListElement,
#category : #'Toplo-Widget-Accordion-Core'
}

{ #category : #'Xp to trash' }
ToAccordionListElement class >> exampleBasicAccordion [

<script>
| list |
list := ToAccordionListElement new.
list dataAccessor addAll: ((1 to: 5) collect: [ :i |
ToBasicAccordionElement new button addChild:
(ToLabel text: 'coucou ' , i asString) ]).
list matchParent.
list openInSpace
]

{ #category : #'Xp to trash' }
ToAccordionListElement class >> exampleCollapse [

<script>
| list |
list := ToAccordionListElement new.
list dataAccessor addAll: ((1 to: 5) collect: [ :i |
ToAccordionXPElement new labelText: 'coucou ' , i asString ]).
list matchParent.
list openInSpace
]

{ #category : #example }
ToAccordionListElement class >> exampleSkinAccordion [

<script>
| list |
list := self new.
list dataAccessor addAll: ((1 to: 5) collect: [ :i |
ToAccordionElement new builder: [ :h | h addChild: (ToLabel text:'coucou ' , i asString) ]]).
list matchParent.
list openInSpace
]

{ #category : #'Xp to trash' }
ToAccordionListElement class >> exampleToAccordionXPElement [

<script>
| list |
list := ToAccordionListElement new.
list dataAccessor addAll: ((1 to: 5) collect: [ :i |
ToAccordionXPElement new labelText: 'coucou ' , i asString ]).
list matchParent.
list openInSpace
]

{ #category : #initialization }
ToAccordionListElement >> defaultInnerElement [

^ ToInfiniteElement onListElement: self
]

{ #category : #initialization }
ToAccordionListElement >> defaultNodeManagerClass [
"The object responsible to populate the list nodes."

^ ToAccordionListNodeManager
]
44 changes: 44 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionListNodeManager.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Class {
#name : #ToAccordionListNodeManager,
#superclass : #ToAbstractNodeManager,
#category : #'Toplo-Widget-Accordion-Core'
}

{ #category : #'instance creation' }
ToAccordionListNodeManager >> buildNode: aNode [

| collapse |
collapse := aNode holder dataItem.
"in the case of this list the dateitem is in fact a bl element."

collapse removeFromParent.
aNode addChild: collapse at: 1
]

{ #category : #'instance creation' }
ToAccordionListNodeManager >> constraintNode: aNode [

aNode constraintsDo: [ :c |
c horizontal matchParent.
c vertical fitContent ]
]

{ #category : #'instance creation' }
ToAccordionListNodeManager >> newHolder [
"Return the holder (contains information about the node) of a node"

^ ToListNodeHolder new
]

{ #category : #'instance creation' }
ToAccordionListNodeManager >> newNodeForHolder: aNodeHolder [

^ ToAccordionNode new
]

{ #category : #'instance creation' }
ToAccordionListNodeManager >> unbuildNode: aNode [

aNode removeChildren.

]
11 changes: 11 additions & 0 deletions src/Toplo-Widget-Accordion/ToAccordionNode.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToAccordionNode,
#superclass : #ToListNode,
#category : #'Toplo-Widget-Accordion-Core'
}

{ #category : #accessing }
ToAccordionNode >> builder: aValuable [

aValuable value: self header
]
Loading

0 comments on commit c310cf3

Please sign in to comment.