Re: Widget sizing?



A GtkLayout does not seem to work, it seems that it does indeed request the
size of its children, so that if I put a GtkLayout inside a GtkWindow, and
I size the GtkLayout to a specific size, then I cant resize the window
smaller than that.

I have included a simple toy sample that demonstrates the issue I am
having.  If you run it, and resize the window, you cant ever make the
window smaller.

If I dont "request size" for the GtkLayout, then it is always a zero size
(or its initial size) so that any buttons or other widgets I put in it clip
immediately.  All of the children (so the layouts inside of the layouts, or
any widgets inside of those) are all sized based on the root (Window) size,
but I cant resize the root window because those widgets are all holding it
to a minimum size. I don't know what to do to solve this.  Any help solving
this would be much appreciated.

#include <gtk/gtk.h>
static void container_resize( GtkWidget *widget, GdkEvent *event, gpointer
data)
{
    gtk_widget_set_size_request((GtkWidget*)data, event->configure.width,
event->configure.height);
}

int main( int   argc, char *argv[] )
{
    gtk_init (&argc, &argv);

    // Create the Window
    GtkWidget *window;
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    // Create the GtkLayout child
    GtkObject* wadjust = gtk_adjustment_new(0, 0, 0, 0, 0, 0);
    GtkObject* hadjust = gtk_adjustment_new(0, 0, 0, 0, 0, 0);
    GtkWidget* layout = (GtkWidget*)
gtk_layout_new((GtkAdjustment*)wadjust, (GtkAdjustment*)hadjust);
    gtk_widget_set_size_request(layout, 500,500);
    gtk_container_add (GTK_CONTAINER (window), layout);

    // Connect to our resize function
    g_signal_connect (window, "configure-event", G_CALLBACK
(container_resize), layout);

    // Show Everything
    gtk_widget_show(layout);
    gtk_widget_show  (window);
    gtk_main ();

    return 0;
}



On Thu, Nov 13, 2014 at 1:04 PM, The Devils Jester <
thedevilsjester gmail com> wrote:

With just a cursory glance at the containers documentation and function
list, it seems to be exactly what I need, thank you.

On Thu, Nov 13, 2014 at 12:57 PM, Tristan Van Berkom <
tristan upstairslabs com> wrote:

On Thu, 2014-11-13 at 12:53 -0600, The Devils Jester wrote:
You say that GTK has a lot of containers, are there any that already
fit my needs (minimally, I am not looking for overkill).


I need a container that I can add an arbitrary number of widgets to as
children, and it will display these children.
I don't want any styling, or layout management of any kind, I want to
position/size the children as I see fit.
GtkFixed fits the bill pretty nicely except that it has a "minimum
size" based on the contents.


Before I reinvent the wheel (or sub class the wheel!), is there an
existing GTK container that can already do this?

GtkLayout does that, but then it does not request *any* space, and
child widgets will simply be clipped out of the visible area unless
the layout is allocated enough space.




On Thu, Nov 13, 2014 at 12:45 PM, Tristan Van Berkom
<tristan upstairslabs com> wrote:
        On Thu, 2014-11-13 at 12:42 -0600, The Devils Jester wrote:
        > I considered GtkContainer but my Google searches did not
        come up with
        > any recent examples of sub classing it and I am having a
        difficult
        > time understanding the mechanics behind sub classing a GTK
        object.
        > Does anyone have a bare bones hello world subclassed
        GtkContainer
        > sample that I could examine?

        GTK+ has a lot of containers, my suggestion would be to pick
        one
        that comes close to what you want (a box perhaps ?), and start
        by copying it and removing the bits that are not relevant.

        The simplest cases to start with might be bin widgets like
        GtkEventBox (but it does some extra stuff like creating
        an extra event window).

        Cheers,
            -Tristan

        >
        > On Thu, Nov 13, 2014 at 11:34 AM, Tristan Van Berkom
        > <tristan upstairslabs com> wrote:
        >         On Thu, 2014-11-13 at 11:23 -0600, The Devils Jester
        wrote:
        >         > In a nutshell I am (more or less) trying to
        simulate a
        >         vertical layout
        >         > manager using a GtkFixed layout manager. I have
        specific
        >         need to do this,
        >         > rather than just use the Gtk provided one.
        >
        >         If you need a kind of container that GTK+ does not
        provide,
        >         you really
        >         should just subclass GtkContainer and implement the
        size
        >         requesting
        >         and size allocation methods.
        >
        >         Trying to simulate it using a GtkFixed and setting
        size
        >         requests might
        >         seem tempting, but just wont get you what you want,
        if what
        >         you want
        >         is content driven size allocations (you will find
        yourself in
        >         a catch 22
        >         very quickly, where the size you previously forced
        on a child
        >         is
        >         reported when you ask for it's new size, hence you
        can never
        >         know what
        >         it's new requested size might be, because you
        already forced
        >         it
        >         explicitly).
        >
        >         Best,
        >             -Tristan
        >
        >         >
        >         > The problem occurs when I have to resize a widget
        in the
        >         GtkFixed
        >         > container.  The function I am using for this is
        >         > gtk_widget_set_size_request.  The widget resizes
        (in this
        >         case it stretches
        >         > to fit the "container size"), but then the window
        can never
        >         be resized to
        >         > smaller than the widget size.   I can make the
        window larger
        >         (which makes
        >         > the container larger, which makes the widget
        larger) but I
        >         can never make
        >         > the window smaller because the size request holds
        it to a
        >         minimum size.
        >         >
        >         > How can I resize the widget in a way that the
        window will
        >         ignore its size
        >         > when calculating the minimum window size?
        >         > _______________________________________________
        >         > gtk-app-devel-list mailing list
        >         > gtk-app-devel-list gnome org
        >         >
        https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
        >
        >
        >
        >











[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]