How to increase the width of the stats name column in OpenSceneGraph? - c++

I've added some user stats to the OSG stats handler. Unfortunately, the 'title' column does not seem to expand automatically based on the width of the added user stats names.
Is there a way I could change the width of the title column?
The issue it causes now is if the 'bar' for my user stat begins at 'zero', the bar will be drawn over the time, preventing the users from reading it.
In the image above, the vertical white hair line should come after SimFrameTime:113.67 so it can be read correctly when the bar fro the frame starts at 'zero'.

The frame tick lines position are fixed in screen space, they do not take into account the text size.
See the implementation in file osgViewer/statsHandler.cpp - the first line is drawn at "_startBlock" which is hardcoded to 150 "units" in the ortho camera space.
You can either change that value in your copy of OSG or expose the value in the StatsHandler class interface and submit a patch if you want official osg to support this feature.

Related

Cutting of parts of sf::Text, sf::Texture, etc?

I'm creating a simple chat client and server and I'm having some issues with how sf::Text is rendered. Say in the chat history for example. When users type their messages, the old messages will be pushed up. Eventually the message hits the top and I'll want to only display the part of the message that is still within the chat history. This is where I'm lost.
The element containing the text has two visible objects - sf::RectangleShape (the background for the text) and a sf::Text. I can easily adjust the size of the shape once it hits the top so it's not visible outside the chat history, but I can't adjust the size of the text without distorting the contents. Changing the character size obviously isn't ideal either.
What I want is to cut the text in half horizontally if half of the text is outside the chat history. My first thought was to mask it somehow but it seems like SFML has no support for that.
The reason I'm mentioning sf::Texture in the title as well is because I've had the same issue with that in the past. I just couldn't find a way to cut off parts of it, I only managed to distort it.
Is this possible at all in SFML?
One way of doing this is to draw the chat history to a sf::RenderTexture, which is the tool used for off-screen rendering.
Once you've drawn the chat history to your render texture, you can draw the texture on to the screen.
So if you place text that is half on the render texture and half outside, only the part that actually fits on there will be drawn.
Be aware though that render_texture are fairly expensive to construct, so you you want to re-use them and not create new ones all the time.

QTextEdit "pre-allocate" canvas size

I'm writing a simple text editor client that receives a given file in chunks, instead of reading it all in at once. For example, if I have a 10,000 line file, I'll only get the first 25 lines + some slop when I open it up in the client. As I scroll down the file, it'll load the lines that come into view dynamically.
I've got the dynamic insertion of the file contents working as I scroll around the file. However, I want the QScrollBar to reflect the full size of the file when a file is opened, instead of just the current contents of the QTextDocument.
Here it is in screenshot form:
The QTextEdit and QScrollBar when a file is initially loaded with just the first chunk of lines.
The same thing, once I've scrolled to the bottom of the file and the rest of it has been loaded.
Note the smaller QScrollBar slider.
I'm wondering if there's some kind of way to preset the size of the underlying canvas, i.e. it would be easy to calculate the height of the full document in pixels, and then make the QTextEdit scroll area that size. Preferably without having to resort to painting. Any other ideas are also welcome.
You need to start with programmatically setting the range of the vertical scrollbar:
textEdit->verticalScrollBar()->setMaximum(numberOfLines);
See the documentation for more details: QAbstractSlider::setMaximum()
In addition, you will probably need to implement custom behavior when the QAbstractSlider::sliderMoved(int) signal is emitted. The idea is that your canvas stays small, it only provides a small window on the complete text.

How to check if the length or width of Row in a window is greater than the width of its parent window C++

