简体   繁体   English

Xlib:绘制文本输入框并在键入时读取文本

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

I am trying 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. 我希望能够使用箭头键来编辑该文本,因为我希望用段落来完成此操作,而不是7个字母的拼写。

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? Xlib可以这样做吗? Is there something else that might be more suitable? 还有其他更合适的东西吗? Thanks! 谢谢!

Can Xlib do this? Xlib可以这样做吗?
Why yes, Xlib can do a lot of things. 为什么会这样,Xlib可以做很多事情。 What you describe seems simple enough by using X's event processing and drawing functions . 通过使用X的事件处理绘图 功能,您所描述的内容似乎足够简单。

Xlib is pretty crufty, though, and IMO you should only use it if you need closeness to the X protocol. 但是,Xlib非常笨拙,而IMO仅在需要与X协议紧密相关时才应使用它。 (Even then there are newer replacements like XCB. But I digress.) (甚至还有更新的替代品,例如XCB。但我离题了。)

You might find it easier to work with a modern toolkit, like GTK+ or Qt. 您可能会发现使用GTK +或Qt等现代工具包更容易。

For example, this might be expressed as a GtkEntry with a "key-press-event" handler. 例如,这可以表示为带有“按键事件”处理程序的GtkEntry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM