fixed crash on text field editing

This commit is contained in:
Selim Mustafaev 2022-05-13 01:55:00 +03:00
parent ff532f5ed9
commit 458901c029
7 changed files with 37 additions and 15 deletions

View File

@ -22,7 +22,6 @@ namespace gtkpp {
}
void Application::onActivate(const std::function<void()>& callback) {
_signalActivate.connect(callback);
}
@ -31,6 +30,7 @@ namespace gtkpp {
}
void Application::addWindow(const std::shared_ptr<Window>& window) {
_window = window;
gtk_application_add_window(GTK_APPLICATION(_app), GTK_WINDOW(window->gobj()));
}

View File

@ -17,6 +17,7 @@ namespace gtkpp {
class Application {
private:
AdwApplication* _app;
std::shared_ptr<Window> _window;
sigc::signal<void()> _signalActivate;
private:

View File

@ -3,11 +3,11 @@
//
#include "Entry.h"
#include <iostream>
namespace gtkpp {
void changedCallback(GtkEntry* widget, void* data) {
auto entry = reinterpret_cast<Entry*>(data);
void changedCallback(GtkEntry*, Entry* entry) {
entry->_signalChanged.emit();
}
@ -32,4 +32,13 @@ namespace gtkpp {
_signalChanged.connect(callback);
}
int Entry::textLength() const {
return gtk_entry_get_text_length(GTK_ENTRY(_widget));
}
std::string Entry::text() const {
auto buffer = gtk_entry_get_buffer(GTK_ENTRY(_widget));
return gtk_entry_buffer_get_text(buffer);
}
}

View File

@ -16,7 +16,7 @@ namespace gtkpp {
sigc::signal<void()> _signalChanged;
private:
friend void changedCallback(GtkEntry* widget, void* data);
friend void changedCallback(GtkEntry*, Entry* entry);
public:
Entry();
@ -24,6 +24,8 @@ namespace gtkpp {
void setPurpose(GtkInputPurpose purpose);
void setVisibility(bool visibility);
void onChanged(const std::function<void()>& callback);
int textLength() const;
std::string text() const;
};
}

View File

@ -10,4 +10,12 @@ namespace gtkpp {
_widget = gtk_spinner_new();
}
void Spinner::start() {
gtk_spinner_start(GTK_SPINNER(_widget));
}
void Spinner::stop() {
gtk_spinner_stop(GTK_SPINNER(_widget));
}
}

View File

@ -12,6 +12,8 @@ namespace gtkpp {
class Spinner: public Widget {
public:
Spinner();
void start();
void stop();
};
}

View File

@ -48,12 +48,12 @@ LoginWindow::LoginWindow() {
}
void LoginWindow::loginClicked() {
// auto email = _emailField.get_text();
// auto password = _passwordField.get_text();
//
// enableControls(false);
// _spinner.start();
//
auto email = _loginEntry.text();
auto password = _passwordEntry.text();
enableControls(false);
_spinner.start();
// try {
// User user = co_await Api::login(email, password).scheduleOn(GLibMainContextExecutor::instance());
// auto app = this->get_application();
@ -70,8 +70,8 @@ void LoginWindow::loginClicked() {
}
void LoginWindow::validateFields() {
// bool buttonEnabled = _emailField.get_text_length() > 0 && _passwordField.get_text_length() > 0;
// _loginButton.set_sensitive(buttonEnabled);
bool buttonEnabled = _loginEntry.textLength() > 3 && _passwordEntry.textLength() > 3;
_loginButton.setEnabled(buttonEnabled);
}
void LoginWindow::showError(const std::string& message) {
@ -88,7 +88,7 @@ void LoginWindow::showError(const std::string& message) {
}
void LoginWindow::enableControls(bool enable) {
// _loginButton.set_sensitive(enable);
// _emailField.set_sensitive(enable);
// _passwordField.set_sensitive(enable);
_loginButton.setEnabled(enable);
_loginEntry.setEnabled(enable);
_passwordEntry.setEnabled(enable);
}