I wanted to wrap the existing text of checkbox into multiline if the width of row exceeds the width of its parent window. I am not really sure how to do that.
The image I want to show the checkbox string
The image where the string is cropped and only shows if window is resized or maximized
You are going to have a problem with this I am afraid.
The setting for making a checkbox multiline is ES_MULTILINE and if you look here you will see that it states:
To create an edit control using the CreateWindow or CreateWindowEx function, specify the EDIT class, appropriate window style constants, and a combination of the following edit control styles. After the control has been created, these styles cannot be modified, except as noted.
So, it would seem to me that you have three ways forward, depending on what you feel is the best or most elegant for you.
Set your control in the resource editor as multiline anyway. Then it doesn't matter and will wrap. No need to have to change the setting.
Implement the needed functionality to limit the size the window can be reduced to. I can show you how if you are interested. This way, if you set the control resize properties correctly it can resize larger but only reduce down the a known dimension (ie: the dimensions you created it in the resource editor).
Possibly have two controls in the same place, one as multiline and one as single. And when you decide which you want to show, swap the visibility. But I think this is a bad idea, bit of a headache, and not worth the hassle.
IMHO I would do both ideas 1 and 2 and I would happily extend my answer to provide more information.
Update
Having looked at your images and the comments about translations then there is a fourth idea. If you use a third party application to manage the translations and use satellite DLL files then you can adjust the resources on a language by language basis. I sometimes have to make the default width for some windows wider due to their verbose nature.
I have set BS_MULTILINE for the checkbox. The minimum size of the window is fixed but I just want the checkbox to fit in that. I expect it to show at least one word in the same line as other labels and remaining words in second line. So I am checking if the total width of the first row is greater than the width of window then show the string with \r\n in it else show normal string. However, I want to align first line or the first word of the checkbox with the checkbox and remaining words should come below the first word. Currently, the checkbox is in between two lines which looks weird. Is there anyway I can do this?

How to provide a custom column width calculation for CListCtrl?

I'm using a CListCtrl with my own "DrawItem" to draw some custom graphics into the first column, in front of the text. The text is moved ~20 pixels to the right for this. That part works.
If the user double-clicks the column divider in the header, Windows calculates the best column width. But of course Windows doesn't know my custom drawing. So the result is ~20 pixels too small for the first column.
How can I correct that?
Found a workaround:
I can trick MFC into thinking that the list control uses checkboxes:
pMyList->SetExtendedStyle(pMyList->GetExtendedStyle() | LVS_EX_CHECKBOXES);
The user will never ever see the system's checkboxes (because of my custom drawing), but this gives me just the space that I need.

How to display scrollbar for a list view whose contents keep changing?

I have a ListView-like control that displays a list of items of various heights. The contents of the list, and the heights of the items can change – a background thread is populating the list and calculating the layout of each item, possibly even while the user is scrolling the content.
Which brings me to my question: How do I display a useful vertical scrollbar for this view? I’ve seen cases (notably web browsers) where the slider “jumps away” from the mouse cursor while the user is dragging it, the result of the underlying content growing in height. I don’t want that.
So far
Instead of the slider representing the viewport height relative to the content height, maybe it could represent a point in a timeline instead? (The items are sorted by timestamp). This would at least prevent the scrollbar from changing as item layouts are calculated.
Get rid of the scrollbar altogether and use a forward/backward rocker switch like the one used in Picasa (the further the slider is pulled upwards or downwards, the faster the view is scrolled, until the user releases the slider). If I take this route, are there any controls you can recommend?
I am using Qt, but this applies to UI design in general.
IMO the fundamental problem with a classic scrollbar is that due to background population, the valid range is changing - and thus, the meaning of a scrollbar position changes.
If you can predict the full range of items, you can still provide a scrollbar and replace yet-unknown items with "loading...".
Otherwise, a rocker (is that an official name?) would be the next best thing to use.
However, since you have a dedicated scale (timeline), it might be better to have separate buttons that jump a dedicated time (e.g. one minute, one hour, one day, ..). For a fancier look, you could create a rocker with "hot" areas that jump for a specific time, whereas the areas inbetween are interpolated (linear or or logarithmic, depending on the scale to cover).
i.e. line this (drawing just the "backward" half):
--------------------------
|##|XXXXXXX|##|XXXXXXX|##|
--------------------------
-1h -1m -1s