diff options
Diffstat (limited to 'src/gui_gtk.cc')
| -rw-r--r-- | src/gui_gtk.cc | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/src/gui_gtk.cc b/src/gui_gtk.cc index 6afec5d..14c1f63 100644 --- a/src/gui_gtk.cc +++ b/src/gui_gtk.cc @@ -909,13 +909,14 @@ public: } void add_string(std::string const& id, std::string const& label, - std::string const& value) override { - values_.emplace_back(new StringValue(id, label, value)); + std::string const& value, + std::string const& description) override { + values_.emplace_back(new StringValue(id, label, description, value)); } void add_number(std::string const& id, std::string const& label, - uint64_t value) override { - values_.emplace_back(new NumberValue(id, label, value)); + uint64_t value, std::string const& description) override { + values_.emplace_back(new NumberValue(id, label, description, value)); } std::string get_string(std::string const& id) const override { @@ -975,10 +976,15 @@ public: GTK_RESPONSE_REJECT, nullptr); auto content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog_)); - auto spacing = 5; + auto grid = gtk_grid_new(); + gtk_grid_set_column_spacing(GTK_GRID(grid), 5); + gtk_grid_set_row_spacing(GTK_GRID(grid), 5); + gint row = 0; if (!text_.empty()) { auto label = gtk_label_new(text_.c_str()); - gtk_box_pack_start(GTK_BOX(content_area), label, true, true, spacing); + gtk_label_set_width_chars(GTK_LABEL(label), 35); + gtk_label_set_line_wrap(GTK_LABEL(label), true); + gtk_grid_attach(GTK_GRID(grid), label, 0, row++, 2, 1); } for (auto& value : values_) { auto label = gtk_label_new(value->label_.c_str()); @@ -999,16 +1005,24 @@ public: break; } } - auto box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, spacing); - gtk_box_pack_start(GTK_BOX(box), label, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), value->entry_, true, true, 0); - gtk_box_pack_start(GTK_BOX(content_area), box, false, false, spacing); + gtk_grid_attach(GTK_GRID(grid), label, 0, row, 1, 1); + gtk_grid_attach(GTK_GRID(grid), value->entry_, 1, row++, 1, 1); + if (!value->description_.empty()) { + auto desc = gtk_label_new(NULL); + gtk_label_set_markup(GTK_LABEL(desc), + ("<i>" + value->description_ + "</i>").c_str()); + gtk_widget_set_halign(GTK_WIDGET(desc), GTK_ALIGN_END); + gtk_label_set_line_wrap(GTK_LABEL(desc), true); + gtk_label_set_max_width_chars(GTK_LABEL(desc), 35); + gtk_grid_attach(GTK_GRID(grid), desc, 0, row++, 2, 1); + } } error_ = gtk_label_new(""); gtk_label_set_xalign(GTK_LABEL(error_), 0.0); - gtk_box_pack_start(GTK_BOX(content_area), error_, true, true, spacing); + gtk_grid_attach(GTK_GRID(grid), error_, 0, row++, 2, 1); + gtk_container_add(GTK_CONTAINER(content_area), grid); gtk_widget_show_all(dialog_); - add_extra_widgets(GTK_BOX(content_area), spacing); + row = add_extra_widgets(GTK_GRID(grid), row); gtk_widget_hide(error_); gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); gint result; @@ -1047,10 +1061,13 @@ protected: Type const type_; std::string const id_; std::string const label_; + std::string const description_; GtkWidget* entry_; - Value(Type type, std::string const& id, std::string const& label) - : type_(type), id_(id), label_(label), entry_(nullptr) { + Value(Type type, std::string const& id, std::string const& label, + std::string const& description) + : type_(type), id_(id), label_(label), description_(description), + entry_(nullptr) { } }; @@ -1058,8 +1075,8 @@ protected: std::string value_; StringValue(std::string const& id, std::string const& label, - std::string const& value) - : Value(STRING, id, label), value_(value) { + std::string const& description, std::string const& value) + : Value(STRING, id, label, description), value_(value) { } }; @@ -1067,8 +1084,8 @@ protected: uint64_t value_; NumberValue(std::string const& id, std::string const& label, - uint64_t value) - : Value(NUMBER, id, label), value_(value) { + std::string const& description, uint64_t value) + : Value(NUMBER, id, label, description), value_(value) { } }; @@ -1093,7 +1110,8 @@ protected: return false; } - virtual void add_extra_widgets(GtkBox*, gint) { + virtual gint add_extra_widgets(GtkGrid* UNUSED(grid), gint row) { + return row; } virtual void reset_extra_widgets() { @@ -1139,10 +1157,11 @@ public: } private: - void add_extra_widgets(GtkBox* content_area, gint spacing) override { + gint add_extra_widgets(GtkGrid* layout, gint row) override { assert(!spinner_); spinner_ = gtk_spinner_new(); - gtk_box_pack_start(content_area, spinner_, true, true, spacing); + gtk_grid_attach(layout, spinner_, 0, row++, 2, 1); + return row; } void reset_extra_widgets() override { |
