aboutsummaryrefslogtreecommitdiff
path: root/src/ChatWindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ChatWindow.cpp')
-rw-r--r--src/ChatWindow.cpp59
1 files changed, 52 insertions, 7 deletions
diff --git a/src/ChatWindow.cpp b/src/ChatWindow.cpp
index b0bb696..041d2c3 100644
--- a/src/ChatWindow.cpp
+++ b/src/ChatWindow.cpp
@@ -1,6 +1,8 @@
#include "../include/ChatWindow.hpp"
#include "../include/ChatMessage.hpp"
#include <gtkmm/alignment.h>
+#include <gtkmm/viewport.h>
+#include <gtkmm/scrollbar.h>
#include <cassert>
namespace dchat
@@ -82,23 +84,66 @@ namespace dchat
void ChatWindow::setupMessageArea(Gtk::Grid *rightPanel)
{
- chatArea.set_vexpand(true);
- chatArea.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_AUTOMATIC);
- rightPanel->attach(chatArea, 0, 0, 1, 2);
+ //messageArea.set_valign(Gtk::ALIGN_START);
+ messageArea.set_vexpand(true);
+ messageArea.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_AUTOMATIC);
+ rightPanel->attach(messageArea, 0, 0, 1, 2);
- chatAreaLayout.set_name("chat-area-layout");
- chatArea.add(chatAreaLayout);
+ messageAreaLayout.set_name("chat-area-layout");
+ messageArea.add(messageAreaLayout);
}
void ChatWindow::setupChatInput(Gtk::Grid *rightPanel)
{
+ Gtk::Grid *chatArea = Gtk::manage(new Gtk::Grid());
+ rightPanel->attach_next_to(*chatArea, messageArea, Gtk::POS_BOTTOM, 1, 1);
+
Gtk::ScrolledWindow *chatScrollWindow = Gtk::manage(new Gtk::ScrolledWindow());
+ chatScrollWindow->set_hexpand(true);
+ chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER);
chatScrollWindow->set_name("chat-scroll-view");
- rightPanel->attach_next_to(*chatScrollWindow, chatArea, Gtk::POS_BOTTOM, 1, 1);
+ chatArea->attach(*chatScrollWindow, 0, 0, 1, 1);
chatInput.set_hexpand(true);
chatInput.set_name("chat-input");
chatInput.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR);
+
+ double fontSize = 18.5;//PANGO_PIXELS(chatInput.get_style_context()->get_font().get_size());
+ chatPrevNumLines = 1;
+ chatInput.get_buffer()->signal_changed().connect([this, chatScrollWindow, fontSize]
+ {
+ int numLines = chatInput.get_buffer()->get_line_count();
+ numLines = std::min(numLines, 10);
+ if(numLines != chatPrevNumLines)
+ {
+ chatPrevNumLines = numLines;
+ chatScrollWindow->set_min_content_height(fontSize * numLines);
+
+ auto adj = chatScrollWindow->get_vadjustment();
+ if(chatInput.get_buffer()->get_line_count() <= 10)
+ {
+ chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER);
+ adj->set_value(0);
+ }
+ else
+ {
+ chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_ALWAYS);
+ }
+ }
+ });
+ chatScrollWindow->get_vadjustment()->signal_value_changed().connect([this, chatScrollWindow]()
+ {
+ auto adj = chatScrollWindow->get_vadjustment();
+ if(chatInput.get_buffer()->get_line_count() <= 11)
+ {
+ chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER);
+ adj->set_value(0);
+ }
+ else
+ {
+ chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_ALWAYS);
+ }
+ });
chatScrollWindow->add(chatInput);
}
@@ -143,7 +188,7 @@ namespace dchat
message->set_valign(Gtk::Align::ALIGN_START);
message->set_hexpand(true);
message->show_all();
- chatAreaLayout.attach(*message, 0, it->second.messageCount, 1, 1);
+ messageAreaLayout.attach(*message, 0, it->second.messageCount, 1, 1);
++it->second.messageCount;
}