2014-02-24 23:13:47 -06:00
// 25 february 2014
package ui
import (
2014-02-24 23:48:23 -06:00
"sync"
2014-02-24 23:13:47 -06:00
)
// A ProgressBar is a horizontal rectangle that fills up from left to right to indicate the progress of a long-running task.
// This progress is typically a percentage, so within the range [0,100].
type ProgressBar struct {
lock sync . Mutex
created bool
sysData * sysData
initProg int
}
// NewProgressBar creates a new ProgressBar.
func NewProgressBar ( ) * ProgressBar {
return & ProgressBar {
sysData : mksysdata ( c_progressbar ) ,
}
}
2014-03-12 15:58:33 -05:00
// SetProgress sets the currently indicated progress amount on the ProgressBar. If this amount is outside the range [0,100] (ideally -1), the function will panic (TODO make it indeterminate).
2014-02-24 23:13:47 -06:00
func ( p * ProgressBar ) SetProgress ( percent int ) {
p . lock . Lock ( )
defer p . lock . Unlock ( )
2014-02-24 23:31:48 -06:00
if percent < 0 || percent > 100 {
panic ( "invalid percent" ) // TODO
}
2014-02-24 23:13:47 -06:00
if p . created {
p . sysData . setProgress ( percent )
return
}
p . initProg = percent
}
func ( p * ProgressBar ) make ( window * sysData ) error {
p . lock . Lock ( )
defer p . lock . Unlock ( )
err := p . sysData . make ( "" , window )
if err != nil {
return err
}
p . sysData . setProgress ( p . initProg )
p . created = true
return nil
}
2014-03-03 16:44:03 -06:00
func ( p * ProgressBar ) setRect ( x int , y int , width int , height int , winheight int ) error {
2014-02-24 23:13:47 -06:00
p . lock . Lock ( )
defer p . lock . Unlock ( )
2014-03-03 16:44:03 -06:00
return p . sysData . setRect ( x , y , width , height , winheight )
2014-02-24 23:13:47 -06:00
}
2014-03-09 18:44:41 -05:00
func ( p * ProgressBar ) preferredSize ( ) ( width int , height int ) {
2014-02-24 23:13:47 -06:00
p . lock . Lock ( )
defer p . lock . Unlock ( )
2014-03-09 18:44:41 -05:00
return p . sysData . preferredSize ( )
2014-02-24 23:13:47 -06:00
}