From 4a23517b6beddad8f4e2c5264d309fec590847e7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 29 Jan 2019 23:39:25 +0100 Subject: Fix chat input size with word wrapping, messed up channels sidebar... --- src/ChatWindow.cpp | 57 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/ChatWindow.cpp b/src/ChatWindow.cpp index d33c824..76df69e 100644 --- a/src/ChatWindow.cpp +++ b/src/ChatWindow.cpp @@ -150,9 +150,10 @@ namespace dchat channelsScrollWindow->set_overlay_scrolling(false); channelsLayout->attach_next_to(*channelsScrollWindow, *channelsTitle, Gtk::POS_BOTTOM, 1, 2); - leftPanelChannels.set_row_spacing(5); - leftPanelChannels.set_vexpand(true); - leftPanelChannels.set_hexpand(true); + leftPanelChannels.set_stack(messageAreaStack); + //leftPanelChannels.set_row_spacing(5); + //leftPanelChannels.set_vexpand(true); + //leftPanelChannels.set_hexpand(true); channelsScrollWindow->add(leftPanelChannels); //// @@ -239,14 +240,9 @@ namespace dchat void ChatWindow::setupMessageArea(Gtk::Grid *rightPanel) { - //messageArea.set_valign(Gtk::ALIGN_START); - messageArea.set_vexpand(true); - messageArea.set_overlay_scrolling(false); - messageArea.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_AUTOMATIC); - rightPanel->attach(messageArea, 0, 0, 1, 2); - messageAreaStack.set_name("message-area-layout"); - messageArea.add(messageAreaStack); + messageAreaStack.set_vexpand(true); + rightPanel->attach(messageAreaStack, 0, 0, 1, 2); } void ChatWindow::setupChatInput(Gtk::Grid *rightPanel) @@ -326,14 +322,15 @@ namespace dchat chatInputChangeByPlaceholder = false; } - int numLines = chatInput.get_buffer()->get_line_count(); + Gdk::Rectangle rect; + chatInput.get_iter_location(chatInput.get_buffer()->end(), rect); + int numLines = 1 + (rect.get_y() + rect.get_height()) / fontSize; if(numLines != chatPrevNumLines) { - if(numLines <= 10) - chatScrollWindow->set_min_content_height(fontSize * std::min(numLines, 10)); + chatScrollWindow->set_min_content_height(fontSize * std::min(numLines, 10)); auto adj = chatScrollWindow->get_vadjustment(); - if(chatInput.get_buffer()->get_line_count() <= 11) + if(numLines <= 11) { chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER); adj->set_value(0); @@ -346,10 +343,13 @@ namespace dchat chatPrevNumLines = numLines; }); - chatScrollWindow->get_vadjustment()->signal_value_changed().connect([this, chatScrollWindow]() + chatScrollWindow->get_vadjustment()->signal_value_changed().connect([this, chatScrollWindow, fontSize]() { + Gdk::Rectangle rect; + chatInput.get_iter_location(chatInput.get_buffer()->end(), rect); + int numLines = 1 + (rect.get_y() + rect.get_height()) / fontSize; auto adj = chatScrollWindow->get_vadjustment(); - if(chatInput.get_buffer()->get_line_count() <= 11) + if(numLines <= 11) { chatScrollWindow->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER); adj->set_value(0); @@ -369,9 +369,17 @@ namespace dchat leftPanelUsersLayout->show(); leftPanelUsersStack.add(*leftPanelUsersLayout, roomIdStr); + Gtk::ScrolledWindow *messageArea = Gtk::manage(new Gtk::ScrolledWindow()); + messageArea->set_vexpand(true); + messageArea->set_overlay_scrolling(false); + messageArea->set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_AUTOMATIC); + messageAreaStack.add(*messageArea, roomIdStr, "Room name"); + if(!messageAreaStack.get_visible_child()) + messageAreaStack.set_visible_child(roomIdStr); + Gtk::Grid *messageAreaLayout = new Gtk::Grid(); - messageAreaLayout->show(); - messageAreaStack.add(*messageAreaLayout, roomIdStr); + messageArea->add(*messageAreaLayout); + messageArea->show_all(); fprintf(stderr, "Added channel %s\n", room->id->toString().c_str()); Gtk::RadioButton *roomButton = new Gtk::RadioButton("Room name"); @@ -383,7 +391,7 @@ namespace dchat { setCurrentRoom(room); }); - leftPanelChannels.attach(*roomButton, 0, roomCount, 1, 1); + //leftPanelChannels.attach(*roomButton, 0, roomCount, 1, 1); ++roomCount; uint numMessages = 0; @@ -534,7 +542,8 @@ namespace dchat void ChatWindow::changeRoomName(const RoomChangeNameRequest &request) { - Gtk::RadioButton *button = roomDataById[*request.room->id]->button; + RoomData *roomData = roomDataById[*request.room->id]; + Gtk::RadioButton *button = roomData->button; button->set_label(request.newName); if(*request.room->id == *currentRoom->id) topbar->setTitle(request.newName); @@ -555,9 +564,9 @@ namespace dchat void ChatWindow::scrollToBottom() { - while(gtk_events_pending()) - gtk_main_iteration_do(FALSE); - auto adj = messageArea.get_vadjustment(); - adj->set_value(adj->get_upper()); + //while(gtk_events_pending()) + // gtk_main_iteration_do(FALSE); + //auto adj = messageArea.get_vadjustment(); + //adj->set_value(adj->get_upper()); } } -- cgit v1.2.3