[Gtk-sharp-list] Gtk# 2.99.0 released!

Bertrand Lorentz bertrand.lorentz at gmail.com
Sun Nov 18 20:02:47 UTC 2012


On Sat, Nov 17, 2012 at 6:39 PM, Curtis Wensley
<curtis.wensley at gmail.com> wrote:
>>> The other thing I noticed, was that there is no longer an easy way to set
>>> a
>>> minimum size for a control unless it is subclassed and override
>>> OnGetPreferredWidth/Height.  I used to do this via the SizeRequested
>>> event.
>>
>> What do you mean by that ? Could you give some sample code ?
>
> What I mean is I have code like this (makes a control have a minimum size),
> which is shared code for all controls:
>
>         Control.SizeRequested += (o, args) => {
>                 var alloc = args.Requisition;
>                 alloc.Width = Math.Max (alloc.Width, MinimumSize.Width);
>                 alloc.Height = Math.Max (alloc.Height, MinimumSize.Height);
>                 args.Requisition = alloc;
>         };
>
> To do this with gtk# 3, I'd have to subclass each control:
>
>         class MyNotebook : Gtk.Notebook
>         {
>                 public Gdk.Size MinimumSize { get; set; }
>
>                 protected override void OnGetPreferredHeight (out int minimum_height, out
> int natural_height)
>                 {
>                         base.OnGetPreferredHeight (out minimum_height, out natural_height);
>                         minimum_height = MinimumSize.Height;
>                 }
>
>                 protected override void OnGetPreferredWidth (out int minimum_width, out
> int natural_width)
>                 {
>                         base.OnGetPreferredWidth (out minimum_width, out natural_width);
>                         minimum_width = MinimumSize.Width;
>                 }
>         }

Unless I'm missing something, I think you can already do what you want
with the SetSizeRequest method:

Control.SetSizeRequest (MinimumSize.Width, MinimumSize.Height);

See there for the docs for the corresponding C function:
http://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-size-request

--
Bertrand Lorentz


More information about the Gtk-sharp-list mailing list