Prevent gtk2 toggle buttons and progress bars from stretching vertically - c

I'm trying to write an interface in GTK+2, and I can't find a way to make sure toggle buttons and progress bars won't try to fill up entire space avaiable to them.
My interface has a picture, and a bunch of progress bars and toggle buttons on the other side. If there's enough of them to make the entire vbox with them higher than the picture itself, everything is fine:
However, when there isn't enough of them, they get vertically stretched, which makes them look wrong:
I can't find any way to make sure this doesn't happen, the only thing that I found in the documentation related to setting height of these widgets is setting their minimal height. I'm looking for a way to ensure these widgets don't try to take up all space they can.
My code is here. I couldn't include the placeholder image that I'm using here, but it's just a 128x128 placeholder that can be easily replaced if needed.

When you create your widget for a single CPU, you add it to the parent container:
gtk_container_add(GTK_CONTAINER (vbox), current->box);
Container functions are generic for multiple types of widgets to hold children but don't allow specific adjustments.
In a box you can specify whether the available space should be added to the child widget and how it should appear.
To use this you need to change this line to:
gtk_box_pack_start(GTK_BOX(vbox), current->box, FALSE, FALSE, <borderline>);
This should prevent the widget to be enlarged.

Related

Why do `TextField`s sometime include its parent `Container`s and sometimes not when they start being edited?

I have a TextField inside a Container. The Container is in the SOUTH of a Form (BorderLayout). The Form's CENTER Contains a scrollable BoxLayout.y() Container
When the bottom TextField is tapped on Android, the keyboard is shown. Sometimes, it cuts the TextField's parent Container up to the TextField's bottom, sometimes it doesn't. When it does cut it, the Form's CENTER also gets pushed up, and the Toolbar disappears. I am trying to make sure that calling the keyboard never cuts the parent Container and that the CENTER Container doesn't get pushed up
Is there a way to guarantee that the parent Container is always shown so that it doesn't get cut?
Example of an instance when it doesn't get cut:
Example of an instance when it does get cut. Notice Toolbar is gone and CENTER Container is pushed upwards:
Generally this is really hard to tune positions for keyboard. We try to make it seamless but there are points where this is pretty difficult to control. Especially with a south placed text field which is static (not scrollable).
If you can isolate a test case that shows misbehavior here we might be able to fine tune the logic a bit.
Solution to prevent this consists in setting the Form's setFormBottomPaddingEditingMode(true);. Easy fix! 👍

Control width render animation in Codenameone

I have a page which has multiple vertical sections, each with a thermometer type control i have built, rendered on each. How do i code it so that when the page loads that the 'mercury' width, of all the sections, can grow in an animated way to fill the thermometers?
I have tried the samples provided for making the form.animateLayout(3000); but i've been unsuccessful in getting individual controls to grow their width concurrently..
FYI the thermometer is a Container, with a Table as its Layout, with a red Label placed on the container, at a specific width
outlineContainer.add(table.createConstraint().widthPercentage(90), mercuryLabel);
This is how i guarantee the thermometer mercury is at the correct width.
Thanks in advance.
You need to animate the direct parent of the growing element so something like this should work:
mercuryLabel.setWidth(0);
outlineContainer.animateLayout(1000);
Make sure you don't have revalidate, repaint or other related code that will disrupt this.

How to prevent widgets from expanding to whole box (GTK 2)

I'm having the following issue with GTK2:
I created two buttons with labels inside an horizontal box. (I intend to pile several hboxes)
However there's an issue: When I make the box_pack functions they go like this:
gtk_box_pack_start(GTK_BOX(hbox1), button1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox1), button2, FALSE, FALSE, 0);
Despite putting them both false, the buttons still expand vertically, making the "hbox1" ocupy all the space that is left on the parent box. I want the buttons to expand only to the minimum height required for the label to be displayed properly (like it usually happens on vertical boxes).
I heard that in GTK3 you could use the gtk_widget_set_vexpand and gtk_widget_set_hexpand functions. However, these do not seem to exist in GTK2, as they are on recognized....
Any solution for this?
(Not just this case with horizontal boxes, but with the respective case in vertical boxes)
This is an older question, but an important one. In short, set the valign property of the problematic widget to Gtk.Align.CENTER, just as #user7537486's comment on the original question said. Hope that solves it!
If I understood correctly, you need another hbox to behave like a expander, more or less like this:
|button|spander|
so, when you expand:
|button| spander|
button still at its minimum size....
is that what you asking for?

Get current width and height of an Embed Clutter Stage

I'm using Clutter to compose an interactive/animate UI.
I'm using two box containers (ClutterBox) with an integrated FixedLayout, and I want to be able to rearrange those boxes onto screen using an hard-coded layout during (gtk-)window resizing. Searching in some gtk3 examples, I find out this can be achieved connecting the signal "size-allocate" of the GtkWindow. What I still unable to accomplish is to get width and height of the Embed ClutterStage.
I used gtk_widget_get_preferred_size passing the ClutterStage widget, but it gives back to me only the preferred size, and not the current, resized value.
Does anyone have a clue?
calling clutter_actor_get_size() on the stage returned by a GtkClutterEmbed widget is enough to get the size of the stage: the GtkClutterEmbed widget that owns the embedded stage resizes the stage every time GTK+ negotiates the geometry of the widgets of a window.
you can also use a ClutterBindConstraint object to bind the size of an actor to the size of the stage, or a ClutterSnapConstraint or a ClutterAlignConstraint objects to resize or align actors to the stage.
Try gtk_widget_get_allocation().

Automatically sizing a GtkTextView in a GtkScrolledWindow

I work on gschem, a free software tool for editing electronics schematic diagrams. Recently we have encountered a problem using a GtkScrolledWindow containing a GtkTextView.
Context
Recent versions of Ubuntu use overlay scrollbars, which mean that GtkScrolledWindows no longer set a minimum height that provides enough room for a legacy scrollbar (in fact, they have a minimum height of 0). Likewise, a GtkTextView with no text to display requests a height of 0. This means that one of the scrollable GtkTextViews in gschem has been being displayed as one pixel in height, and this is obviously unusable.
In the dialog box on the right of the screenshot shown above, note the invisible widget between the "Value:" label and the "Add" button.
This has been reported independently by several users -- see also the bug report.
Question
Obviously, we could fix this by doing:
g_object_set (textview, "height-request", 100, NULL);
However, this is pretty inelegant, and will break for users who set very large font sizes in pixels (e.g. users with vision problems or who use high-DPI screens).
Ideally, therefore, we want to set the minimum size of the GtkTextView relative to the default font size, e.g. tell it to "show at least three lines of text".
Can anyone suggest a sensible/elegant approach for doing this?
Just disable the ubuntu overlay scrollbars in your application by doing:
putenv("LIBOVERLAY_SCROLLBAR=0");
Not ideal, but it's a quite good until you can find a more permanent solution. Alternatively just wait until Ubuntu disables overlay scrollbars...
I would add code to dig out the current/default style information, use that to figure out the font baseline height, and then compute some rough size allocation based on that, around three lines as you mention.
Does it have to be a textview ? If you can use an eventbox instead, then you can make a cairo surface from it, render the text with pango, and then use pango_layout_get_size() to get the text height.
Likewise, a GtkTextView with no text to display requests a height of 0.
Probably you can create GtkTextView with some text inside. Like several spaces, and set empty value after creation.

Resources