Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not update sizes and positions of views in a manager #182

Open
sineatos opened this issue Dec 17, 2018 · 3 comments
Open

Can not update sizes and positions of views in a manager #182

sineatos opened this issue Dec 17, 2018 · 3 comments

Comments

@sineatos
Copy link

I created a struct and implemented the Manager interface. More than one View is created in a func Layout(g *gocui.Gui) error by g.SetView, and when I execute MainLoop(), 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 using g.SetView, and when I execute MainLoop, only the first View appears in Layout 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?

@whereswaldon
Copy link

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.

@sineatos
Copy link
Author

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:
1

Then I resized the terminal and made it become larger than before, and the termial was showed as follow:
2

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.

@whereswaldon
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants