* the dialog replacement now calculates its neccessary height
MODIFY
ui/editor.go
ui/editor.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/Bios-Marcel/cordless/shortcuts"
+ "github.com/Bios-Marcel/cordless/ui/tviewutil"
"github.com/Bios-Marcel/tview"
"github.com/atotto/clipboard"
@@ -345,17 +346,8 @@ func (editor *Editor) setAndFixText(text string) {
}
func (editor *Editor) countRows(text string) int {
- splitLines := strings.Split(text, "\n")
_, _, width, _ := editor.internalTextView.GetInnerRect()
-
- wrappedLines := 0
- for _, line := range splitLines {
- if len(line) >= width {
- wrappedLines = wrappedLines + ((len(line) - (len(line) % width)) / width)
- }
- }
-
- return len(splitLines) + wrappedLines
+ return tviewutil.CalculateNeccessaryHeight(width, text)
}
func (editor *Editor) triggerHeightRequestIfNeccessary() {

ADD
ui/tviewutil/text.go
+package tviewutil
+
+import "strings"
+
+// CalculateNeccessaryHeight calculates the necessary height in the ui given
+// the text and the width of the component the text will appear in.
+func CalculateNeccessaryHeight(width int, text string) int {
+ splitLines := strings.Split(text, "\n")
+
+ wrappedLines := 0
+ for _, line := range splitLines {
+ if len(line) >= width {
+ wrappedLines = wrappedLines + ((len(line) - (len(line) % width)) / width)
+ }
+ }
+
+ return len(splitLines) + wrappedLines
+
+}

RENAME
ui/tview/treeview/treeview.go
ui/tviewutil/treeview.go
-package treeview
+package tviewutil
import (
"github.com/Bios-Marcel/tview"

MODIFY
ui/window.go
ui/window.go
@@ -18,7 +18,7 @@ import (
"github.com/Bios-Marcel/cordless/scripting/js"
"github.com/Bios-Marcel/cordless/shortcuts"
"github.com/Bios-Marcel/cordless/times"
- "github.com/Bios-Marcel/cordless/ui/tview/treeview"
+ "github.com/Bios-Marcel/cordless/ui/tviewutil"
"github.com/Bios-Marcel/discordemojimap"
"github.com/Bios-Marcel/discordgo"
"github.com/Bios-Marcel/tview"
@@ -532,15 +532,15 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
window.userList.internalTreeView.SetSearchOnTypeEnabled(true)
window.privateList.internalTreeView.SetSearchOnTypeEnabled(true)
} else if config.GetConfig().OnTypeInListBehaviour == config.FocusMessageInputOnTypeInList {
- guildList.SetInputCapture(treeview.CreateFocusTextViewOnTypeInputHandler(
+ guildList.SetInputCapture(tviewutil.CreateFocusTextViewOnTypeInputHandler(
guildList.Box, window.app, window.messageInput.internalTextView))
- channelTree.internalTreeView.SetInputCapture(treeview.CreateFocusTextViewOnTypeInputHandler(
+ channelTree.internalTreeView.SetInputCapture(tviewutil.CreateFocusTextViewOnTypeInputHandler(
channelTree.internalTreeView.Box, window.app, window.messageInput.internalTextView))
- window.userList.SetInputCapture(treeview.CreateFocusTextViewOnTypeInputHandler(
+ window.userList.SetInputCapture(tviewutil.CreateFocusTextViewOnTypeInputHandler(
window.userList.internalTreeView.Box, window.app, window.messageInput.internalTextView))
- window.privateList.SetInputCapture(treeview.CreateFocusTextViewOnTypeInputHandler(
+ window.privateList.SetInputCapture(tviewutil.CreateFocusTextViewOnTypeInputHandler(
window.privateList.GetComponent().Box, window.app, window.messageInput.internalTextView))
- window.chatView.internalTextView.SetInputCapture(treeview.CreateFocusTextViewOnTypeInputHandler(
+ window.chatView.internalTextView.SetInputCapture(tviewutil.CreateFocusTextViewOnTypeInputHandler(
window.chatView.internalTextView.Box, window.app, window.messageInput.internalTextView))
}
@@ -687,9 +687,12 @@ func (window *Window) ShowDialog(color tcell.Color, text string, buttonHandler f
}
window.dialogTextView.SetText(text)
window.dialogTextView.SetBackgroundColor(color)
-
window.dialogReplacement.SetVisible(true)
window.app.SetFocus(buttonWidgets[0])
+
+ _, _, width, _ := window.rootContainer.GetRect()
+ height := tviewutil.CalculateNeccessaryHeight(width, window.dialogTextView.GetText(true))
+ window.rootContainer.ResizeItem(window.dialogReplacement, 1+height, 0)
}
func (window *Window) registerMouseFocusListeners() {

* the dialog replacement now calculates its neccessary height