开发者

Xlib: draw a text input box and read text as it is typed

开发者 https://www.devze.com 2023-02-06 19:35 出处:网络
I am tryi开发者_运维问答ng to implement a text box where a user can type, use arrow keys, backspace, delete, etc.I would like to be able to know what is in this text box without the user needing to su

I am tryi开发者_运维问答ng to implement a text box where a user can type, use arrow keys, backspace, delete, etc. I would like to be able to know what is in this text box without the user needing to submit anything. I suppose I could catch keypress events, find a way to display a cursor, and basically build a min-text-editor by hand--but maybe that would be reinventing the wheel?

What I am after is rather scrabble-like. You have several letters in the top part of a window and a text box in the bottom. Each time you type a letter it disappears from the top pane so that you know when you've used them all up. I want to be able to edit that text with the arrow keys, 'cause rather than the 7 letters scrabble would give me I hope to be doing this with paragraphs.

I have the window displaying, and the source file processed and displayed as a list of allowable letters... I just want to update the list of allowable letters while the user types in their sentence. Can Xlib do this? Is there something else that might be more suitable? Thanks!


Can Xlib do this?
Why yes, Xlib can do a lot of things. What you describe seems simple enough by using X's event processing and drawing functions.

Xlib is pretty crufty, though, and IMO you should only use it if you need closeness to the X protocol. (Even then there are newer replacements like XCB. But I digress.)

You might find it easier to work with a modern toolkit, like GTK+ or Qt.

For example, this might be expressed as a GtkEntry with a "key-press-event" handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消