Make MyImageMenuItem constructable from an RTImage

This commit is contained in:
Lawrence Lee
2021-04-12 21:48:54 -07:00
parent be7aecac40
commit 3efbb99ba9
2 changed files with 20 additions and 2 deletions

View File

@@ -1466,13 +1466,28 @@ TextOrIcon::TextOrIcon (const Glib::ustring &fname, const Glib::ustring &labelTx
} }
MyImageMenuItem::MyImageMenuItem(Glib::ustring label, Glib::ustring imageFileName) MyImageMenuItem::MyImageMenuItem(Glib::ustring label, Glib::ustring imageFileName)
{
RTImage* itemImage = nullptr;
if (!imageFileName.empty()) {
itemImage = Gtk::manage(new RTImage(imageFileName));
}
construct(label, itemImage);
}
MyImageMenuItem::MyImageMenuItem(Glib::ustring label, RTImage* itemImage) {
construct(label, itemImage);
}
void MyImageMenuItem::construct(Glib::ustring label, RTImage* itemImage)
{ {
box = Gtk::manage (new Gtk::Grid()); box = Gtk::manage (new Gtk::Grid());
this->label = Gtk::manage( new Gtk::Label(label)); this->label = Gtk::manage( new Gtk::Label(label));
box->set_orientation(Gtk::ORIENTATION_HORIZONTAL); box->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
if (!imageFileName.empty()) { if (itemImage) {
image = Gtk::manage( new RTImage(imageFileName) ); image = itemImage;
box->attach_next_to(*image, Gtk::POS_LEFT, 1, 1); box->attach_next_to(*image, Gtk::POS_LEFT, 1, 1);
} else { } else {
image = nullptr; image = nullptr;

View File

@@ -489,8 +489,11 @@ private:
RTImage *image; RTImage *image;
Gtk::Label *label; Gtk::Label *label;
void construct(Glib::ustring label, RTImage* image);
public: public:
MyImageMenuItem (Glib::ustring label, Glib::ustring imageFileName); MyImageMenuItem (Glib::ustring label, Glib::ustring imageFileName);
MyImageMenuItem (Glib::ustring label, RTImage* image);
const RTImage *getImage () const; const RTImage *getImage () const;
const Gtk::Label* getLabel () const; const Gtk::Label* getLabel () const;
}; };