Rename constant month{Height,Width} to maxMonth{Height,Width}

This commit is contained in:
Petar Kapriš 2021-11-30 07:48:51 +01:00 committed by Петар Каприш
parent 72916575bd
commit b99fbda938

18
Main.go
View file

@ -14,9 +14,9 @@ const (
dayWidth = 2
smallGap = 1
largeGap = 3
monthWidth = 7*dayWidth + 6*smallGap
monthHeight = (31+6+(7-1))/7 + 2
/* monthHeight is the height of a 31-day month starting on Sunday (month
maxMonthWidth = 7*dayWidth + 6*smallGap
maxMonthHeight = (31+6+(7-1))/7 + 2
/* maxMonthHeight is the height of a 31-day month starting on Sunday (month
name and weekdays included) */
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) {
centeredText(months[m], x, y, monthWidth, wall, defStyle)
centeredText(months[m], x, y, maxMonthWidth, wall, defStyle)
for i := 1; i <= 7; i++ {
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() {
wall.Clear()
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)
return
}
monthsWide := (w - 2*smallGap + largeGap) / (monthWidth + largeGap)
monthsHigh := (h - smallGap - titleHeight) / (monthHeight + smallGap)
monthsWide := (w - 2*smallGap + largeGap) / (maxMonthWidth + largeGap)
monthsHigh := (h - smallGap - titleHeight) / (maxMonthHeight + smallGap)
monthsDrawn := min(monthsHigh*monthsWide, 12) // TODO: izraziti 12 drugacije??
startingMonth := time.Month((int(selTime.Month())-1)/monthsDrawn*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 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 {
return
}