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

Progress bar #160

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
56 changes: 56 additions & 0 deletions src/Toplo-Widget-ProgressBar/TToProgress.trait.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Trait {
#name : #TToProgress,
#instVars : [
'progressBar',
'remainingBar',
'valueInPercentage'
],
#category : #'Toplo-Widget-ProgressBar'
}

{ #category : #'t - accessing' }
TToProgress >> isInfinite: aBoolean [
]

{ #category : #'t - accessing' }
TToProgress >> progressBar [

^ progressBar
]

{ #category : #'t - accessing' }
TToProgress >> progressBar: anObject [

progressBar := anObject
]

{ #category : #'t - accessing' }
TToProgress >> remainingBar [

^ remainingBar
]

{ #category : #'t - accessing' }
TToProgress >> remainingBar: anObject [

remainingBar := anObject
]

{ #category : #'t - resizeable' }
TToProgress >> resizeProgressBar [

^ self explicitRequirement
]

{ #category : #'t - accessing' }
TToProgress >> valueInPercentage [

^ valueInPercentage
]

{ #category : #'t - accessing' }
TToProgress >> valueInPercentage: aFloat [

valueInPercentage := aFloat.
self resizeProgressBar
]
157 changes: 157 additions & 0 deletions src/Toplo-Widget-ProgressBar/ToProgressBar.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
Class {
#name : #ToProgressBar,
#superclass : #ToElement,
#traits : 'TToProgress',
#classTraits : 'TToProgress classTrait',
#instVars : [
'icon',
'label',
'container'
],
#category : #'Toplo-Widget-ProgressBar'
}

{ #category : #example }
ToProgressBar class >> example_LinearProgressBarFinite [

| p |
p := ToProgressBar new.
p matchParent.
p valueInPercentage: 0.75.
p openInSpace.
^ p

]

{ #category : #example }
ToProgressBar class >> example_LinearProgressBarFiniteWithIcon [

| p |
p := ToProgressBar new.
p matchParent.
p icon: (ToImage new innerImage: (self iconNamed: #glamorousAccept)).
p valueInPercentage: 0.75.
p openInSpace.
^ p

]

{ #category : #example }
ToProgressBar class >> example_LinearProgressBarFiniteWithLabel [

| p |
p := ToProgressBar new.
p matchParent.
p label: (ToLabel text: '75%').
p valueInPercentage: 0.75.
p openInSpace.
^ p
]

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

^ container
]

{ #category : #accessing }
ToProgressBar >> container: anObject [

container := anObject
]

{ #category : #initialization }
ToProgressBar >> defaultLayout [

^ BlLinearLayout horizontal
]

{ #category : #testing }
ToProgressBar >> hasIcon [

^ self icon notNil
]

{ #category : #testing }
ToProgressBar >> hasLabel [

^ self label notNil
]

{ #category : #accessing }
ToProgressBar >> icon [

^ icon
]

{ #category : #accessing }
ToProgressBar >> icon: anElement [

anElement = icon ifTrue: [ ^ self ].
self label: nil.
icon ifNotNil: [ :s | s removeFromParent].
icon := anElement.
anElement ifNil: [ ^ self ].
self addChild: anElement
]

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

super initialize.
self layout verticalAlignment: BlElementAlignment vertical center.

progressBar := ToElement new matchParent.
remainingBar := ToElement new matchParent.

progressBar constraintsDo: [ :c |
c frame horizontal alignLeft.
c frame vertical alignCenter].
remainingBar constraintsDo: [ :c |
c frame horizontal alignLeft.
c frame vertical alignCenter].

container := ToElement new matchParent.
container layout: BlFrameLayout new.

container addChild: progressBar.
container addChild: remainingBar.

progressBar
addEventHandlerOn: BlElementExtentChangedEvent
do: [ :e | self resizeProgressBar ].

self addChild: container
]

{ #category : #accessing }
ToProgressBar >> label [

^ label
]

{ #category : #accessing }
ToProgressBar >> label: anElement [

anElement = label ifTrue: [ ^ self ].
self icon: nil.
label ifNotNil: [ :s | s removeFromParent].
label := anElement.
anElement ifNil: [ ^ self ].
self addChild: anElement
]

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

^ ToProgressBarSkin new
]

{ #category : #'t - resizeable' }
ToProgressBar >> resizeProgressBar [

| w |
self valueInPercentage ifNil: [ ^ self ].
w := remainingBar size x * self valueInPercentage.
progressBar width: w
]
28 changes: 28 additions & 0 deletions src/Toplo-Widget-ProgressBar/ToProgressBarSkin.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class {
#name : #ToProgressBarSkin,
#superclass : #ToBasicSkin,
#category : #'Toplo-Widget-ProgressBar'
}

{ #category : #'event handling' }
ToProgressBarSkin >> installLookEvent: anEvent [

super installLookEvent: anEvent.
anEvent elementDo: [ :e |
e hasLabel ifTrue: [
e label text attributes:
{ (BlTextForegroundAttribute paint:(e valueOfTokenNamed: #'color-text')) }.
e label textChanged.
e label padding: (BlInsets left: 10) ].

e hasIcon ifTrue: [ e icon padding: (BlInsets left: 10) ].

e progressBar background: (e valueOfTokenNamed: #'color-primary').
e remainingBar background: (e valueOfTokenNamed: #'color-bg-container-disabled').

e progressBar height: 6.
e remainingBar height: 6.

e progressBar geometry: (BlRoundedRectangleGeometry cornerRadius: 100).
e remainingBar geometry: (BlRoundedRectangleGeometry cornerRadius: 100)]
]
Loading
Loading