Skip to content

Commit 33054ab

Browse files
committed
feat: vertical scroll functionality in boards view
1 parent 7206eed commit 33054ab

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

internal/boards/board_view.go

+26-9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type boardView struct {
5353
cursorY int
5454
screenX, screenY int
5555
scrollX int
56+
scrollY int
5657
columnSize int
5758
}
5859

@@ -109,28 +110,28 @@ func NewBoardView(project *jira.Project, boardConfiguration *jira.BoardConfigura
109110
}
110111

111112
func (b *boardView) Draw(screen tcell.Screen) {
112-
b.topBar.Draw(screen)
113-
b.tmpX = 0
114-
for _, column := range b.columns {
115-
app.DrawText(screen, b.tmpX-b.scrollX, topMargin, columnHeaderStyle, centerString(column, b.columnSize))
116-
b.tmpX += b.columnSize + 1
117-
}
118113
if len(b.issues) == 0 {
114+
b.drawColumnsHeaders(screen)
115+
b.topBar.Draw(screen)
119116
return
120117
}
121118
for _, issue := range b.issues {
122119
column := b.statusesColumnsMap[issue.Fields.Status.Id]
123120
x := b.columnsX[column]
124121
y := b.issuesRow[issue.Id]
122+
// do not draw issues at the bottom of top-bar&headers
123+
if y+topMargin-b.scrollY < topMargin {
124+
continue
125+
}
125126
if b.highlightedIssue.Id == issue.Id {
126127
var style = &cursorIssueStyle
127128
if b.issueSelected {
128129
style = &selectedIssueStyle
129130
}
130-
app.DrawTextLimited(screen, x-b.scrollX, y+topMargin, x+b.columnSize-b.scrollX, y+1+topMargin, *style, b.issuesSummaries[issue.Id])
131+
app.DrawTextLimited(screen, x-b.scrollX, y+topMargin-b.scrollY, x+b.columnSize-b.scrollX, y+1+topMargin, *style, b.issuesSummaries[issue.Id])
131132
continue
132133
}
133-
app.DrawTextLimited(screen, x-b.scrollX, y+topMargin, x+b.columnSize-b.scrollX, y+1+topMargin, issueStyle, b.issuesSummaries[issue.Id])
134+
app.DrawTextLimited(screen, x-b.scrollX, y+topMargin-b.scrollY, x+b.columnSize-b.scrollX, y+1+topMargin, issueStyle, b.issuesSummaries[issue.Id])
134135
}
135136
if b.highlightedIssue != nil {
136137
app.DrawText(screen, 0, 1, titleStyle, app.WriteIndicator)
@@ -141,6 +142,8 @@ func (b *boardView) Draw(screen tcell.Screen) {
141142
} else {
142143
b.selectedIssueBottomBar.Draw(screen)
143144
}
145+
b.drawColumnsHeaders(screen)
146+
b.topBar.Draw(screen)
144147
b.ensureHighlightInViewport()
145148
}
146149

@@ -169,7 +172,6 @@ func (b *boardView) Init() {
169172
app.GetApp().Loading(true)
170173
b.issues = make([]jira.Issue, 0, maxIssuesNumber)
171174
page := int32(0)
172-
// TODO - cursorY scrolling needs to be added in order to scroll long columns
173175
for len(b.issues) < maxIssuesNumber {
174176
iss, total, _, err := b.api.SearchJqlPageable(b.filterJQL, page, issueFetchBatchSize)
175177
if err != nil {
@@ -237,6 +239,14 @@ func (b *boardView) HandleKeyEvent(ev *tcell.EventKey) {
237239
}
238240
}
239241

242+
func (b *boardView) drawColumnsHeaders(screen tcell.Screen) {
243+
b.tmpX = 0
244+
for _, column := range b.columns {
245+
app.DrawText(screen, b.tmpX-b.scrollX, topMargin, columnHeaderStyle, centerString(column, b.columnSize))
246+
b.tmpX += b.columnSize + 1
247+
}
248+
}
249+
240250
func (b *boardView) moveCursorRight() {
241251
if b.cursorX+1 >= len(b.statusesColumnsMap) {
242252
return
@@ -250,7 +260,9 @@ func (b *boardView) moveCursorRight() {
250260
// no issues in a column
251261
if f := b.refreshHighlightedIssue(); !f {
252262
b.moveCursorRight()
263+
return
253264
}
265+
b.scrollY = 0
254266
}
255267

256268
func (b *boardView) moveCursorLeft() {
@@ -266,7 +278,9 @@ func (b *boardView) moveCursorLeft() {
266278
// no issues in a column
267279
if f := b.refreshHighlightedIssue(); !f {
268280
b.moveCursorLeft()
281+
return
269282
}
283+
b.scrollY = 0
270284
}
271285

272286
func (b *boardView) handleActions() {
@@ -399,6 +413,9 @@ func (b *boardView) ensureHighlightInViewport() {
399413
if b.scrollX+(b.cursorX*b.columnSize)+b.columnSize > b.screenX { // highlighted issue out of screen
400414
b.scrollX = app.MaxInt(0, (b.cursorX-2)*b.columnSize)
401415
}
416+
if b.scrollY+b.cursorY > b.scrollY { // highlighted issue out of screen
417+
b.scrollY = app.MaxInt(0, b.cursorY-2)
418+
}
402419
}
403420

404421
func centerString(str string, width int) string {

0 commit comments

Comments
 (0)