aboutsummaryrefslogtreecommitdiff
path: root/src/LoginWindow.cpp
blob: 5dfbed6d770fd2cf04040e4bef4a60512ba1e7a8 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "../include/LoginWindow.hpp"
#include <gtkmm/label.h>
#include <gtkmm/entry.h>
#include <gtkmm/alignment.h>
#include <gtkmm/button.h>
#include <cassert>

namespace dchat
{
    LoginWindow::LoginWindow() : 
        loginButton("Login")
    {
        loginHandler = [this]
        {
            if(loginHandlerUser)
                loginHandlerUser(usernameInput.get_text(), passwordInput.get_text());
        };

        Gtk::Label *username = Gtk::manage(new Gtk::Label());
        username->set_text("Username");
        username->set_halign(Gtk::ALIGN_START);
        attach(*username, 0, 0, 1, 1);

        usernameInput.set_size_request(200);
        usernameInput.signal_activate().connect(loginHandler);
        attach_next_to(usernameInput, *username, Gtk::POS_BOTTOM, 3, 1);

        Gtk::Alignment *usernamePasswordSpacer = Gtk::manage(new Gtk::Alignment());
        usernamePasswordSpacer->set_size_request(-1, 35);
        attach_next_to(*usernamePasswordSpacer, usernameInput, Gtk::POS_BOTTOM, 1, 1);

        Gtk::Label *password = Gtk::manage(new Gtk::Label());
        password->set_text("Password");
        password->set_halign(Gtk::ALIGN_START);
        attach_next_to(*password, *usernamePasswordSpacer, Gtk::POS_BOTTOM, 1, 1);

        passwordInput.set_visibility(false);
        passwordInput.set_size_request(200);
        passwordInput.signal_activate().connect(loginHandler);
        attach_next_to(passwordInput, *password, Gtk::POS_BOTTOM, 3, 1);

        Gtk::Alignment *loginButtonSpacerTop = Gtk::manage(new Gtk::Alignment());
        loginButtonSpacerTop->set_size_request(-1, 20);
        attach_next_to(*loginButtonSpacerTop, passwordInput, Gtk::POS_BOTTOM, 1, 1);

        Gtk::Alignment *loginButtonSpacer = Gtk::manage(new Gtk::Alignment());
        attach_next_to(*loginButtonSpacer, *loginButtonSpacerTop, Gtk::POS_BOTTOM, 2, 1);

        loginButton.set_halign(Gtk::ALIGN_END);
        loginButton.signal_clicked().connect(loginHandler);
        attach_next_to(loginButton, *loginButtonSpacer, Gtk::POS_RIGHT, 1, 1);

        set_halign(Gtk::ALIGN_CENTER);
        set_valign(Gtk::ALIGN_CENTER);
        get_style_context()->add_class("login-window");
    }

    void LoginWindow::setLoginHandler(LoginHandler loginHandler)
    {
        loginHandlerUser = loginHandler;
    }
}