Γραφικά συστατικά

Οι εφαρμογές της gtkmm αποτελούνται από παράθυρα που περιέχουν γραφικά συστατικά, όπως κουμπιά και πλαίσια κειμένου. Σε μερικά άλλα συστήματα, τα γραφικά συστατικά λέγονται "στοιχεία ελέγχου". Για κάθε γραφικό συστατικό στα παράθυρα της εφαρμογής σας, υπάρχει ένα αντικείμενο C++ στον κώδικα της εφαρμογής σας. Έτσι χρειάζεστε απλά να καλέσετε μια μέθοδο της κλάσης του γραφικού συστατικού για να επηρεάσετε το ορατό γραφικό συστατικό.

Widgets are arranged inside container widgets such as frames and notebooks, in a hierarchy of widgets within widgets. Some of these container widgets, such as Gtk::Grid, are not visible - they exist only to arrange other widgets. Here is some example code that adds 2 Gtk::Button widgets to a Gtk::Box container widget:

m_box.pack_start(m_Button1);
m_box.pack_start(m_Button2);
and here is how to add the Gtk::Box, containing those buttons, to a Gtk::Frame, which has a visible frame and title:
m_frame.add(m_box);

Τα περισσότερα από τα κεφάλαια σε αυτό το βιβλίο πραγματεύονται ειδικά γραφικά συστατικά. Δείτε την ενότητα Γραφικά συστατικά περιέκτη για περισσότερες λεπτομέρειες για την προσθήκη γραφικών συστατικών σε γραφικά συστατικά περιέκτη.

Αν και μπορείτε να ορίσετε τη διάταξη και την εμφάνιση των παραθύρων και των γραφικών συστατικών με τον κώδικα C++, θα βρείτε πιο βολικό να σχεδιάσετε τις διεπαφές χρήστη σας με το Glade και να τις φορτώσετε στον χρόνο εκτέλεσης με Gtk::Builder. Δείτε το κεφάλαιο Glade and Gtk::Builder.

Although gtkmm widget instances have lifetimes and scopes just like those of other C++ classes, gtkmm has an optional time-saving feature that you will see in some of the examples. The Gtk::make_managed() allows you to create a new widget and state that it will become owned by the container into which you place it. This allows you to create the widget, add it to the container and not be concerned about deleting it, since that will occur when the parent container (which may itself be managed) is deleted. You can learn more about gtkmm memory management techniques in the Memory Management chapter.