Re: GtkAllocation accessor
- From: Tadej Borovšak <tadeboro gmail com>
- To: Patrick Welche <prlw1 cam ac uk>
- Cc: gtk-list gnome org
- Subject: Re: GtkAllocation accessor
- Date: Tue, 1 Jun 2010 16:21:40 +0200
Hi.
> To use it, I need to
>
> GtkWidget *w = some_widget_new(some,properties);
> GtkAlloction a;
> gtk_widget_get_allocation(w, &a);
> make use of a->width and friends
> then free a?
You don't need to free a because it's allocated on a stack. Also, you
use a.width, not a->width when doing work.
> Wouldn't
>
> GtkAllocation * gtk_widget_get_allocation(GtkWidget *widget)
> {
> return widget->allocation;
> }
>
> be easier to use / less of a memory management headache as the
> memory already is allocated and controlled by the widget?
Considering my previous comment, there is no memory management
involved here, so complexity is not increased.
This is how a code snippet looks now:
GtkAllocation a;
gtk_widget_get_allocation (w, &a);
do_some_calc (a.width, a.height);
and this is how it would look using your method:
GtkAllocation *a;
a = gtk_widget_get_allocation (a);
do_some_calc (a->width, a->height);
I fail to see much difference here, but the first method is definitely
safer (see my next comment).
> Any thoughts on why it was done this way / thoughts on the addition of
> say a gtk_widget_get_allocation_pointer()?
I'm not the GTK+ developer, but I would say that main reason for doing
this is making sure that application developer cannot inadvertently
change widget's allocation. With current access method, you're always
working with copies.
--
Tadej Borovšak
tadeboro.blogspot.com
tadeboro gmail com
tadej borovsak gmail com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]