Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Athenian Hoplite

Pages: [1]
1
General / UI click detection
« on: May 26, 2020, 12:09:29 am »
Hey,

In implementing my UI I have come to a standstill.
Right now to detect which UI element is being being focused I simply transverse my UI layers top to bottom and check to see if the mouse position is inside the UI elements rect. If it is I check to see if it also is inside one of its children's rect, that way I can always focus the deepest-in-the-hierarchy element.

Consider this simple hierarchy:
- Panel
    - TextBox

If my textbox is actually placed outside of the rect of its parent (either the whole textbox or even a part of it) then I will never be able to focus it since I always check from top to bottom in the UI hierarchy. This could be fixed if I forced child UI elements to be inside their parent's rect but I don't like that restriction since it takes away too much flexibility.

Now to solve this I could change my system to use a quad tree in which I would place my UI elements and not only would the whole process be probably much faster but I would get around this last issue. However it would bring about the new issue where I could no longer guarantee that the focused UI element is the deepest in the hierarchy, and this would put me at the mercy of clicking in a text box inside a panel and having the system return me the panel as the focused element instead of the text box.

Any ideas ?

Thanks in advance,
AH

2
Graphics / sf::Text and "\n"
« on: May 25, 2020, 10:15:09 pm »
Hi,

When playing around with sf::Text today I noticed that when adding "\n" to the text's string it's width increased by 1. Is this always the case ? Or is it related to character size or character spacing in any way ?

Thanks in advance,
AH

3
General / [SOLVED] Text Input Field - Ideas for wrapping
« on: May 19, 2020, 03:19:11 pm »
Hi there,

First of all big praise to the dev team for this awesome library !

I am developing a game engine of sorts on top of SFML. With that comes the development of a UI system for it. I have already set up a sort of UI event system for dealing with events and distributing them to subscribers.

In implementing a text input field class I come to wonder how to deal with text wrapping on the end of the input field. Most fields (in most UIs I've used) usually simply continue to draw to the right as more characters are inserted and characters on the left are "lost" off the view.

I have already implemented this behaviour by using a RenderTexture to draw the sf::Text to and then drawing the RenderTexture to a final sprite. When input wraps I simply push the sprites' texture rect to the right (by adding on X) thus revealing the new text and stop rendering text on the left end.

This is all good but this forces me to create a rather big render texture so that I can continue to write on it. Lets say I have a 300x30 text field, the texture I use has to be at least 900x30 so that I can allow the user to input at least as much text as 3 times the text field size (for an example). This seems wasteful of memory (and texture binding/unbinding cost) ...

I tried simply erasing characters on the left of the text as the user reaches the limit on the right but as the characters have different sizes this sometimes results in a dance where 1 character removed on the left leaves space for 2 new ones on the right (which is annoying).

Any ideas ?

Thanks in advance

Pages: [1]