I am having a (vertical) GTK FlowBox that has multiple children. All but the last are having no fixed size and are just filling the space their child control needs. The last element is in a GtkScrolledWindow and supposed to fill the remainder of the GtkFlowBox. I have tried several layout options but none of them makes the last child fill the remainder of the GtkFlowBox.
The things I have tried:
Setting vertical alignment to Fill for the GtkFlowBoxChild, the GtkScrolledWindow and its child GtkTreeView
Setting the Expand Vertical to TRUEfor all the controls mentioned above
Is it possible to have an element of the GtkFlowBox fill the remainder of the box?
I am using GTK version 3.22.30
My solution was to use a regular GtkBox instead of a GtkFlowBox and make all but the last elements vertically aligned to the start.
Related
I've got this sfml window that displays a text and now I want to make it markable so that you can copy the text.
Any ideas how to do that?
If you just want to copy everything then just use
sf::Clipboard::setString(your_string_here);
If you want more features, here are some I implemented when I programmed a Code Editor in SFML.
I stored two indexes, the first is where the selection begins, and the second is where the section ends.
So in the string Hello World!, if you wanted to select World you would set the begin index to 6, and the end index to 10 or 11 (depending on whether you include the final character or not).
I render this using an sf::RectangleShape, since my editor supported multiple line selection boxes the code is more complicated, but for your example you would want to get the position of each character. I used my own text renderer, but SFML's sf::Text::findCharacterPos() should be able to help with that.
Next the copy part, this is just
sf::Clipboard::setString(getSelected());
where getSelected() is
return std::string::substr(selection_begin, selection_end - selection_begin);
If you want pasting as well then it is also simple:
eraseSelected();
insertStringAtCursor(sf::Clipboard::getString());
Which are both simple string operations as well (std::string::erase and reset the selection indexes, and std::string::insert).
Finally, to let the user change what is selected, either holding shift and pressing the arrow keys or clicking and dragging are both common ways, the former being easier than the latter.
For the former, check if shift is held and then if left or right is pressed update the indexes.
For the latter, you will need to handle mouse events and dragging. When dragging begins, set one of the indexes, whilst the mouse is moving and is dragging set the other index.
I am automating our mobile app on iOS and Android. When I get the search results(list of elements), I want to iterate through those all elements matching my xpath.
The problem is that - Appium returns only those elements which are visible in the viewport, which makes sense. However, I would like to get all elements matching my xpath/locator strategy, although the elements are not in viewport. To get further set of elements, I have to scroll to those elements and get them into viewport.
Is there any configuration provided by appium, to enable this feature? Or will I have to continue scrolling to those elements before accessing?
You need to handle scrolling on your own.
On Android, Appium can make a snapshot of what is currently in the viewport.
You can get a list of elements and iterate them, then scroll by screen hight and get another list of elements, iterate them. Repeat it until the new list is empty - make sure you don't get same elements twice.
On iOS, it's more tricky: the driver will return you elements including the ones not in the viewport. For reliable interaction, I suggest scrolling to each element.
I am creating a custom single line edit control, with a custom font in win32 api on windows 7, the font is not a fixed width font, and I need to move caret according to the mouse click, The edit control is not empty and if I know the horizontal position of the mouse click within the window, how do I calculate the number of characters after which I need to move caret to ?
I really am out of ideas, if it was a fixed width font, I would have divided the horizontal mouse click position with average character width, that would have been simpler, doing the same with not a fixed width font, is prone to errors.
Given that it's a single-line control, you probably don't plan on working with immensely long input (at least normally). That being the case, one possibility would be to just store the character positions in an array (or vector, etc.) Then you can use (for example) a binary search in that array to find character positions. Of course, you can do the same even for longer strings--though it can increase storage requirements quite a bit.
This is a familiar problem. You are in essence trying to do hit testing on text and for that you need the location on the screen of each character of the text.
My preferred strategy is to calculate an array of RECT, one for each character of displayed text. The array needs to be updated when text is added or deleted, but it easily handles single or multiple lines. The function GetCharWidth32 retrieves all the widths for a string of text in a particular font selected into a DC. For single line one call is enough, and calculating the array of RECTs is simple. It's not much harder to do multiline.
Handle the mouse down message, loop through the array and find the right character. A brute force search is plenty fast enough.
This method is simple and easily generalises to a range of similar problems.
In QtCreator I created a QSplitter which separates vertically a QTreeWidget from a vertical layout with many things on the right.
I would like that this second column by default takes the minimum space it needs to maximise the first one.
I tried setting sizes and vertical policy of the splitter as expanding but surely I'm not doing it right. How can I set this exactly?
You can set this in code with QSplitter::setStretchFactor(int index, int stretch).
You would set the first column to have a stretch of 1 and the second 0.
splitter->setStretchFactor(0, 1);
splitter->setStretchFactor(1, 0);
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