From 3efbb99ba9eedd4942a5ba34f8d8ce54fbdc07d6 Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Mon, 12 Apr 2021 21:48:54 -0700 Subject: [PATCH] Make MyImageMenuItem constructable from an RTImage --- rtgui/guiutils.cc | 19 +++++++++++++++++-- rtgui/guiutils.h | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index f415d770f..52ad2d6d4 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -1466,13 +1466,28 @@ TextOrIcon::TextOrIcon (const Glib::ustring &fname, const Glib::ustring &labelTx } 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()); this->label = Gtk::manage( new Gtk::Label(label)); box->set_orientation(Gtk::ORIENTATION_HORIZONTAL); - if (!imageFileName.empty()) { - image = Gtk::manage( new RTImage(imageFileName) ); + if (itemImage) { + image = itemImage; box->attach_next_to(*image, Gtk::POS_LEFT, 1, 1); } else { image = nullptr; diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index d90d45370..2077d505d 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -489,8 +489,11 @@ private: RTImage *image; Gtk::Label *label; + void construct(Glib::ustring label, RTImage* image); + public: MyImageMenuItem (Glib::ustring label, Glib::ustring imageFileName); + MyImageMenuItem (Glib::ustring label, RTImage* image); const RTImage *getImage () const; const Gtk::Label* getLabel () const; };