another wrappers for GTK widgets
This commit is contained in:
parent
88d1126822
commit
ff532f5ed9
@ -49,7 +49,7 @@ add_executable(autocat_gnome main.cpp
|
|||||||
gtkpp/Application.cpp
|
gtkpp/Application.cpp
|
||||||
gtkpp/Application.h
|
gtkpp/Application.h
|
||||||
gtkpp/Window.cpp
|
gtkpp/Window.cpp
|
||||||
gtkpp/Window.h gtkpp/Box.cpp gtkpp/Box.h gtkpp/Widget.cpp gtkpp/Widget.h gtkpp/Entry.cpp gtkpp/Entry.h)
|
gtkpp/Window.h gtkpp/Box.cpp gtkpp/Box.h gtkpp/Widget.cpp gtkpp/Widget.h gtkpp/Entry.cpp gtkpp/Entry.h gtkpp/Button.cpp gtkpp/Button.h gtkpp/Spinner.cpp gtkpp/Spinner.h gtkpp/HeaderBar.cpp gtkpp/HeaderBar.h)
|
||||||
|
|
||||||
target_link_libraries(autocat_gnome ${GTKMM_LIBRARIES}
|
target_link_libraries(autocat_gnome ${GTKMM_LIBRARIES}
|
||||||
${GLIBMM_LIBRARIES}
|
${GLIBMM_LIBRARIES}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ namespace gtkpp {
|
|||||||
|
|
||||||
Application::Application(const std::string &id) {
|
Application::Application(const std::string &id) {
|
||||||
_app = adw_application_new(id.c_str(), G_APPLICATION_FLAGS_NONE);
|
_app = adw_application_new(id.c_str(), G_APPLICATION_FLAGS_NONE);
|
||||||
|
g_signal_connect(_app, "activate", G_CALLBACK(activateCallback), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::run(int argc, char **argv) {
|
int Application::run(int argc, char **argv) {
|
||||||
@ -21,7 +22,7 @@ namespace gtkpp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Application::onActivate(const std::function<void()>& callback) {
|
void Application::onActivate(const std::function<void()>& callback) {
|
||||||
g_signal_connect(_app, "activate", G_CALLBACK(activateCallback), this);
|
|
||||||
_signalActivate.connect(callback);
|
_signalActivate.connect(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
|
|
||||||
gtkpp::Box::Box(GtkOrientation orientation, int spacing) {
|
gtkpp::Box::Box(GtkOrientation orientation, int spacing) : Widget() {
|
||||||
_widget = gtk_box_new(orientation, spacing);
|
_widget = gtk_box_new(orientation, spacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
gtkpp/Button.cpp
Normal file
27
gtkpp/Button.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 11.05.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Button.h"
|
||||||
|
|
||||||
|
namespace gtkpp {
|
||||||
|
|
||||||
|
void clickedCallback(GtkButton*, void* data) {
|
||||||
|
auto button = reinterpret_cast<Button*>(data);
|
||||||
|
button->_signalClicked.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
Button::Button() : Widget() {
|
||||||
|
_widget = gtk_button_new();
|
||||||
|
g_signal_connect(_widget, "clicked", G_CALLBACK(clickedCallback), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::setTitle(const std::string &title) {
|
||||||
|
gtk_button_set_label(GTK_BUTTON(_widget), title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::onClick(const std::function<void()> &callback) {
|
||||||
|
_signalClicked.connect(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
29
gtkpp/Button.h
Normal file
29
gtkpp/Button.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 11.05.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef AUTOCAT_GNOME_BUTTON_H
|
||||||
|
#define AUTOCAT_GNOME_BUTTON_H
|
||||||
|
|
||||||
|
#include "Widget.h"
|
||||||
|
#include <string>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
|
namespace gtkpp {
|
||||||
|
|
||||||
|
class Button: public Widget {
|
||||||
|
private:
|
||||||
|
sigc::signal<void()> _signalClicked;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend void clickedCallback(GtkButton*, void* data);
|
||||||
|
|
||||||
|
public:
|
||||||
|
Button();
|
||||||
|
void setTitle(const std::string& title);
|
||||||
|
void onClick(const std::function<void()>& callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //AUTOCAT_GNOME_BUTTON_H
|
||||||
@ -4,18 +4,32 @@
|
|||||||
|
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
|
|
||||||
gtkpp::Entry::Entry() {
|
namespace gtkpp {
|
||||||
_widget = gtk_entry_new();
|
|
||||||
}
|
|
||||||
|
|
||||||
void gtkpp::Entry::setPlaceholder(const std::string &placeholder) {
|
void changedCallback(GtkEntry* widget, void* data) {
|
||||||
gtk_entry_set_placeholder_text(GTK_ENTRY(_widget), placeholder.c_str());
|
auto entry = reinterpret_cast<Entry*>(data);
|
||||||
}
|
entry->_signalChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
void gtkpp::Entry::setPurpose(GtkInputPurpose purpose) {
|
Entry::Entry() : Widget() {
|
||||||
gtk_entry_set_input_purpose(GTK_ENTRY(_widget), purpose);
|
_widget = gtk_entry_new();
|
||||||
}
|
g_signal_connect(_widget, "changed", G_CALLBACK(changedCallback), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entry::setPlaceholder(const std::string &placeholder) {
|
||||||
|
gtk_entry_set_placeholder_text(GTK_ENTRY(_widget), placeholder.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entry::setPurpose(GtkInputPurpose purpose) {
|
||||||
|
gtk_entry_set_input_purpose(GTK_ENTRY(_widget), purpose);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entry::setVisibility(bool visibility) {
|
||||||
|
gtk_entry_set_visibility(GTK_ENTRY(_widget), visibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entry::onChanged(const std::function<void()>& callback) {
|
||||||
|
_signalChanged.connect(callback);
|
||||||
|
}
|
||||||
|
|
||||||
void gtkpp::Entry::setVisibility(bool visibility) {
|
|
||||||
gtk_entry_set_visibility(GTK_ENTRY(_widget), visibility);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,17 +7,23 @@
|
|||||||
|
|
||||||
#include "Widget.h"
|
#include "Widget.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
namespace gtkpp {
|
namespace gtkpp {
|
||||||
|
|
||||||
class Entry: public Widget {
|
class Entry: public Widget {
|
||||||
private:
|
private:
|
||||||
|
sigc::signal<void()> _signalChanged;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend void changedCallback(GtkEntry* widget, void* data);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Entry();
|
Entry();
|
||||||
void setPlaceholder(const std::string& placeholder);
|
void setPlaceholder(const std::string& placeholder);
|
||||||
void setPurpose(GtkInputPurpose purpose);
|
void setPurpose(GtkInputPurpose purpose);
|
||||||
void setVisibility(bool visibility);
|
void setVisibility(bool visibility);
|
||||||
|
void onChanged(const std::function<void()>& callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
gtkpp/HeaderBar.cpp
Normal file
21
gtkpp/HeaderBar.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 11.05.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "HeaderBar.h"
|
||||||
|
#include <adwaita.h>
|
||||||
|
|
||||||
|
namespace gtkpp {
|
||||||
|
|
||||||
|
HeaderBar::HeaderBar() : Widget() {
|
||||||
|
_widget = adw_header_bar_new();
|
||||||
|
}
|
||||||
|
|
||||||
|
HeaderBar::HeaderBar(const std::string &title): HeaderBar() {
|
||||||
|
setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderBar::setTitle(const std::string& title) {
|
||||||
|
adw_header_bar_set_title_widget(ADW_HEADER_BAR(_widget), gtk_label_new(title.c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
22
gtkpp/HeaderBar.h
Normal file
22
gtkpp/HeaderBar.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 11.05.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef AUTOCAT_GNOME_HEADERBAR_H
|
||||||
|
#define AUTOCAT_GNOME_HEADERBAR_H
|
||||||
|
|
||||||
|
#include "Widget.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace gtkpp {
|
||||||
|
|
||||||
|
class HeaderBar: public Widget {
|
||||||
|
public:
|
||||||
|
HeaderBar();
|
||||||
|
explicit HeaderBar(const std::string& title);
|
||||||
|
void setTitle(const std::string& title);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //AUTOCAT_GNOME_HEADERBAR_H
|
||||||
13
gtkpp/Spinner.cpp
Normal file
13
gtkpp/Spinner.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 11.05.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Spinner.h"
|
||||||
|
|
||||||
|
namespace gtkpp {
|
||||||
|
|
||||||
|
Spinner::Spinner() : Widget() {
|
||||||
|
_widget = gtk_spinner_new();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
gtkpp/Spinner.h
Normal file
19
gtkpp/Spinner.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 11.05.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef AUTOCAT_GNOME_SPINNER_H
|
||||||
|
#define AUTOCAT_GNOME_SPINNER_H
|
||||||
|
|
||||||
|
#include "Widget.h"
|
||||||
|
|
||||||
|
namespace gtkpp {
|
||||||
|
|
||||||
|
class Spinner: public Widget {
|
||||||
|
public:
|
||||||
|
Spinner();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //AUTOCAT_GNOME_SPINNER_H
|
||||||
@ -22,3 +22,17 @@ void gtkpp::Widget::setVAlign(GtkAlign align) {
|
|||||||
void gtkpp::Widget::setVExpand(bool expand) {
|
void gtkpp::Widget::setVExpand(bool expand) {
|
||||||
gtk_widget_set_vexpand(_widget, expand);
|
gtk_widget_set_vexpand(_widget, expand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gtkpp::Widget::setHorizontalMargins(int margin) {
|
||||||
|
gtk_widget_set_margin_start(_widget, margin);
|
||||||
|
gtk_widget_set_margin_end(_widget, margin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gtkpp::Widget::setVerticalMargins(int margin) {
|
||||||
|
gtk_widget_set_margin_top(_widget, margin);
|
||||||
|
gtk_widget_set_margin_bottom(_widget, margin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gtkpp::Widget::setEnabled(bool enabled) {
|
||||||
|
gtk_widget_set_sensitive(_widget, enabled);
|
||||||
|
}
|
||||||
|
|||||||
@ -16,8 +16,11 @@ namespace gtkpp {
|
|||||||
public:
|
public:
|
||||||
[[nodiscard]] GtkWidget* gobj() const;
|
[[nodiscard]] GtkWidget* gobj() const;
|
||||||
void setMargins(int margin);
|
void setMargins(int margin);
|
||||||
|
void setVerticalMargins(int margin);
|
||||||
|
void setHorizontalMargins(int margin);
|
||||||
void setVAlign(GtkAlign align);
|
void setVAlign(GtkAlign align);
|
||||||
void setVExpand(bool expand);
|
void setVExpand(bool expand);
|
||||||
|
void setEnabled(bool enabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,70 +7,44 @@
|
|||||||
#include "../services/Api.h"
|
#include "../services/Api.h"
|
||||||
#include "../coro/GLibMainContextExecutor.h"
|
#include "../coro/GLibMainContextExecutor.h"
|
||||||
|
|
||||||
|
#include "../gtkpp/HeaderBar.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <folly/experimental/coro/Task.h>
|
#include <folly/experimental/coro/Task.h>
|
||||||
#include <folly/executors/IOThreadPoolExecutor.h>
|
#include <folly/executors/IOThreadPoolExecutor.h>
|
||||||
|
|
||||||
LoginWindow::LoginWindow(): _rootBox(GTK_ORIENTATION_VERTICAL, 0),
|
LoginWindow::LoginWindow() {
|
||||||
_contentBox(GTK_ORIENTATION_VERTICAL, 8) {
|
|
||||||
|
|
||||||
setDefaultSize(640, 480);
|
setDefaultSize(640, 480);
|
||||||
|
|
||||||
auto header = adw_header_bar_new();
|
|
||||||
adw_header_bar_set_title_widget(ADW_HEADER_BAR(header), gtk_label_new("Login"));
|
|
||||||
|
|
||||||
auto loginButton = gtk_button_new();
|
|
||||||
gtk_button_set_label(GTK_BUTTON(loginButton), "Log in");
|
|
||||||
gtk_widget_set_margin_top(loginButton, 8);
|
|
||||||
gtk_widget_set_margin_bottom(loginButton, 8);
|
|
||||||
gtk_widget_set_sensitive(loginButton, false);
|
|
||||||
|
|
||||||
auto spinner = gtk_spinner_new();
|
|
||||||
|
|
||||||
_loginEntry.setPlaceholder("Email");
|
_loginEntry.setPlaceholder("Email");
|
||||||
_loginEntry.setPurpose(GTK_INPUT_PURPOSE_EMAIL);
|
_loginEntry.setPurpose(GTK_INPUT_PURPOSE_EMAIL);
|
||||||
|
_loginEntry.onChanged([this] { validateFields(); });
|
||||||
|
|
||||||
_passwordEntry.setPlaceholder("Password");
|
_passwordEntry.setPlaceholder("Password");
|
||||||
_passwordEntry.setPurpose(GTK_INPUT_PURPOSE_PASSWORD);
|
_passwordEntry.setPurpose(GTK_INPUT_PURPOSE_PASSWORD);
|
||||||
_passwordEntry.setVisibility(false);
|
_passwordEntry.setVisibility(false);
|
||||||
|
_passwordEntry.onChanged([this] { validateFields(); });
|
||||||
|
|
||||||
_contentBox.append(_loginEntry);
|
_loginButton.setTitle("Log in");
|
||||||
_contentBox.append(_passwordEntry);
|
_loginButton.setVerticalMargins(8);
|
||||||
_contentBox.append(loginButton);
|
_loginButton.setEnabled(false);
|
||||||
_contentBox.append(spinner);
|
_loginButton.onClick([this] { loginClicked(); });
|
||||||
_contentBox.setMargins(48);
|
|
||||||
_contentBox.setVAlign(GTK_ALIGN_CENTER);
|
|
||||||
_contentBox.setVExpand(true);
|
|
||||||
|
|
||||||
_rootBox.append(header);
|
gtkpp::Box contentBox(GTK_ORIENTATION_VERTICAL, 8);
|
||||||
_rootBox.append(_contentBox);
|
contentBox.append(_loginEntry);
|
||||||
|
contentBox.append(_passwordEntry);
|
||||||
|
contentBox.append(_loginButton);
|
||||||
|
contentBox.append(_spinner);
|
||||||
|
contentBox.setMargins(48);
|
||||||
|
contentBox.setVAlign(GTK_ALIGN_CENTER);
|
||||||
|
contentBox.setVExpand(true);
|
||||||
|
|
||||||
adw_window_set_content(ADW_WINDOW(_window), _rootBox.gobj());
|
gtkpp::Box rootBox(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
rootBox.append(gtkpp::HeaderBar("Login"));
|
||||||
|
rootBox.append(contentBox);
|
||||||
|
|
||||||
// _emailField.set_placeholder_text("Email");
|
adw_window_set_content(ADW_WINDOW(_window), rootBox.gobj());
|
||||||
// _passwordField.set_placeholder_text("Password");
|
|
||||||
// _passwordField.set_input_purpose(Gtk::InputPurpose::PASSWORD);
|
|
||||||
// _passwordField.set_visibility(false);
|
|
||||||
//
|
|
||||||
// _emailField.signal_changed().connect(sigc::mem_fun(*this, &LoginWindow::validateFields));
|
|
||||||
// _passwordField.signal_changed().connect(sigc::mem_fun(*this, &LoginWindow::validateFields));
|
|
||||||
//
|
|
||||||
// _loginButton.set_margin_top(8);
|
|
||||||
// _loginButton.set_margin_bottom(8);
|
|
||||||
// _loginButton.set_label("Log in");
|
|
||||||
// _loginButton.signal_clicked().connect(sigc::mem_fun(*this, &LoginWindow::loginClicked));
|
|
||||||
// _loginButton.set_sensitive(false);
|
|
||||||
//
|
|
||||||
// Gtk::Box box(Gtk::Orientation::VERTICAL, 8);
|
|
||||||
// box.set_margin(48);
|
|
||||||
// box.set_valign(Gtk::Align::CENTER);
|
|
||||||
//
|
|
||||||
// box.append(_emailField);
|
|
||||||
// box.append(_passwordField);
|
|
||||||
// box.append(_loginButton);
|
|
||||||
// box.append(_spinner);
|
|
||||||
//
|
|
||||||
// set_child(box);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginWindow::loginClicked() {
|
void LoginWindow::loginClicked() {
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
#include "../gtkpp/Window.h"
|
#include "../gtkpp/Window.h"
|
||||||
#include "../gtkpp/Box.h"
|
#include "../gtkpp/Box.h"
|
||||||
#include "../gtkpp/Entry.h"
|
#include "../gtkpp/Entry.h"
|
||||||
|
#include "../gtkpp/Button.h"
|
||||||
|
#include "../gtkpp/Spinner.h"
|
||||||
|
|
||||||
class LoginWindow: public gtkpp::Window {
|
class LoginWindow: public gtkpp::Window {
|
||||||
private:
|
private:
|
||||||
@ -18,10 +20,10 @@ private:
|
|||||||
// Gtk::Spinner _spinner;
|
// Gtk::Spinner _spinner;
|
||||||
// std::unique_ptr<Gtk::MessageDialog> _dialog;
|
// std::unique_ptr<Gtk::MessageDialog> _dialog;
|
||||||
|
|
||||||
gtkpp::Box _rootBox;
|
|
||||||
gtkpp::Box _contentBox;
|
|
||||||
gtkpp::Entry _loginEntry;
|
gtkpp::Entry _loginEntry;
|
||||||
gtkpp::Entry _passwordEntry;
|
gtkpp::Entry _passwordEntry;
|
||||||
|
gtkpp::Button _loginButton;
|
||||||
|
gtkpp::Spinner _spinner;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LoginWindow();
|
LoginWindow();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user