Rename constant month{Height,Width} to maxMonth{Height,Width}
This commit is contained in:
parent
72916575bd
commit
b99fbda938
18
Main.go
18
Main.go
|
@ -14,9 +14,9 @@ const (
|
||||||
dayWidth = 2
|
dayWidth = 2
|
||||||
smallGap = 1
|
smallGap = 1
|
||||||
largeGap = 3
|
largeGap = 3
|
||||||
monthWidth = 7*dayWidth + 6*smallGap
|
maxMonthWidth = 7*dayWidth + 6*smallGap
|
||||||
monthHeight = (31+6+(7-1))/7 + 2
|
maxMonthHeight = (31+6+(7-1))/7 + 2
|
||||||
/* monthHeight is the height of a 31-day month starting on Sunday (month
|
/* maxMonthHeight is the height of a 31-day month starting on Sunday (month
|
||||||
name and weekdays included) */
|
name and weekdays included) */
|
||||||
|
|
||||||
titleHeight = smallGap + 1
|
titleHeight = smallGap + 1
|
||||||
|
@ -89,7 +89,7 @@ func wrappedText(s string, scr tcell.Screen, style tcell.Style) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawMonth(m time.Month, x, y int) {
|
func drawMonth(m time.Month, x, y int) {
|
||||||
centeredText(months[m], x, y, monthWidth, wall, defStyle)
|
centeredText(months[m], x, y, maxMonthWidth, wall, defStyle)
|
||||||
|
|
||||||
for i := 1; i <= 7; i++ {
|
for i := 1; i <= 7; i++ {
|
||||||
centeredText(weekdays[i%7], x+(i-1)*(dayWidth+smallGap), y+1, dayWidth, wall, defStyle)
|
centeredText(weekdays[i%7], x+(i-1)*(dayWidth+smallGap), y+1, dayWidth, wall, defStyle)
|
||||||
|
@ -118,21 +118,21 @@ func drawMonth(m time.Month, x, y int) {
|
||||||
func drawWall() {
|
func drawWall() {
|
||||||
wall.Clear()
|
wall.Clear()
|
||||||
w, h := wall.Size()
|
w, h := wall.Size()
|
||||||
if w < monthWidth+2*smallGap || h < monthHeight+2*smallGap+titleHeight {
|
if w < maxMonthWidth+2*smallGap || h < maxMonthHeight+2*smallGap+titleHeight {
|
||||||
wrappedText("Екран је премали за календар.", wall, defStyle)
|
wrappedText("Екран је премали за календар.", wall, defStyle)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
monthsWide := (w - 2*smallGap + largeGap) / (monthWidth + largeGap)
|
monthsWide := (w - 2*smallGap + largeGap) / (maxMonthWidth + largeGap)
|
||||||
monthsHigh := (h - smallGap - titleHeight) / (monthHeight + smallGap)
|
monthsHigh := (h - smallGap - titleHeight) / (maxMonthHeight + smallGap)
|
||||||
monthsDrawn := min(monthsHigh*monthsWide, 12) // TODO: izraziti 12 drugacije??
|
monthsDrawn := min(monthsHigh*monthsWide, 12) // TODO: izraziti 12 drugacije??
|
||||||
|
|
||||||
startingMonth := time.Month((int(selTime.Month())-1)/monthsDrawn*monthsDrawn + 1)
|
startingMonth := time.Month((int(selTime.Month())-1)/monthsDrawn*monthsDrawn + 1)
|
||||||
endingMonth := time.Month(min(12, int(startingMonth)+monthsDrawn-1))
|
endingMonth := time.Month(min(12, int(startingMonth)+monthsDrawn-1))
|
||||||
|
|
||||||
centerVert := (w - monthsWide*monthWidth - (monthsWide-1)*largeGap) / 2
|
centerVert := (w - monthsWide*maxMonthWidth - (monthsWide-1)*largeGap) / 2
|
||||||
for i, m := 0, startingMonth; i < monthsHigh; i++ {
|
for i, m := 0, startingMonth; i < monthsHigh; i++ {
|
||||||
for j := 0; j < monthsWide; j++ {
|
for j := 0; j < monthsWide; j++ {
|
||||||
drawMonth(m, centerVert+j*(monthWidth+largeGap), titleHeight+smallGap+i*(monthHeight+smallGap))
|
drawMonth(m, centerVert+j*(maxMonthWidth+largeGap), titleHeight+smallGap+i*(maxMonthHeight+smallGap))
|
||||||
if m >= endingMonth {
|
if m >= endingMonth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue