A few fixes
This commit is contained in:
@@ -40,6 +40,9 @@ type TimeField struct {
|
||||
x, y int
|
||||
w, h int
|
||||
|
||||
yr, mo, dy int
|
||||
hr, mn, sc int
|
||||
|
||||
value time.Time
|
||||
hasDate bool
|
||||
hasTime bool
|
||||
@@ -75,21 +78,34 @@ func (w *TimeField) Init(id string, style tcell.Style) {
|
||||
tcell.KeyHome: w.handleHome,
|
||||
tcell.KeyEnd: w.handleEnd,
|
||||
})
|
||||
w.visible = true
|
||||
w.tabbable = true
|
||||
}
|
||||
|
||||
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())
|
||||
if w.w > w.WantW() {
|
||||
w.w = w.WantW()
|
||||
}
|
||||
if w.h > w.WantH() {
|
||||
w.h = w.WantH()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *TimeField) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active {
|
||||
return false
|
||||
}
|
||||
switch w.cursor {
|
||||
case 0: // year
|
||||
case 1: // month
|
||||
case 2: // day
|
||||
case 3: // hour
|
||||
case 4: // minute
|
||||
case 5: // second
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
func (w *TimeField) HandleTime(ev *tcell.EventTime) {}
|
||||
@@ -97,31 +113,33 @@ func (w *TimeField) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
ds := w.style
|
||||
if !w.active {
|
||||
ds = ds.Dim(true)
|
||||
}
|
||||
dS := w.style.Dim(!w.active)
|
||||
|
||||
// pos := w.GetPos()
|
||||
x := w.x
|
||||
y := w.y
|
||||
labelW := len(w.label)
|
||||
if labelW > 0 {
|
||||
wh.DrawText(w.x, w.y, w.label+": ", ds, screen)
|
||||
x = x + labelW + 2
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.label, wh.BRD_SIMPLE, dS, screen)
|
||||
} else {
|
||||
wh.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, wh.BRD_SIMPLE, dS, screen)
|
||||
}
|
||||
x, y = x+1, y+1
|
||||
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 {
|
||||
wh.DrawText(x, w.y, "-", ds, screen)
|
||||
wh.DrawText(x, y, "-", dS, screen)
|
||||
x++
|
||||
}
|
||||
if idx == w.cursor && !w.nowBtnActive {
|
||||
if w.active {
|
||||
wh.DrawText(x, w.y, string(vl), ds.Reverse(true).Blink(true), screen)
|
||||
wh.DrawText(x, y, string(vl), dS.Reverse(true).Blink(true), screen)
|
||||
} else {
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, y, string(vl), dS, screen)
|
||||
}
|
||||
} else {
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, y, string(vl), dS, screen)
|
||||
}
|
||||
x++
|
||||
}
|
||||
@@ -134,26 +152,27 @@ func (w *TimeField) Draw(screen tcell.Screen) {
|
||||
}
|
||||
for idx, vl := range txt {
|
||||
if idx == 2 || idx == 5 {
|
||||
wh.DrawText(x, w.y, ":", ds, screen)
|
||||
wh.DrawText(x, y, ":", dS, screen)
|
||||
x++
|
||||
}
|
||||
if idx+8 == w.cursor && !w.nowBtnActive {
|
||||
if w.active {
|
||||
wh.DrawText(x, w.y, string(vl), ds.Reverse(true).Blink(true), screen)
|
||||
wh.DrawText(x, y, string(vl), dS.Reverse(true).Blink(true), screen)
|
||||
} else {
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, y, string(vl), dS, screen)
|
||||
}
|
||||
} else {
|
||||
wh.DrawText(x, w.y, string(vl), ds, screen)
|
||||
wh.DrawText(x, y, string(vl), dS, screen)
|
||||
}
|
||||
x++
|
||||
}
|
||||
}
|
||||
if w.showNowBtn {
|
||||
x, y = x+w.w-8, y+1
|
||||
if w.nowBtnActive {
|
||||
wh.DrawText(x, w.y, "[ Now ]", ds.Reverse(true), screen)
|
||||
wh.DrawText(x, y, "[ Now ]", dS.Reverse(true), screen)
|
||||
} else {
|
||||
wh.DrawText(x, w.y, "[ Now ]", ds, screen)
|
||||
wh.DrawText(x, y, "[ Now ]", dS, screen)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,9 +210,9 @@ func (w *TimeField) WantW() int {
|
||||
wdt += 5 // hh:mm
|
||||
}
|
||||
}
|
||||
return wdt
|
||||
return wdt + 2
|
||||
}
|
||||
func (w *TimeField) WantH() int { return 1 }
|
||||
func (w *TimeField) WantH() int { return 3 }
|
||||
func (w *TimeField) MinW() int {
|
||||
wdt := 0
|
||||
if w.hasDate {
|
||||
@@ -209,9 +228,9 @@ func (w *TimeField) MinW() int {
|
||||
wdt += 5 // hh:mm
|
||||
}
|
||||
}
|
||||
return wdt
|
||||
return wdt + 2
|
||||
}
|
||||
func (w *TimeField) MinH() int { return 1 }
|
||||
func (w *TimeField) MinH() int { return 3 }
|
||||
|
||||
func (w *TimeField) SetLabel(lbl string) { w.label = lbl }
|
||||
func (w *TimeField) SetTime(tm time.Time) { w.value = tm }
|
||||
|
||||
Reference in New Issue
Block a user