Backwards compatible LuaDialog layout (+new colspan option)

This commit is contained in:
Robin Gareus 2017-08-19 03:12:28 +02:00
parent d3b341d5c2
commit 91a2cf7901
3 changed files with 127 additions and 63 deletions

View file

@ -125,11 +125,9 @@ class LuaDialogLabel : public LuaDialogWidget
{ {
public: public:
LuaDialogLabel (std::string const& title, Gtk::AlignmentEnum xalign) LuaDialogLabel (std::string const& title, Gtk::AlignmentEnum xalign)
: LuaDialogWidget ("", "") : LuaDialogWidget ("", "", 0, 2)
, _lbl ("<b>" + title + "</b>", xalign, Gtk::ALIGN_CENTER, false) , _lbl (title, xalign, Gtk::ALIGN_CENTER, false)
{ { }
_lbl.set_use_markup ();
}
Gtk::Widget* widget () Gtk::Widget* widget ()
{ {
@ -141,13 +139,43 @@ protected:
Gtk::Label _lbl; Gtk::Label _lbl;
}; };
class LuaDialogHeading : public LuaDialogLabel
{
public:
LuaDialogHeading (std::string const& title, Gtk::AlignmentEnum xalign)
: LuaDialogLabel ("<b>" + title + "</b>", xalign)
{
_lbl.set_use_markup ();
}
};
class LuaHSeparator : public LuaDialogWidget
{
public:
LuaHSeparator ()
: LuaDialogWidget ("", "", 0, 2)
{}
Gtk::Widget* widget ()
{
return &_sep;
}
void assign (luabridge::LuaRef* rv) const { }
protected:
Gtk::HSeparator _sep;
};
class LuaDialogCheckbox : public LuaDialogWidget class LuaDialogCheckbox : public LuaDialogWidget
{ {
public: public:
LuaDialogCheckbox (std::string const& key, std::string const& title, bool on) LuaDialogCheckbox (std::string const& key, std::string const& title, bool on)
: LuaDialogWidget (key, "") : LuaDialogWidget (key, "", 1, 1)
, _cb (title)
{ {
if (!title.empty ()) {
_cb.add_label (title, false, 0);
}
_cb.set_active (on); _cb.set_active (on);
} }
@ -514,13 +542,13 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
std::string title = i.value ()["title"].cast<std::string> (); std::string title = i.value ()["title"].cast<std::string> ();
std::string type = i.value ()["type"].cast<std::string> (); std::string type = i.value ()["type"].cast<std::string> ();
std::string key; std::string key;
if (i.value ()["key"].isString ()) { if (i.value ()["key"].isString ()) {
key = i.value ()["key"].cast<std::string> (); key = i.value ()["key"].cast<std::string> ();
} }
LuaDialogWidget *widge; LuaDialogWidget* w = NULL;
if (type == "heading") { if (type == "heading") {
Gtk::AlignmentEnum xalign = Gtk::ALIGN_CENTER; Gtk::AlignmentEnum xalign = Gtk::ALIGN_CENTER;
@ -532,19 +560,37 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
xalign = Gtk::ALIGN_RIGHT; xalign = Gtk::ALIGN_RIGHT;
} }
} }
widge = new LuaDialogLabel (title, xalign); w = new LuaDialogHeading (title, xalign);
} else if (type == "checkbox") { } else if (type == "label") {
Gtk::AlignmentEnum xalign = Gtk::ALIGN_CENTER;
if (i.value ()["align"].isString ()) {
std::string align = i.value ()["align"].cast <std::string> ();
if (align == "left") {
xalign = Gtk::ALIGN_LEFT;
} else if (align == "right") {
xalign = Gtk::ALIGN_RIGHT;
}
}
w = new LuaDialogLabel (title, xalign);
} else if (type == "hseparator") {
w = new LuaHSeparator ();
}
/* the following widgets do require a key */
else if (key.empty ()) {
continue;
}
else if (type == "checkbox") {
bool dflt = false; bool dflt = false;
if (i.value ()["default"].isBoolean ()) { if (i.value ()["default"].isBoolean ()) {
dflt = i.value ()["default"].cast<bool> (); dflt = i.value ()["default"].cast<bool> ();
} }
widge = new LuaDialogCheckbox (key, title, dflt); w = new LuaDialogCheckbox (key, title, dflt);
} else if (type == "entry") { } else if (type == "entry") {
std::string dflt; std::string dflt;
if (i.value ()["default"].isString ()) { if (i.value ()["default"].isString ()) {
dflt = i.value ()["default"].cast<std::string> (); dflt = i.value ()["default"].cast<std::string> ();
} }
widge = new LuaDialogEntry (key, title, dflt); w = new LuaDialogEntry (key, title, dflt);
} else if (type == "radio") { } else if (type == "radio") {
std::string dflt; std::string dflt;
if (!i.value ()["values"].isTable ()) { if (!i.value ()["values"].isTable ()) {
@ -553,13 +599,13 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
if (i.value ()["default"].isString ()) { if (i.value ()["default"].isString ()) {
dflt = i.value ()["default"].cast<std::string> (); dflt = i.value ()["default"].cast<std::string> ();
} }
widge = new LuaDialogRadio (key, title, i.value ()["values"], dflt); w = new LuaDialogRadio (key, title, i.value ()["values"], dflt);
} else if (type == "fader") { } else if (type == "fader") {
double dflt = 0; double dflt = 0;
if (i.value ()["default"].isNumber ()) { if (i.value ()["default"].isNumber ()) {
dflt = i.value ()["default"].cast<double> (); dflt = i.value ()["default"].cast<double> ();
} }
widge = new LuaDialogFader (key, title, dflt); w = new LuaDialogFader (key, title, dflt);
} else if (type == "slider") { } else if (type == "slider") {
double lower, upper, dflt; double lower, upper, dflt;
int digits = 0; int digits = 0;
@ -575,7 +621,7 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
if (i.value ()["digits"].isNumber ()) { if (i.value ()["digits"].isNumber ()) {
digits = i.value ()["digits"].cast<int> (); digits = i.value ()["digits"].cast<int> ();
} }
widge = new LuaDialogSlider (key, title, lower, upper, dflt, digits, i.value ()["scalepoints"]); w = new LuaDialogSlider (key, title, lower, upper, dflt, digits, i.value ()["scalepoints"]);
} else if (type == "number") { } else if (type == "number") {
double lower, upper, dflt, step; double lower, upper, dflt, step;
int digits = 0; int digits = 0;
@ -596,7 +642,7 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
if (i.value ()["digits"].isNumber ()) { if (i.value ()["digits"].isNumber ()) {
digits = i.value ()["digits"].cast<int> (); digits = i.value ()["digits"].cast<int> ();
} }
widge = new LuaDialogSpinBox (key, title, lower, upper, dflt, step, digits); w = new LuaDialogSpinBox (key, title, lower, upper, dflt, step, digits);
} else if (type == "dropdown") { } else if (type == "dropdown") {
std::string dflt; std::string dflt;
if (!i.value ()["values"].isTable ()) { if (!i.value ()["values"].isTable ()) {
@ -605,27 +651,29 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
if (i.value ()["default"].isString ()) { if (i.value ()["default"].isString ()) {
dflt = i.value ()["default"].cast<std::string> (); dflt = i.value ()["default"].cast<std::string> ();
} }
widge = new LuaDialogDropDown (key, title, i.value ()["values"], dflt); w = new LuaDialogDropDown (key, title, i.value ()["values"], dflt);
} else if (type == "file") { } else if (type == "file") {
std::string path; std::string path;
if (i.value ()["path"].isString ()) { if (i.value ()["path"].isString ()) {
path = i.value ()["path"].cast<std::string> (); path = i.value ()["path"].cast<std::string> ();
} }
widge = new LuaFileChooser (key, title, Gtk::FILE_CHOOSER_ACTION_OPEN, path); w = new LuaFileChooser (key, title, Gtk::FILE_CHOOSER_ACTION_OPEN, path);
} else if (type == "folder") { } else if (type == "folder") {
std::string path; std::string path;
if (i.value ()["path"].isString ()) { if (i.value ()["path"].isString ()) {
path = i.value ()["path"].cast<std::string> (); path = i.value ()["path"].cast<std::string> ();
} }
widge = new LuaFileChooser (key, title, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, path); w = new LuaFileChooser (key, title, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, path);
} }
if (widge) { if (w) {
_widgets.push_back(widge);
if (i.value ()["col"].isNumber ()) { if (i.value ()["col"].isNumber ()) {
widge->set_col (i.value ()["col"].cast<int> ()); w->set_col (i.value ()["col"].cast<int> ());
} }
if (i.value ()["colspan"].isNumber ()) {
w->set_span (i.value ()["colspan"].cast<int> ());
}
_widgets.push_back(w);
} }
} }
@ -636,26 +684,35 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
table->set_col_spacings (20); table->set_col_spacings (20);
table->set_row_spacings (8); table->set_row_spacings (8);
_ad.get_vbox ()->pack_start (*table); _ad.get_vbox ()->pack_start (*table);
int row = 0; int row = 0;
int last_end = -1;
for (DialogWidgets::const_iterator i = _widgets.begin (); i != _widgets.end (); ++i) { for (DialogWidgets::const_iterator i = _widgets.begin (); i != _widgets.end (); ++i) {
int col = (*i)->col(); int col = (*i)->col();
if (col <= 0) { int cend = col + (*i)->span();
if (col < last_end) {
++row; ++row;
} }
last_end = cend;
std::string const& label = (*i)->label (); std::string const& label = (*i)->label ();
if (!label.empty ()) { if (!label.empty ()) {
Gtk::HBox* hb = Gtk::manage (new Gtk::HBox()); /* items with implicit label (title) */
Gtk::Label* lbl = Gtk::manage (new Gtk::Label (label + ":", Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false)); Gtk::Label* lbl = Gtk::manage (new Gtk::Label (label + ":", Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
hb->set_spacing(4); if (cend - col > 1) {
hb->pack_start (*lbl, true, false); table->attach (*lbl, col, col + 1, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
hb->pack_start (*(*i)->widget (), true, false); table->attach (*((*i)->widget ()), col + 1, cend, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
table->attach (*hb, col+0, col+1, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); } else {
} else if ((*i)->key ().empty ()) { Gtk::HBox* hb = Gtk::manage (new Gtk::HBox());
table->attach (*((*i)->widget ()), col+0, col+1, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); hb->set_spacing(4);
hb->pack_start (*lbl, true, false);
hb->pack_start (*(*i)->widget (), true, false);
table->attach (*hb, col, cend, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
}
} else { } else {
table->attach (*((*i)->widget ()), col+0, col+1, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); table->attach (*((*i)->widget ()), col, cend, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
} }
} }
} }

View file

@ -53,24 +53,31 @@ private:
class LuaDialogWidget { class LuaDialogWidget {
public: public:
LuaDialogWidget (std::string const& key, std::string const& label, int col = 0) LuaDialogWidget (std::string const& key, std::string const& label, int col = 0, int colspan = -1)
: _key (key), _label (label), _col (col) : _key (key), _label (label), _col (col), _colspan (colspan)
{} {
if (_colspan < 0) {
_colspan = label.empty () ? 1 : 2;
}
}
virtual ~LuaDialogWidget () {} virtual ~LuaDialogWidget () {}
virtual Gtk::Widget* widget () = 0; virtual Gtk::Widget* widget () = 0;
virtual void assign (luabridge::LuaRef* rv) const = 0; virtual void assign (luabridge::LuaRef* rv) const = 0;
std::string const& label () const { return _label; } std::string const& label () const { return _label; }
std::string const& key () const { return _key; } std::string const& key () const { return _key; }
int const& col () const { return _col; } int col () const { return _col; }
int span () const { return _colspan; }
void set_col (int col) { _col = col; } void set_col (int col) { _col = col; }
void set_span (int span) { _colspan = span; }
protected: protected:
std::string _key; std::string _key;
std::string _label; std::string _label;
int _col; int _col;
int _colspan;
}; };

View file

@ -28,71 +28,71 @@ function factory () return function ()
--prompt the user for the tracks they'd like to instantiate --prompt the user for the tracks they'd like to instantiate
local dialog_options = { local dialog_options = {
{ type = "heading", title = "Select the tracks you'd like\n to add to your session: " }, { type = "heading", title = "Select the tracks you'd like\nto add to your session: ", col=0, align = "left", colspan = 1},
{ type = "heading", title = "Name", col=1 }, { type = "heading", title = "Name", col=1, colspan = 1 },
{ type = "heading", title = "Stereo?", col=2 }, { type = "heading", title = "Stereo?", col=2, colspan = 1 },
{ type = "checkbox", key = "check-ldvox", default = false, title = "Lead Vocal" }, { type = "checkbox", key = "check-ldvox", default = false, title = "Lead Vocal", col=0 },
{ type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 }, { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 },
{ type = "checkbox", key = "stereo-ldvox", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-ldvox", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-bass", default = false, title = "Bass" }, { type = "checkbox", key = "check-bass", default = false, title = "Bass", col=0 },
{ type = "entry", key = "name-bass", default = "Bass", title = "", col=1 }, { type = "entry", key = "name-bass", default = "Bass", title = "", col=1 },
{ type = "checkbox", key = "stereo-bass", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-bass", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-piano", default = false, title = "Piano" }, { type = "checkbox", key = "check-piano", default = false, title = "Piano", col=0 },
{ type = "entry", key = "name-piano", default = "Piano", title = "", col=1 }, { type = "entry", key = "name-piano", default = "Piano", title = "", col=1 },
{ type = "checkbox", key = "stereo-piano", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-piano", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-electric-piano", default = false, title = "Electric Piano" }, { type = "checkbox", key = "check-electric-piano", default = false, title = "Electric Piano", col=0 },
{ type = "entry", key = "name-electric-piano", default = "E Piano", title = "", col=1 }, { type = "entry", key = "name-electric-piano", default = "E Piano", title = "", col=1 },
{ type = "checkbox", key = "stereo-electric-piano", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-electric-piano", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-organ", default = false, title = "Organ" }, { type = "checkbox", key = "check-organ", default = false, title = "Organ", col=0 },
{ type = "entry", key = "name-organ", default = "Organ", title = "", col=1 }, { type = "entry", key = "name-organ", default = "Organ", title = "", col=1 },
{ type = "checkbox", key = "stereo-organ", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-organ", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-electric-guitar", default = false, title = "Electric Guitar" }, { type = "checkbox", key = "check-electric-guitar", default = false, title = "Electric Guitar", col=0 },
{ type = "entry", key = "name-electric-guitar", default = "E Guitar", title = "", col=1 }, { type = "entry", key = "name-electric-guitar", default = "E Guitar", title = "", col=1 },
{ type = "checkbox", key = "stereo-electric-guitar", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-electric-guitar", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-solo-guitar", default = false, title = "Lead Guitar" }, { type = "checkbox", key = "check-solo-guitar", default = false, title = "Lead Guitar", col=0 },
{ type = "entry", key = "name-solo-guitar", default = "Ld Gtr", title = "", col=1 }, { type = "entry", key = "name-solo-guitar", default = "Ld Gtr", title = "", col=1 },
{ type = "checkbox", key = "stereo-solo-guitar", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-solo-guitar", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-accoustic-guitar", default = false, title = "Acoustic Guitar" }, { type = "checkbox", key = "check-accoustic-guitar", default = false, title = "Acoustic Guitar", col=0 },
{ type = "entry", key = "name-accoustic-guitar", default = "Ac Gtr", title = "", col=1 }, { type = "entry", key = "name-accoustic-guitar", default = "Ac Gtr", title = "", col=1 },
{ type = "checkbox", key = "stereo-accoustic-guitar", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-accoustic-guitar", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-basic-kit", default = false, title = "Basic Drum Mics" }, { type = "checkbox", key = "check-basic-kit", default = false, title = "Basic Drum Mics", col=0 },
{ type = "heading", title = "(Kick + Snare)", col=1 }, { type = "label", title = "(Kick + Snare)", col=1, colspan = 1, align = "left"},
-- { type = "checkbox", key = "stereo-overhead-mono", default = false, title = "", col=2 }, -- { type = "checkbox", key = "stereo-overhead-mono", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-full-kit", default = false, title = "Full Drum Mics" }, { type = "checkbox", key = "check-full-kit", default = false, title = "Full Drum Mics", col=0 },
{ type = "heading", title = "(Kick, Snare, HiHat, 3 Toms)", col=1 }, { type = "label", title = "(Kick, Snare, HiHat, 3 Toms)", col=1, colspan = 1, align = "left"},
-- { type = "checkbox", key = "stereo-overhead-mono", default = false, title = "", col=2 }, -- { type = "checkbox", key = "stereo-overhead-mono", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-overkill-kit", default = false, title = "Overkill Drum Mics" }, { type = "checkbox", key = "check-overkill-kit", default = false, title = "Overkill Drum Mics", col=0 },
{ type = "heading", title = "(Kick (2x), Snare(2x), HiHat, 3 Toms)", col=1 }, { type = "label", title = "(Kick (2x), Snare(2x), HiHat, 3 Toms)", col=1, colspan = 1, align = "left"},
-- { type = "checkbox", key = "stereo-overhead-mono", default = false, title = "", col=2 }, -- { type = "checkbox", key = "stereo-overhead-mono", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-overhead", default = false, title = "Drum Overheads" }, { type = "checkbox", key = "check-overhead", default = false, title = "Drum Overheads", col=0 },
-- { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 }, -- { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 },
{ type = "checkbox", key = "stereo-overhead", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-overhead", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-room", default = false, title = "Drum Room" }, { type = "checkbox", key = "check-room", default = false, title = "Drum Room", col=0 },
-- { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 }, -- { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 },
{ type = "checkbox", key = "stereo-room", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-room", default = false, title = "", col=2 },
{ type = "checkbox", key = "check-bgvox", default = false, title = "Background Vocals (3x)" }, { type = "checkbox", key = "check-bgvox", default = false, title = "Background Vocals (3x)", col=0 },
-- { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 }, -- { type = "entry", key = "name-ldvox", default = "Lead Vocal", title = "", col=1 },
{ type = "checkbox", key = "stereo-bgvox", default = false, title = "", col=2 }, { type = "checkbox", key = "stereo-bgvox", default = false, title = "", col=2 },
{ type = "heading", title = "-------------------" }, { type = "hseparator", title="", col=0, colspan = 3},
{ type = "checkbox", key = "group", default = false, title = "Group Track(s)?" }, { type = "checkbox", key = "group", default = false, title = "Group Track(s)?", col=0 },
{ type = "checkbox", key = "gates", default = false, title = "Add Gate(s)?" }, { type = "checkbox", key = "gates", default = false, title = "Add Gate(s)?", col=0 },
{ type = "checkbox", key = "char", default = false, title = "Add Character Plugin(s)?" }, { type = "checkbox", key = "char", default = false, title = "Add Character Plugin(s)?", col=0 },
} }
local dlg = LuaDialog.Dialog ("Template Setup", dialog_options) local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)