Really figuring some things out
This commit is contained in:
39
timefield.go
39
timefield.go
@@ -25,7 +25,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
@@ -37,9 +37,8 @@ type TimeField struct {
|
||||
visible bool
|
||||
tabbable bool
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
wantW, wantH int
|
||||
x, y int
|
||||
w, h int
|
||||
|
||||
value time.Time
|
||||
hasDate bool
|
||||
@@ -79,8 +78,14 @@ func (w *TimeField) Init(id string, style tcell.Style) {
|
||||
w.tabbable = true
|
||||
}
|
||||
|
||||
func (w *TimeField) Id() string { return w.id }
|
||||
func (w *TimeField) HandleResize(ev *tcell.EventResize) {}
|
||||
func (w *TimeField) Id() string { return w.id }
|
||||
func (w *TimeField) HandleResize(ev *tcell.EventResize) {
|
||||
w.w, w.h = ev.Size()
|
||||
|
||||
w.w = wh.Min(w.w, w.WantW())
|
||||
w.h = wh.Min(w.h, w.WantH())
|
||||
}
|
||||
|
||||
func (w *TimeField) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active {
|
||||
return false
|
||||
@@ -99,24 +104,24 @@ func (w *TimeField) Draw(screen tcell.Screen) {
|
||||
x := w.x
|
||||
labelW := len(w.label)
|
||||
if labelW > 0 {
|
||||
h.DrawText(w.x, w.y, w.label+": ", ds, screen)
|
||||
wh.DrawText(w.x, w.y, w.label+": ", ds, screen)
|
||||
x = x + labelW + 2
|
||||
}
|
||||
if w.hasDate {
|
||||
yr, mo, dy := w.value.Year(), w.value.Month(), w.value.Day()
|
||||
for idx, vl := range fmt.Sprintf("%4d%2d%2d", yr, mo, dy) {
|
||||
if idx == 4 || idx == 7 {
|
||||
h.DrawText(x, w.y, "-", ds, screen)
|
||||
wh.DrawText(x, w.y, "-", ds, screen)
|
||||
x++
|
||||
}
|
||||
if idx == w.cursor && !w.nowBtnActive {
|
||||
if w.active {
|
||||
h.DrawText(x, w.y, string(vl), ds.Reverse(true).Blink(true), screen)
|
||||
wh.DrawText(x, w.y, string(vl), ds.Reverse(true).Blink(true), screen)
|
||||
} else {
|
||||
h.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
}
|
||||
} else {
|
||||
h.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
}
|
||||
x++
|
||||
}
|
||||
@@ -129,26 +134,26 @@ func (w *TimeField) Draw(screen tcell.Screen) {
|
||||
}
|
||||
for idx, vl := range txt {
|
||||
if idx == 2 || idx == 5 {
|
||||
h.DrawText(x, w.y, ":", ds, screen)
|
||||
wh.DrawText(x, w.y, ":", ds, screen)
|
||||
x++
|
||||
}
|
||||
if idx+8 == w.cursor && !w.nowBtnActive {
|
||||
if w.active {
|
||||
h.DrawText(x, w.y, string(vl), ds.Reverse(true).Blink(true), screen)
|
||||
wh.DrawText(x, w.y, string(vl), ds.Reverse(true).Blink(true), screen)
|
||||
} else {
|
||||
h.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
}
|
||||
} else {
|
||||
h.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
}
|
||||
x++
|
||||
}
|
||||
}
|
||||
if w.showNowBtn {
|
||||
if w.nowBtnActive {
|
||||
h.DrawText(x, w.y, "[ Now ]", ds.Reverse(true), screen)
|
||||
wh.DrawText(x, w.y, "[ Now ]", ds.Reverse(true), screen)
|
||||
} else {
|
||||
h.DrawText(x, w.y, "[ Now ]", ds, screen)
|
||||
wh.DrawText(x, w.y, "[ Now ]", ds, screen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user