Comments (2)
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.
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)
- Mouse hover steals focus HOT 7
- When running hello world code: 30:22: undefined: text.TextContentSegment HOT 6
- Second example on gowid/docs/Tutorial.md doesn't compile HOT 1
- gowid.UrwidColor is invalid HOT 2
- gowid-terminal example hangs on DEL (xterm/vt220 backspace) HOT 3
- apps run slowly on weak systems when there's lots of mouse movement
- Create a new release HOT 3
- Some utf8 character widths were miscalculated in the terminal component HOT 4
- broken on go 1.15.2? HOT 3
- Release new version HOT 3
- How to implement this layout HOT 6
- Most of the images/screenshots in Widgets.md are missing HOT 1
- Application crashes - "integer divide by zero" HOT 4
- Terminal widget crashes: invalid memory address or nil pointer dereference HOT 1
- [Feature request] Handling mouse double-click in button widget HOT 3
- [Feature Request] Scroll support in terminal widget HOT 19
- [ QUESTION ] Update widget NOW HOT 2
- Application crashes sometimes in RedrawTerminal HOT 2
- Crash in RedrawTerminal: index out of range HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gowid.