Skip to content

Commit

Permalink
wallet/chatedit: fix scroll bug by returning 0 when inner_height < ma…
Browse files Browse the repository at this point in the history
…x_height in max_scroll() calc
  • Loading branch information
darkfi committed Jan 6, 2025
1 parent c416774 commit f4f414e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions bin/darkwallet/src/app/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
17 changes: 11 additions & 6 deletions bin/darkwallet/src/ui/chatedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f4f414e

Please sign in to comment.