malachid

malachid

Hands-on Rust: Mouse not scaling for the tooltips (151)

The layers in general are working, with the map, entities and hud. The tooltips are not showing up though. It seems that it is due to the filter failing in tooltips.rs. I verified that the source available from the site does run correctly, so I started comparing my code to yours - but am not seeing anything obvious. I tried adding some logging to both sets of code to see where it might be breaking.

In src/main.rs I tried adding a log:

ctx.set_active_console(0);
println!("mouse({}): {:?}", ctx.active_console, Point::from_tuple(ctx.mouse_pos));
self.resources.insert(Point::from_tuple(ctx.mouse_pos()));

If I move the mouse to the bottom right corner of the map, on both versions of the code, it shows that it is on console #0 with coordinates around x:2229 y:1354.

So next was in src/systems/tooltips.rs. Based on your comments here, I tried adding a log just before submitting the batch (drawing the log didn’t work).

println!("batch mouse: {:?}", *mouse_pos);
draw_batch.submit(10100).expect("Batch error");

Here, it differs.
For my code, this shows the mouse_pos at the same coordinates as listed in main.rs (ie: 2229x1354). For your code, it shows the mouse_pos at x:39 y:24.

I added more logging at the top of the tooltips.rs and the #[resource] mouse_pos: &Point is being populated with a different value between our two versions. Since the insert in the tick is the same, I thought maybe I configured the system incorrectly in main, but it’s the same there as well.

Any thoughts on why yours shows a large number during self.resources.insert(Point::from_tuple(ctx.mouse_pos)); but a smaller number during #[resource] mouse_pos: &Point? Mine shows the same number in both places.

Thanks for your help!

Marked As Solved

malachid

malachid

I figured it out.

ctx.mouse_pos vs ctx.mouse_pos()

Need to be careful about the auto-complete.

Where Next?

Popular Pragmatic Bookshelf topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
GilWright
Working through the steps (checking that the Info,plist matches exactly), run the demo game and what appears is grey but does not fill th...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New

Other popular topics Top

New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New

Sub Categories: