-
Notifications
You must be signed in to change notification settings - Fork 17
/
datepicker.go
68 lines (54 loc) · 2.18 KB
/
datepicker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package gocoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
// #import "datepicker.h"
import "C"
// DatePicker represents a date picker control that can trigger actions.
type DatePicker struct {
datePickerPtr C.DatePickerPtr
datePickerID int
callback func()
}
type DatePickerStyle int32
type DatePickerMode int32
const (
DatePickerStyleClockAndCalendar DatePickerStyle = 1
DatePickerStyleTextField DatePickerStyle = 2
DatePickerStyleTextFieldAndStepper DatePickerStyle = 0
DatePickerModeRange DatePickerMode = 1
DatePickerModeSingle DatePickerMode = 0
)
var datePickers []*DatePicker
var datePickerFormats []string
func NewDatePicker(x int, y int, width int, height int) *DatePicker {
datePickerID := len(datePickers)
datePickerPtr := C.DatePicker_New(C.int(datePickerID), C.int(x), C.int(y), C.int(width), C.int(height))
datePicker := &DatePicker{
datePickerPtr: datePickerPtr,
datePickerID: datePickerID,
}
datePickers = append(datePickers, datePicker)
datePickerFormats = append(datePickerFormats, "yyyy-MM-dd")
return datePicker
}
func (datePicker *DatePicker) SetStyle(style DatePickerStyle) {
C.DatePicker_SetStyle(datePicker.datePickerPtr, C.int(style))
}
func (datePicker *DatePicker) SetMode(mode DatePickerMode) {
C.DatePicker_SetMode(datePicker.datePickerPtr, C.int(mode))
}
func (datePicker *DatePicker) SetDate(date string) {
C.DatePicker_SetDate(datePicker.datePickerPtr, C.CString(date), C.CString(datePickerFormats[datePicker.datePickerID]))
}
func (datePicker *DatePicker) SetMinimumDate(date string) {
C.DatePicker_SetMinimumDate(datePicker.datePickerPtr, C.CString(date), C.CString(datePickerFormats[datePicker.datePickerID]))
}
func (datePicker *DatePicker) SetMaximumDate(date string) {
C.DatePicker_SetMaximumDate(datePicker.datePickerPtr, C.CString(date), C.CString(datePickerFormats[datePicker.datePickerID]))
}
func (datePicker *DatePicker) SetDateFormat(dateFormat string) {
datePickerFormats[datePicker.datePickerID] = dateFormat
}
func (datePicker *DatePicker) Date() string {
return C.GoString(C.DatePicker_Date(datePicker.datePickerPtr, C.CString(datePickerFormats[datePicker.datePickerID])))
}