diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-08-08 08:10:26 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-08-28 14:21:06 +0200 |
commit | 473d989cde342e38802c52d9117b12b1e5691077 (patch) | |
tree | f73fc2f3002779024a0e7392eb3b1c8c8c364f44 /pkg/gui/context | |
parent | 061bfce835aed7e78c58bf40c567aa5dffc27e0c (diff) |
Extract a renderLines function
We'll make some changes to how the display strings are rendered, so it helps to
have this code only once. This also fixes the problem that contexts using
refreshViewportOnChange weren't able to use column alignments so far. We didn't
need this yet, but it's just nice if everything works. :)
Diffstat (limited to 'pkg/gui/context')
-rw-r--r-- | pkg/gui/context/list_context_trait.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index 9942fffe0..827ba2c11 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -57,10 +57,19 @@ func (self *ListContextTrait) FocusLine() { } } +func (self *ListContextTrait) renderLines(startIdx int, endIdx int) string { + var columnAlignments []utils.Alignment + if self.getColumnAlignments != nil { + columnAlignments = self.getColumnAlignments() + } + return utils.RenderDisplayStrings( + self.getDisplayStrings(startIdx, endIdx), + columnAlignments) +} + func (self *ListContextTrait) refreshViewport() { startIdx, length := self.GetViewTrait().ViewPortYBounds() - displayStrings := self.getDisplayStrings(startIdx, startIdx+length) - content := utils.RenderDisplayStrings(displayStrings, nil) + content := self.renderLines(startIdx, startIdx+length) self.GetViewTrait().SetViewPortContent(content) } @@ -93,14 +102,7 @@ func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) error // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view func (self *ListContextTrait) HandleRender() error { self.list.RefreshSelectedIdx() - var columnAlignments []utils.Alignment - if self.getColumnAlignments != nil { - columnAlignments = self.getColumnAlignments() - } - content := utils.RenderDisplayStrings( - self.getDisplayStrings(0, self.list.Len()), - columnAlignments, - ) + content := self.renderLines(0, self.list.Len()) self.GetViewTrait().SetContent(content) self.c.Render() self.setFooter() |