ck/drw/drw.go
Petar Kapriš 9fa8301ba6 Split project into several packages
The source code of the project has been split up into several packages,
each one pertaining to different aspects of the system. Currently there
is a main package, a drw package, containing all the funcitons
regarding the drawing of the calendar, and a util package containing
time-related project specific functions and general utility functions
for the project.
There are plenty of subsystems in the program which have not even been
developed yet, and new packages will be made pertaining to those. The
package tree may be heavily reorganized in the near future.
2021-11-30 20:14:45 +01:00

58 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package drw
import (
"unicode/utf8"
"github.com/gdamore/tcell/v2"
"gitlab.com/tvrdosrz/ck/util"
)
var (
months = [...]string{"", "Јануар", "Фебруар", "Март", "Април", "Мај", "Јун",
"Јул", "Август", "Септембар", "Октобар", "Новембар", "Децембар"}
weekdays = [...]string{"Недеља", "Понедељак", "Уторак", "Среда", "Четвртак",
"Петак", "Субота"}
)
var (
DefStyle tcell.Style
TodayStyle tcell.Style
SelStyle tcell.Style
)
func centeredText(s string, x, y, width int, scr tcell.Screen, style tcell.Style) {
start := x + util.Max((width-utf8.RuneCountInString(s))/2, 0)
i := 0
for ; x+i < start; i++ {
scr.SetContent(x+i, y, ' ', nil, style)
}
for _, char := range s {
if i >= width {
break
}
scr.SetContent(x+i, y, char, nil, style)
i++
}
for ; x+i < start; i++ {
scr.SetContent(x+i, y, ' ', nil, style)
}
}
func wrappedText(s string, scr tcell.Screen, style tcell.Style) {
x := 0
y := 0
w, h := scr.Size()
for _, char := range s {
if x >= w {
if y >= h {
break
}
x = 0
y++
}
scr.SetContent(x, y, char, nil, style)
x++
}
}