Lua Dialog refinements:
* Add Heading Widget * Swap OK/Cancel Buttons * Update table layout (spacing + alignment) * Some whitespace tweaks
This commit is contained in:
parent
441cc5b485
commit
35aa4f692a
|
@ -103,6 +103,26 @@ Message::to_gtk_mt (MessageType mt)
|
|||
* Lua Dialog Widgets
|
||||
*/
|
||||
|
||||
class LuaDialogLabel : public LuaDialogWidget
|
||||
{
|
||||
public:
|
||||
LuaDialogLabel (std::string const& title, Gtk::AlignmentEnum xalign)
|
||||
: LuaDialogWidget ("", "")
|
||||
, _lbl ("<b>" + title + "</b>", xalign, Gtk::ALIGN_CENTER, false)
|
||||
{
|
||||
_lbl.set_use_markup ();
|
||||
}
|
||||
|
||||
Gtk::Widget* widget ()
|
||||
{
|
||||
return &_lbl;
|
||||
}
|
||||
|
||||
void assign (luabridge::LuaRef* rv) const { }
|
||||
protected:
|
||||
Gtk::Label _lbl;
|
||||
};
|
||||
|
||||
class LuaDialogCheckbox : public LuaDialogWidget
|
||||
{
|
||||
public:
|
||||
|
@ -430,14 +450,29 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
|
|||
for (luabridge::Iterator i (lr); !i.isNil (); ++i) {
|
||||
if (!i.key ().isNumber ()) { continue; }
|
||||
if (!i.value ().isTable ()) { continue; }
|
||||
if (!i.value ()["key"].isString ()) { continue; }
|
||||
if (!i.value ()["title"].isString ()) { continue; }
|
||||
if (!i.value ()["type"].isString ()) { continue; }
|
||||
|
||||
std::string key = i.value ()["key"].cast<std::string> ();
|
||||
std::string title = i.value ()["title"].cast<std::string> ();
|
||||
std::string type = i.value ()["type"].cast<std::string> ();
|
||||
|
||||
if (type == "heading") {
|
||||
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;
|
||||
}
|
||||
}
|
||||
_widgets.push_back (new LuaDialogLabel (title, xalign));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!i.value ()["key"].isString ()) { continue; }
|
||||
std::string key = i.value ()["key"].cast<std::string> ();
|
||||
|
||||
if (type == "checkbox") {
|
||||
bool dflt = false;
|
||||
if (i.value ()["default"].isBoolean ()) {
|
||||
|
@ -514,22 +549,26 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
|
|||
}
|
||||
}
|
||||
|
||||
_ad.add_button (Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
|
||||
_ad.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||
_ad.add_button (Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
|
||||
|
||||
Gtk::Table* table = Gtk::manage (new Gtk::Table ());
|
||||
table->set_spacings (6);
|
||||
table->set_col_spacings (4);
|
||||
table->set_row_spacings (8);
|
||||
_ad.get_vbox ()->pack_start (*table);
|
||||
int row = 0;
|
||||
|
||||
for (DialogWidgets::const_iterator i = _widgets.begin (); i != _widgets.end (); ++i) {
|
||||
std::string const& label = (*i)->label ();
|
||||
if (!label.empty ()) {
|
||||
Gtk::Label* lbl = Gtk::manage (new Gtk::Label ("<b>" + label + ":</b>", Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
|
||||
lbl->set_use_markup ();
|
||||
Gtk::Label* lbl = Gtk::manage (new Gtk::Label (label + ":", Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
|
||||
table->attach (*lbl, 0, 1, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
|
||||
}
|
||||
table->attach (*((*i)->widget ()), 1, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
|
||||
} else if ((*i)->key ().empty ()) {
|
||||
table->attach (*((*i)->widget ()), 0, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
|
||||
} else {
|
||||
table->attach (*((*i)->widget ()), 1, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
|
||||
}
|
||||
++row;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
virtual Gtk::Widget* widget () = 0;
|
||||
virtual void assign (luabridge::LuaRef* rv) const = 0;
|
||||
std::string const& label () const { return _label; }
|
||||
std::string const& key () const { return _key; }
|
||||
|
||||
protected:
|
||||
std::string _key;
|
||||
|
|
Loading…
Reference in New Issue
Block a user