Implemented ProgressBar on Mac OS X.

This commit is contained in:
Pietro Gagliardi 2014-11-04 11:41:38 -05:00
parent 44cd9db87c
commit f35892e892
3 changed files with 63 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#define toNSWindow(x) ((NSWindow *) (x))
#define toNSBox(x) ((NSBox *) (x))
#define toNSTextView(x) ((NSTextView *) (x))
#define toNSProgressIndicator(x) ((NSProgressIndicator *) (x))
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
@public
@ -271,3 +272,31 @@ void textboxSetText(id tv, char *text)
{
[toNSTextView(tv) setString:[NSString stringWithUTF8String:text]];
}
id newProgressBar(void)
{
NSProgressIndicator *pi;
pi = [[NSProgressIndicator alloc] initWithFrame:NSZeroRect];
[pi setStyle:NSProgressIndicatorBarStyle];
[pi setControlSize:NSRegularControlSize];
[pi setControlTint:NSDefaultControlTint];
[pi setBezeled:YES];
[pi setDisplayedWhenStopped:YES];
[pi setUsesThreadedAnimation:YES];
[pi setIndeterminate:NO];
[pi setMinValue:0];
[pi setMaxValue:100];
[pi setDoubleValue:0];
return (id) pi;
}
intmax_t progressbarPercent(id pbar)
{
return (intmax_t) [toNSProgressIndicator(pbar) doubleValue];
}
void progressbarSetPercent(id pbar, intmax_t percent)
{
[toNSProgressIndicator(pbar) setDoubleValue:((double) percent)];
}

View File

@ -82,6 +82,9 @@ extern void groupSetText(id, char *);
extern id newTextbox(void);
extern char *textboxText(id);
extern void textboxSetText(id, char *);
extern id newProgressBar(void);
extern intmax_t progressbarPercent(id);
extern void progressbarSetPercent(id, intmax_t);
/* container_darwin.m */
extern id newContainerView(void *);

31
progressbar_darwin.go Normal file
View File

@ -0,0 +1,31 @@
// 4 november 2014
package ui
import (
"fmt"
)
// #include "objc_darwin.h"
import "C"
type progressbar struct {
*controlSingleObject
}
func newProgressBar() ProgressBar {
return &progressbar{
controlSingleObject: newControlSingleObject(C.newProgressBar()),
}
}
func (p *progressbar) Percent() int {
return int(C.progressbarPercent(p.id))
}
func (p *progressbar) SetPercent(percent int) {
if percent < 0 || percent > 100 {
panic(fmt.Errorf("given ProgressBar percentage %d out of range", percent))
}
C.progressbarSetPercent(p.id, C.intmax_t(percent))
}