Просмотр исходного кода

wallet/chatedit: fix scroll bug by returning 0 when inner_height < max_height in max_scroll() calc

darkfi 1 год назад
Родитель
Сommit
f4f414e537
2 измененных файлов с 17 добавлено и 6 удалено
  1. 6 0
      bin/darkwallet/src/app/schema/mod.rs
  2. 11 6
      bin/darkwallet/src/ui/chatedit.rs

+ 6 - 0
bin/darkwallet/src/app/schema/mod.rs

@@ -163,4 +163,10 @@ pub async fn make(app: &App, window: SceneNodePtr) {
         chat::make(app, window.clone(), channel, &db, emoji_meshes.clone()).await;
     }
     menu::make(app, window.clone()).await;
+
+    // @@@ Debug stuff @@@
+    let chatview_node = app.sg_root.clone().lookup_node("/window/dev_chat_layer").unwrap();
+    chatview_node.set_property_bool(Role::App, "is_visible", true).unwrap();
+    let menu_node = app.sg_root.clone().lookup_node("/window/menu_layer").unwrap();
+    menu_node.set_property_bool(Role::App, "is_visible", false).unwrap();
 }

+ 11 - 6
bin/darkwallet/src/ui/chatedit.rs

@@ -1536,13 +1536,18 @@ impl ChatEdit {
 
     fn max_scroll(&self, text_wrap: &mut TextWrap) -> f32 {
         let width = self.wrap_width();
-        let wrapped_lines = text_wrap.wrap(width);
-        let rect_h = self.rect.get().h;
-        let mut max_scroll = wrapped_lines.height() - rect_h;
+        let mut inner_height = text_wrap.wrap(width).height();
         // Top padding
-        max_scroll += self.padding.get_f32(0).unwrap();
+        inner_height += self.padding.get_f32(0).unwrap();
         // Bottom padding
-        max_scroll += self.padding.get_f32(1).unwrap();
+        inner_height += self.padding.get_f32(1).unwrap();
+
+        let max_height = self.max_height.get();
+        if inner_height < max_height {
+            return 0.
+        }
+
+        let max_scroll = inner_height - max_height;
         max_scroll.clamp(0., f32::MAX)
     }
 
@@ -1943,7 +1948,7 @@ impl UIObject for ChatEdit {
             self.max_scroll(&mut text_wrap)
         };
 
-        let mut scroll = self.scroll.get() + wheel_pos.y * self.scroll_speed.get();
+        let mut scroll = self.scroll.get() - wheel_pos.y * self.scroll_speed.get();
         scroll = scroll.clamp(0., max_scroll);
         debug!(target: "ui::chatedit", "handle_mouse_wheel({wheel_pos:?}) [scroll={scroll}]");
         self.scroll.set(scroll);