Open sineatos opened 5 years ago
It might be easier to give you an answer if you could provide a short example of the code that you're having trouble with. I'm not sure that I understand what's happening based on your description.
I created a new struct named ChatBox, and implemented the Manager
interface. The code is showed as follow:
package cui
import (
"github.com/jroimartin/gocui"
)
// ChatBox is A widget with a dialog box named "Dialog", a user list named "Chatters" and a input box
type ChatBox struct {
}
// Layout
func (m *ChatBox) Layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
termSize := &Size{W: maxX, H: maxY}
// init DialogBox
leftTop1 := DialogBoxLeftTop
rate1 := DialogBoxRate
vc1 := GetRectWithLP(leftTop1, termSize, rate1)
v1, err := g.SetView(ViewNameDialogBox, vc1.LT.X, vc1.LT.Y, vc1.RD.X, vc1.RD.Y)
if err != gocui.ErrUnknownView {
return err
}
v1.Title = TitleDialogBox
// init UserList
leftTop2 := UserListLeftTop
rate2 := UserListRate
vc2 := GetRectWithLP(leftTop2, termSize, rate2)
v2, err := g.SetView(ViewNameUserList, vc2.LT.X, vc2.LT.Y, vc2.RD.X, vc2.RD.Y)
if err != gocui.ErrUnknownView {
return err
}
v2.Title = TitleUserList
// init InputBox
leftTop3 := InputBoxLeftTop
rate3 := InputBoxInfoRate
vc3 := GetRectWithLP(leftTop3, termSize, rate3)
v3, err := g.SetView(ViewNameInputBox, vc3.LT.X, vc3.LT.Y, vc3.RD.X, vc3.RD.Y)
if err != gocui.ErrUnknownView {
return err
}
v3.Title = TitleInputBox
return nil
}
I set Views in Layout
, and the order of setting is DialogBox->UserList->InputBox
.
The GetRectWithLP
is used to get the position and size of View according to the current size of terminal.
Here is an example I met.
First, I used go run main.go
to start my code, and the terminal was showed as follow:
Then I resized the terminal and made it become larger than before, and the termial was showed as follow:
The red frames I marked in picture ("Chatters","Please ...") were fixed on the original positions while "Dialog" was resize when I resized terminal.
In my opinion, UserList and InputBox should become larger when I resized terminal because they are set in Layout
with DialogBox, however they didn't.
This appears to be a bug in GetRectWithLP
, rather than a bug in gocui
. gocui
does not ever manage the size or position of a View
automatically. You are always responsible for performing resize and relocation. It seems that your function is correctly resizing when you provide it with the details of the Dialog box, but not the other views.
I created a struct and implemented the
Manager
interface. More than one View is created in afunc Layout(g *gocui.Gui) error
byg.SetView
, and when I executeMainLoop()
, they can show in terminal.Here is my problem: I set these Views' size and position in
Layout
which are proportional to terminal size by usingg.SetView
, and when I executeMainLoop
, only the first View appears inLayout
can update the size and position when I adjust the size of terminal, while the others are fixed.This problem can be solved by managing only one View in a Manager, then create a lot of Manager. But I want to use a Manager to update sizes and positions of these Views when I adjust the terminal. Is it a bug or something I make wrong?