Re: gtkmm-list Digest, Vol 149, Issue 3



On Sat, Sep 10, 2016 at 1:00 PM, <gtkmm-list-request gnome org> wrote:

I need to add the following functions:

virtual Gtk::SizeRequestMode get_request_mode_vfunc() const;
virtual void get_preferred_width_vfunc(int& minimum_width, int&
natural_width) const;
virtual void get_preferred_height_for_width_vfunc(int width, int&
minimum_height, int& natural_height) const;
virtual void get_preferred_height_vfunc(int& minimum_height, int&
natural_height) const;
virtual void get_preferred_width_for_height_vfunc(int height, int&
minimum_width, int& natural_width) const;
virtual void on_size_allocate(Gtk::Allocation& allocation);
virtual void on_map();
virtual void on_unmap();
virtual void on_realize();
virtual void on_unrealize();


Do you really, though? It would seem easier to create your custom widget by composition and let the existing Gtk::Button implementation handle all of those, unless you absolutely need special behaviour.

I never understood the refrain 'prefer composition over inheritance' until I started trying to inherit from libraries like this and realised how much hassle it causes, which is often unnecessary unless you're fundamentally changing the base class behaviour.

In my case, I wasn't, because I was just adding functionality to existing widgets by wrapping - for which inheritance just caused my headaches - and a phenomenal amount of unnecessary space overhead for all those new vtables I never actually needed.

So now I just use composition to aggregate widgets together and add signals to them.

Just my experience, YMMV.



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