rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
10.69k stars 560 forks source link

keep focus on the modal #806

Open tcurdt opened 1 year ago

tcurdt commented 1 year ago

When I have two pages, one for a modal

    pages := tview.NewPages()
    pages.AddPage("background", background, true, true)
    pages.AddPage("modal", modal(edit, 50, 20), true, true)

I can still switch focus with the mouse and access the controls that are in the background. Is there an easy way to disable this?

I know I could use HidePage() before I open the modal but I would like to still have the background visible - just not accessible.

tcurdt commented 1 year ago

I just found this dialog implementation that wraps the input/mouse handler. That's the only way I assume?

digitallyserviced commented 1 year ago

@tcurdt Read the document comments for the functions you are using. AddPage is ("name", primitive, resize, FOCUSED).... focus determines if input is received.

tcurdt commented 1 year ago

@tcurdt Read the document comments for the functions you are using. AddPage is ("name", primitive, resize, FOCUSED).... focus determines if input is received.

It's visible and not focused

https://github.com/rivo/tview/blob/master/pages.go#L64

func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages {

...and from the comments it sounds like SetFocus is called from the library. So 🤷‍♂️

digitallyserviced commented 1 year ago

Sorry, confusing from flex's additem, but yes setfocus can be called on the app instance to specify the focus..

I would recommend just browsing the demos and docs for the library as a lot of this stuff is explained. Also many issues already exist that you can search for examples.

Look at the list of applications using tview. See how they are doing things. That is your best tool as a developer, learning how to find how to do things on your own without needing it to be pointed out. Reading the source, looking through existing apps. Searching... I will admit that the focus/input system of tview is kinda crappy but it can be worked around or even just avoided and come up with your own way of handling focus/input.

Check out tslocum/cview

tview is a great lib to use and build on. See example below... the base is tview but used creatively with additional primitives/focus/viewstackinig then the original...

Just going to have to work with it! demo3

tcurdt commented 1 year ago

setfocus can be called on the app instance to specify the focus..

But we are on the page level and the focus can also be set by the mouse. So I don't get how how that is relevant.

I would recommend just browsing the demos and docs for the library as a lot of this stuff is explained. Also many issues already exist that you can search for examples.

Not my first rodeo and I only open issue when I have

If I have missed information I am sorry and would love a link pointing me into the right direction.

Look at the list of applications using tview. See how they are doing things.

Searching 10+ other projects in the hope they have implemented what I am looking for is not a particular great use of our collective time TBH. But I have already linked to an implementation further up and would just like to know if that's the intended way of doing things.

Check out tslocum/cview

I came across it before - not sure how I feel about the whole gitlab/self-hosted/mirrored storry.

tview is a great lib to use and build on. See example below... the base is tview but used creatively with additional primitives/focus/viewstackinig then the original...

Without a link to the code it's a nice encouragement - but otherwise not that helpful ;) Maybe add that as another demo?

digitallyserviced commented 1 year ago

All of cview's addition's are also avail as PR's to the tview project....

https://github.com/rivo/tview/pulls?q=is%3Apr+is%3Aopen+author%3Atslocum+sort%3Aupdated-desc

The wiki has great detail on input/focus etc... https://github.com/rivo/tview/wiki/Primitives#hooking-into-key-events

There is no one specific link that will make it click for you. Like no one specific has made it for me. Maybe being self-taught I am a bit hard pressed for good advice other than what I have provided.

Every person has their own ways...

Good developers write good code, great developers copy good code, elite developers delete good code.

OsvaldoTCF commented 4 months ago

When I have two pages, one for a modal

  pages := tview.NewPages()
  pages.AddPage("background", background, true, true)
  pages.AddPage("modal", modal(edit, 50, 20), true, true)

I can still switch focus with the mouse and access the controls that are in the background. Is there an easy way to disable this?

I know I could use HidePage() before I open the modal but I would like to still have the background visible - just not accessible.

. image .

Perhaps the solution is to interfere with the flow of mouse events by accepting only events destined for the current primitive.

OsvaldoTCF commented 4 months ago

This way worked for a small example. The ideal would be to get the "primitive" on which the "click" is being made.

// if err := tview.NewApplication().SetRoot(pages, true). SetMouseCapture(mcap).EnableMouse(true).Run(); err != nil { panic(err)

func mcap(event tcell.EventMouse, action tview.MouseAction) (tcell.EventMouse, tview.MouseAction) { if action == 0 { return event, action }

x, y := event.Position()
if (x > 30 && x < 60) && (y > 10 && y < 20) {
    return event, action

}

return nil, action

}