refactor(ui): make ConfigureBox mutate in place
This commit is contained in:
parent
7abc3e4003
commit
3e2222414a
5 changed files with 7 additions and 9 deletions
|
|
@ -74,7 +74,7 @@ func newComposer(cfg *config.Config, chat *Model) *composer {
|
|||
cache: cache.New(),
|
||||
mentionsList: mentionslist.NewModel(cfg),
|
||||
}
|
||||
c.Box = ui.ConfigureBox(c.Box, &cfg.Theme)
|
||||
ui.ConfigureBox(c.Box, &cfg.Theme)
|
||||
c.
|
||||
SetPlaceholder(tview.NewLine(tview.NewSegment("Select a channel to start chatting", tcell.StyleDefault.Dim(true)))).
|
||||
SetClipboard(
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ func newGuildsTree(cfg *config.Config, chat *Model) *guildsTree {
|
|||
guildNodeByID: make(map[discord.GuildID]*tree.Node),
|
||||
channelNodeByID: make(map[discord.ChannelID]*tree.Node),
|
||||
}
|
||||
|
||||
gt.Box = ui.ConfigureBox(gt.Box, &cfg.Theme)
|
||||
ui.ConfigureBox(gt.Box, &cfg.Theme)
|
||||
gt.
|
||||
SetRoot(tree.NewNode("")).
|
||||
SetTopLevel(1).
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ type Model struct {
|
|||
|
||||
func NewModel(cfg *config.Config) *Model {
|
||||
l := list.NewModel()
|
||||
l.Box = ui.ConfigureBox(l.Box, &cfg.Theme)
|
||||
ui.ConfigureBox(l.Box, &cfg.Theme)
|
||||
l.
|
||||
SetSelectedStyle(tcell.StyleDefault.Reverse(true)).
|
||||
SetSnapToItems(true).
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func newMessagesList(cfg *config.Config, chat *Model) *messagesList {
|
|||
}
|
||||
ml.attachmentsPicker = newAttachmentsPicker(cfg, chat)
|
||||
|
||||
ml.Box = ui.ConfigureBox(ml.Box, &cfg.Theme)
|
||||
ui.ConfigureBox(ml.Box, &cfg.Theme)
|
||||
ml.SetTitle("Messages")
|
||||
ml.SetBuilder(ml.buildItem)
|
||||
ml.SetChangedFunc(ml.onRowCursorChanged)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
// ConfigureBox configures the provided box according to the provided theme.
|
||||
func ConfigureBox(box *tview.Box, cfg *config.Theme) *tview.Box {
|
||||
func ConfigureBox(box *tview.Box, cfg *config.Theme) {
|
||||
border := cfg.Border
|
||||
normalBorderStyle, activeBorderStyle := border.NormalStyle.Style, border.ActiveStyle.Style
|
||||
normalBorderSet, activeBorderSet := border.NormalSet.BorderSet, border.ActiveSet.BorderSet
|
||||
|
|
@ -52,12 +52,11 @@ func ConfigureBox(box *tview.Box, cfg *config.Theme) *tview.Box {
|
|||
if border.Enabled {
|
||||
box.SetBorders(tview.BordersAll)
|
||||
}
|
||||
|
||||
return box
|
||||
}
|
||||
|
||||
func ConfigurePicker(model *picker.Model, cfg *config.Config, title string) {
|
||||
model.Box = ConfigureBox(tview.NewBox(), &cfg.Theme)
|
||||
model.Box = tview.NewBox()
|
||||
ConfigureBox(model.Box, &cfg.Theme)
|
||||
// When a child of the parent flex is focused, the parent layout itself is not reported as focused.
|
||||
// Instead, the focused child (picker) is considered focused.
|
||||
// Therefore, we manually set the active border style on the picker to ensure it displays the correct focused appearance.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue