aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-10 19:14:08 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-10 19:22:07 +0100
commitc183479553dbc81e0eb7f632720c278fa5308b2c (patch)
treece2ab325e48837ba8f7b1d3c9ee2d14f067a41d4 /src
parente8085267aeb23e33fd5cdbc2e4b6d43c64cc7a78 (diff)
Scroll page instead of changing body item if the item cant be fully displayed inside the window
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp29
-rw-r--r--src/plugins/Matrix.cpp8
2 files changed, 34 insertions, 3 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 06907c8..f224d06 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -132,6 +132,11 @@ namespace QuickMedia {
if(items.empty())
return false;
+ if(!selected_line_top_visible) {
+ page_scroll += 32.0f;
+ return true;
+ }
+
int new_selected_item = selected_item;
int num_items = (int)items.size();
@@ -160,6 +165,11 @@ namespace QuickMedia {
if(items.empty())
return false;
+ if(!selected_line_bottom_visible) {
+ page_scroll -= 32.0f;
+ return true;
+ }
+
int new_selected_item = selected_item;
int num_items = (int)items.size();
@@ -328,6 +338,8 @@ namespace QuickMedia {
num_visible_items = 0;
last_item_fully_visible = true;
last_fully_visible_item = -1;
+ selected_line_top_visible = true;
+ selected_line_bottom_visible = true;
int num_items = items.size();
if(num_items == 0 || size.y <= 0.0f) {
@@ -381,9 +393,22 @@ namespace QuickMedia {
}
float selected_item_height = get_item_height(items[selected_item].get(), size.x) + spacing_y;
- if(page_scroll > size.y - selected_item_height) {
+ bool selected_item_fits_on_screen = selected_item_height <= size.y;
+ selected_line_top_visible = pos.y - start_y + page_scroll >= 0.0f;
+ selected_line_bottom_visible = pos.y - start_y + page_scroll + selected_item_height <= size.y;
+
+ if(pos.y - start_y + page_scroll >= size.y)
+ page_scroll -= 32.0f;
+ else if(pos.y - start_y + page_scroll + selected_item_height <= 0.0f)
+ page_scroll += 32.0f;
+
+ selected_line_top_visible |= selected_item_fits_on_screen;
+ selected_line_bottom_visible |= selected_item_fits_on_screen;
+ if(page_scroll > size.y - selected_item_height && selected_item_fits_on_screen) {
+ //fprintf(stderr, "top!\n");
page_scroll = size.y - selected_item_height;
- } else if(page_scroll < 0.0f) {
+ } else if(page_scroll < 0.0f && selected_line_top_visible && selected_item_fits_on_screen) {
+ //fprintf(stderr, "bottom!\n");
page_scroll = 0.0f;
}
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index a90bb30..d6034de 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -496,7 +496,7 @@ namespace QuickMedia {
for(auto &message : messages) {
if(message->mentions_me) {
// TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user
- if(!is_window_focused || room != current_room || is_initial_sync || page_type == MatrixPageType::ROOM_LIST)
+ if((!is_window_focused || room != current_room || is_initial_sync || page_type == MatrixPageType::ROOM_LIST) && message->related_event_type != RelatedEventType::EDIT && message->related_event_type != RelatedEventType::REDACTION)
show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->get_name() + ")", message->body);
}
}
@@ -534,6 +534,7 @@ namespace QuickMedia {
void MatrixRoomsPage::update() {
{
std::lock_guard<std::mutex> lock(mutex);
+ int prev_selected_item = body->get_selected_item();
if(clear_data_on_update) {
clear_data_on_update = false;
body->clear_items();
@@ -555,6 +556,7 @@ namespace QuickMedia {
}
pending_remove_body_items.clear();
+ body->set_selected_item(prev_selected_item, false);
body->clamp_selection();
body->append_items(std::move(room_body_items));
}
@@ -645,6 +647,7 @@ namespace QuickMedia {
void MatrixRoomTagsPage::update() {
{
std::lock_guard<std::recursive_mutex> lock(mutex);
+ int prev_selected_item = body->get_selected_item();
if(clear_data_on_update) {
clear_data_on_update = false;
body->clear_items();
@@ -696,6 +699,7 @@ namespace QuickMedia {
}
}
add_room_body_items_by_tags.clear();
+ body->set_selected_item(prev_selected_item, false);
}
matrix_delegate->update(MatrixPageType::ROOM_LIST);
if(filter_on_update) {
@@ -794,6 +798,7 @@ namespace QuickMedia {
void MatrixInvitesPage::update() {
std::lock_guard<std::mutex> lock(mutex);
+ int prev_selected_item = body->get_selected_item();
if(clear_data_on_update) {
clear_data_on_update = false;
body->clear_items();
@@ -806,6 +811,7 @@ namespace QuickMedia {
remove_body_item_by_url(body->items, room_id);
}
pending_remove_body_items.clear();
+ body->set_selected_item(prev_selected_item, false);
body->clamp_selection();
// TODO: Insert in reverse order (to show the latest invite at the top?)