text_area class

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Post Reply
enki
Posts: 60
Joined: December 28th, 2003, 8:04 pm
Location: Linköping, Sweden

text_area class

Post by enki »

I'm currently writing a text_area class. This is static text widget with support for word-wrapping. I've just started hacking on it and there is still much to do, but the basic features work at least (unless a single word is too long) and there shouldn't be too difficult to fix the rest of it (and make the code a bit cleaner). Before I continue working on it, I just wanted to check if this is something that other people are interested in? If so, maybe you have feature requests and comments? When the code matures a bit I can post the interface here if someone is interested.

My idea is that you specify the maximum-width of the component and that the height will depend on the amount of text. It should also be possible to specify a maximun-height which would make the text scrollable if it's too big. (Scrolling isn't implemented yet)

It will be quite straightforward to use. You create a text_area and specify the text, width and so on. When you want to display the text you just call "show()" and if you want to hide it again you call "hide()".
jacob

Re: text_area class

Post by jacob »

enki, I think such a class could be useful, since some text in the game seem to be clipped if there is too much text. I was thinking of modifying the menu class, and considered making a scrollbar class, so it could be used elsewhere too. If you use font::draw_text(), however, maybe I could instead reuse your text_area class.

One thing: would you consider making it possible to scroll the text in pixel rather than a whole line at the time? I.e. so the topmost visible line may be only partially visible, so you can scroll text the same way as you do in most GUI programs (smoothly, rather than one line at the time). Clipping the text is pretty simple using the surface_restorer class in sdl_utils.
enki
Posts: 60
Joined: December 28th, 2003, 8:04 pm
Location: Linköping, Sweden

Re: text_area class

Post by enki »

jacob wrote:enki, I think such a class could be useful, since some text in the game seem to be clipped if there is too much text. I was thinking of modifying the menu class, and considered making a scrollbar class, so it could be used elsewhere too. If you use font::draw_text(), however, maybe I could instead reuse your text_area class.
Yeah, I heard that there were problems with clipped text for some translations, this class would probably solve this problem.

It's hard to say if it's possible to reuse it for the menu class. I'm not sure how you want to use it? Are there any need for multi-line text in that class? I'm using font::draw_text() to draw the actual text in the end, but I'm not sure if that's what you referred to? I could try to make it fit your need as well (if it's not to difficult).

I was thinking about creating a scrollbar class as well, but if you want to implement it that would be great :). It would be nice to have a common scrollbar that would work for any kind of widget. Maybe we should start at new topic and discuss this? Do you have any ideas on how to implement it?
jacob wrote:One thing: would you consider making it possible to scroll the text in pixel rather than a whole line at the time? I.e. so the topmost visible line may be only partially visible, so you can scroll text the same way as you do in most GUI programs (smoothly, rather than one line at the time). Clipping the text is pretty simple using the surface_restorer class in sdl_utils.
Yeah, I'm planning to scroll the text in pixels (probably easiest to implement :)), but if people want line-scrolling as well I can probably implement that as an option.
jacob

Re: text_area class

Post by jacob »

enki wrote: Are there any need for multi-line text in that class?
Yes, but the menu class needs to do more event handling, and maybe it would be difficult to use a text_area for the menu because of this. You do not need to butcher the interface to adapt to this. Anyway, if we could develop a scrollbar widget, it could be used by both classes.
enki wrote: Maybe we should start at new topic and discuss this? Do you have any ideas on how to implement it?
Yes, I think we should. I do have a few ideas, but I am not certain of anything yet.
enki
Posts: 60
Joined: December 28th, 2003, 8:04 pm
Location: Linköping, Sweden

draw_wrapped_text

Post by enki »

Ok, I'm putting the text_area class on ice of a while, since I don't have any direct need for it. I've created a draw_wrapped_text method instead and added it under the font namespace. This method works similar to the draw_text method, but it makes sure that the text fits within a specified maximum width.

The drawback with this method is that it doesn't support makup in the text. This can be added if there is need for it.

I'll create a patch and put it on Savannah in a short while. Comments are appreciated.

cheers,

-- enki
darksteel
Posts: 243
Joined: August 14th, 2004, 11:38 pm
Location: Somewhere near a big dark eye made of steel

hi

Post by darksteel »

:oops: :P :? :) :( :o :lol: :cry: :wink: :idea: :roll: :twisted: :evil: :shock: :D :!: hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiijavascript:emoticon(':arrow:')javascript:emoticon(':wink:')
Post Reply