Making it easier to change a font.



The thread http://mail.gnome.org/archives/gtkmm-list/2005-February/msg00068.html made me think. To change the font on a Gtk::Button we have to change the font of the label inside the button
 m_button.get_child().modify_font(font_desc);
every beginner will first try (i remember i did)
 m_button.modify_font(font_desc);
and why not? it's a perfectly logical thing to try if you don't know about the internals of a button, and i don't think you would have to know anything about the internals of a button when you are writing 'hello world'.

To illustrate the behavior i would like i attached some code at the end of this message. It overrides the modify_font method of a button and passes the modify_font call to all its children, i think it would be great if this
could be done in modify_font() of Gtk::Container because then:
- all descendants of Gtk::Container would have this behavior. (or would we have to change GtkContainer for that?) - it would not break existing code because AFAIK currently a call to modify_font of a container does nothing so nobody will have used it.
- it would flatten the steep learning curve of gtkmm i keep hearing about.

We could do cool stuff like packing some labels and entry's in a table and then call Gtk::Table::modify_font() to change all the labels and entry's at once.

Perhaps this can be done for more functions then just modify_font.

What do you think good idea or bad idea?

--
Marco Scholten.


/*---------------------------
 *         example
 */--------------------------

class EasyButton: public Gtk::Button
{
  public:
    void modify_font (const Pango::FontDescription& font_desc)
    {
      Pango::FontDescription f = font_desc;
      GtkCallback callback = (GtkCallback) (&gtk_widget_modify_font);
      forall_vfunc(true, callback, f.gobj());
    }
};

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);
  Gtk::Window window;
  Pango::FontDescription font_desc("Serif 20") ;
  EasyButton b1;
  b1.set_label("Test");
  b1.modify_font(font_desc);
  window.add(b1);
  window.show_all_children();
  Gtk::Main::run(window);
  return 0;
}


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/



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