fixed window title string length
This commit is contained in:
parent
93e87a05c7
commit
5bae8b7e41
|
@ -88,7 +88,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
tk.dumpWidget("mouse drag()")
|
||||
tk.dumpWidget("mouse drag()" + tk.labelN)
|
||||
me.currentDrag = tk
|
||||
tk.dragW = w - tk.gocuiSize.w0
|
||||
tk.dragH = h - tk.gocuiSize.h0
|
||||
|
|
|
@ -13,13 +13,10 @@ func (tk *guiWidget) doWindowClick(w int, h int) {
|
|||
// if there is a current window, hide it
|
||||
if me.currentWindow != nil {
|
||||
me.currentWindow.setColor(&colorWindow)
|
||||
// me.currentWindow.hideWidgets()
|
||||
me.currentWindow.isCurrent = false
|
||||
}
|
||||
|
||||
// now set this window as the current window
|
||||
me.currentWindow = tk
|
||||
me.currentWindow.isCurrent = true
|
||||
|
||||
tk.redrawWindow(w, h)
|
||||
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
||||
|
|
|
@ -128,6 +128,7 @@ type window struct {
|
|||
active bool // means this window is the active one
|
||||
isBG bool // means this is the background widget. There is only one of these
|
||||
order int // what level the window is on
|
||||
resize bool // only set the title once
|
||||
}
|
||||
|
||||
type guiWidget struct {
|
||||
|
@ -154,7 +155,6 @@ type guiWidget struct {
|
|||
force rectType // force widget within these boundries (using this to debug window dragging)
|
||||
startW int // ?
|
||||
startH int // ?
|
||||
isCurrent bool // is this the currently displayed Window or Tab?
|
||||
isFake bool // widget types like 'box' are 'false'
|
||||
widths map[int]int // how tall each row in the grid is
|
||||
heights map[int]int // how wide each column in the grid is
|
||||
|
@ -162,8 +162,8 @@ type guiWidget struct {
|
|||
frame bool // ?
|
||||
selectedTab *tree.Node // for a window, this is currently selected tab
|
||||
color *colorT // what color to use
|
||||
resize bool // the window is currently being resized
|
||||
isBG bool // means this is the background widget. There is only one of these
|
||||
// resize bool // the window is currently being resized
|
||||
isBG bool // means this is the background widget. There is only one of these
|
||||
}
|
||||
|
||||
// from the gocui devs:
|
||||
|
|
32
treeDraw.go
32
treeDraw.go
|
@ -38,19 +38,17 @@ func (tk *guiWidget) drawView() {
|
|||
c := tk.gocuiSize.w1
|
||||
d := tk.gocuiSize.h1
|
||||
|
||||
// this is all terrible. This sets the title. kinda
|
||||
if tk.node.WidgetType == widget.Window {
|
||||
if !tk.resize {
|
||||
tk.resize = true
|
||||
tk.textResize() // resize window only once
|
||||
} else {
|
||||
tk.full.w0 = tk.force.w0
|
||||
tk.full.h0 = tk.force.h0
|
||||
// for windows, make it the full size
|
||||
a = tk.full.w0
|
||||
b = tk.full.h0
|
||||
c = tk.full.w0 + 20
|
||||
d = tk.full.h0 + 2
|
||||
}
|
||||
tk.textResize()
|
||||
tk.full.w0 = tk.force.w0
|
||||
tk.full.h0 = tk.force.h0
|
||||
|
||||
// for windows, make it the full size
|
||||
a = tk.full.w0
|
||||
b = tk.full.h0
|
||||
c = tk.full.w0 + tk.gocuiSize.Width()
|
||||
d = tk.full.h0 + tk.gocuiSize.Height()
|
||||
} else {
|
||||
if tk.internal {
|
||||
// do nothing
|
||||
|
@ -76,16 +74,6 @@ func (tk *guiWidget) drawView() {
|
|||
return
|
||||
}
|
||||
|
||||
// this sets up the keybinding for the name of the window
|
||||
// does this really need to be done? I think we probably already
|
||||
// know everything about where all the widgets are so we could bypass
|
||||
// the gocui package and just handle all the mouse events internally here (?)
|
||||
// for now, the w.v.Name is a string "1", "2", "3", etc from the widgetId
|
||||
|
||||
// set the binding for this gocui view now that it has been created
|
||||
// gocui handles overlaps of views so it will run on the view that is clicked on
|
||||
// me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
||||
|
||||
// this actually sends the text to display to gocui
|
||||
tk.v.Wrap = true
|
||||
tk.v.Frame = tk.frame
|
||||
|
|
|
@ -73,21 +73,6 @@ func (w *guiWidget) deleteView() {
|
|||
w.v = nil
|
||||
}
|
||||
|
||||
func (w *guiWidget) IsCurrent() bool {
|
||||
if w.node.WidgetType == widget.Tab {
|
||||
return w.isCurrent
|
||||
}
|
||||
if w.node.WidgetType == widget.Window {
|
||||
// log.Log(GOCUI, "IsCurrent() found current window", w.cuiName, w.String())
|
||||
// log.Log(GOCUI, "IsCurrent() window w.isCurrent =", w.isCurrent)
|
||||
return w.isCurrent
|
||||
}
|
||||
if w.node.WidgetType == widget.Root {
|
||||
return false
|
||||
}
|
||||
return w.parent.IsCurrent()
|
||||
}
|
||||
|
||||
func (tk *guiWidget) String() string {
|
||||
return tk.node.String()
|
||||
}
|
||||
|
|
47
view.go
47
view.go
|
@ -4,53 +4,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/widget"
|
||||
)
|
||||
|
||||
func splitLines(s string) []string {
|
||||
var lines []string
|
||||
sc := bufio.NewScanner(strings.NewReader(s))
|
||||
for sc.Scan() {
|
||||
lines = append(lines, sc.Text())
|
||||
}
|
||||
return lines
|
||||
}
|
||||
// expands the gocuiSize rectangle to fit
|
||||
// all the text in tk.labelN
|
||||
func (tk *guiWidget) textResize() {
|
||||
var w, h int = 0, 0
|
||||
|
||||
func (w *guiWidget) textResize() bool {
|
||||
// w := n.tk
|
||||
var width, height int = 0, 0
|
||||
var changed bool = false
|
||||
|
||||
for i, s := range splitLines(w.labelN) {
|
||||
log.Log(INFO, "textResize() len =", len(s), i, s)
|
||||
if width < len(s) {
|
||||
width = len(s)
|
||||
for _, s := range strings.Split(tk.labelN, "\n") {
|
||||
s = strings.TrimSpace(s)
|
||||
// log.Log(INFO, "textResize() len =", len(s), i, s)
|
||||
if w < len(s) {
|
||||
w = len(s)
|
||||
}
|
||||
height += 1
|
||||
h += 1
|
||||
}
|
||||
if w.gocuiSize.w1 != w.gocuiSize.w0+width+me.FramePadW {
|
||||
w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW
|
||||
changed = true
|
||||
}
|
||||
if w.gocuiSize.h1 != w.gocuiSize.h0+height+me.FramePadH {
|
||||
w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH
|
||||
changed = true
|
||||
}
|
||||
if changed {
|
||||
// w.showWidgetPlacement("textResize() changed")
|
||||
}
|
||||
return changed
|
||||
|
||||
// this is old code. now move this somewhere smarter
|
||||
tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + me.FramePadW // TODO: move this FramePadW out of here
|
||||
tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + me.FramePadH // TODO: fix this size computation
|
||||
}
|
||||
|
||||
func (w *guiWidget) hideWidgets() {
|
||||
if w == nil {
|
||||
return
|
||||
}
|
||||
w.isCurrent = false
|
||||
switch w.node.WidgetType {
|
||||
case widget.Root:
|
||||
case widget.Flag:
|
||||
|
|
Loading…
Reference in New Issue