Coder Social home page Coder Social logo

Comments (2)

gcla avatar gcla commented on May 18, 2024

Hi - sorry for the long delay in replying. One suggestion would be to do it like this, from termshark:

https://github.com/gcla/termshark/blob/master/widgets/filter/filter.go#L241

In short, a callback is set on the edit widget which is invoked when the text changes. I use that to set the background color of the filter, depending on whether what is entered is syntactically valid. Will that work for your use case?

Another approach might be to keep a boolean flag that is set when your widget is rendered (via Render()) with the focus flag set; then when Render() is next invoked with focus not set, and with your custom flag set, clear it, and run the validation. So I suppose the custom flag is just to make sure you don't run validation every single screen render, only each time focus is lost. I haven't tried this way myself though. Let me know!

from gowid.

gcla avatar gcla commented on May 18, 2024

Hi @asv - I know it's been a while since you opened this...

I thought I'd let you know I implemented a similar feature to this in termshark. Here's a widget that helps track losing or gaining focus: https://github.com/gcla/termshark/tree/streams/widgets/trackfocus. The widget itself keeps track of how it was last rendered, and when that changes (not focus -> focus and vice-versa) issues a callback. Here's an example use of it:

https://github.com/gcla/termshark/blob/streams/widgets/streamwidget/streamwidget.go#L639

There's a small catch. Depending on the way you layout widgets, sometimes a gowid app has to call a widget's Render() function in order to determine the size at which it will render within a container, even though the canvas returned isn't used at that point. For example, a list widget sometimes needs to know how much space each child takes to make scrolling decisions - but if the child is rendered as a "flow" widget (columns specified but as many rows as it needs), then gowid has to actually render it to find out. I haven't accounted for that case yet, but this works for my current use.

from gowid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.