aboutsummaryrefslogtreecommitdiff
path: root/src/InputDialog.cpp
blob: 16c4d01918aeb67174c43825f829f89cb834289f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "../include/InputDialog.hpp"
#include <gtkmm/label.h>
#include <gtkmm/grid.h>

namespace dchat
{
    InputDialog::InputDialog(const char *title, const std::vector<const char*> &texts, const char *acceptText, const char *cancelText)
    {
        set_title(title);

        Gtk::Box *box = get_content_area();
        //box->set_halign(Gtk::ALIGN_CENTER);
        //box->set_valign(Gtk::ALIGN_CENTER);
        Gtk::Grid *grid = Gtk::manage(new Gtk::Grid());
        grid->set_halign(Gtk::ALIGN_CENTER);
        grid->set_valign(Gtk::ALIGN_CENTER);
        box->pack_start(*grid, true, true);
        int i = 0;
        for(const char *text : texts)
        {
            Gtk::Label *label = Gtk::manage(new Gtk::Label(text));
            label->set_valign(Gtk::ALIGN_END);
            label->set_halign(Gtk::ALIGN_CENTER);
            grid->attach(*label, 0, i, 1, 1);

            Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());
            entry->set_valign(Gtk::ALIGN_CENTER);
            entry->set_halign(Gtk::ALIGN_CENTER);
            entry->set_hexpand(true);
            grid->attach(*entry, 0, i + 1, 2, 1);
            entries.push_back(entry);

            i += 2;
        }

        add_button(acceptText, Gtk::RESPONSE_ACCEPT);
        add_button(cancelText, Gtk::RESPONSE_CANCEL);
        show_all();

        set_size_request(300, 150);
    }
}