-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
550 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
src/Toplo-Widget-Accordion/ToAccordionElementSkin.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
src/Toplo-Widget-Accordion/ToAccordionListElement.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
src/Toplo-Widget-Accordion/ToAccordionListNodeManager.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
Oops, something went wrong.