summaryrefslogtreecommitdiffstats
path: root/src/app.rs
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2021-08-29 20:05:17 -0400
committerClementTsang <cjhtsang@uwaterloo.ca>2021-08-30 00:51:09 -0400
commit3fa50605b334909d8a0225eaefb6c91feb551ce5 (patch)
tree407ef6a31fcb87d72c384c85871adb9af765b3bf /src/app.rs
parent48c572dbafb443d505fc73fa0d598db3c727593f (diff)
bug: fix bug causing click bounds to fail
There were three bugs: 1. The click bounds calculation was incorrect. I did the silly mistake of checking for <= bounds for the bottom and right sections of a Rect when checking if the mouse intersected - this is WRONG. For example, let's say you want to calculate if an x value of 5 falls between something that starts at 0 and is 5 long. It shouldn't, right? Because it draws from 0 to 4? But if you just did <= Rect.right(), you would get a hit - because it just does (start + width), so you get 5, and 5 <= 5! So, easy fix, change all far bounds checks to <. 2. The second bug is a mistake where I accidentally did not include bounds sets for my memory and net widgets. Instead, they set their bounds to the underlying graph representation, which is WRONG, since that bound gets updated on draw, and gets set to a slightly smaller rect due to borders! 3. A slightly sneakier one. This broke my bounds checks for the CPU widget - and it would have broken my process widget too. The problem lies in the concept of widgets that handle multiple "sub"-blocks internally, and how I was doing click detection internally - I would check if the bounds of the internal Components were hit. Say, the CPU, I would check if the internal graph was hit, then if the internal table was hit. But wait! I said in point 2 that a graph gets its borders updated on draw to something slightly smaller, due to borders! And there's the problem - it affected tables too. I was setting the bounds of components to that of the *internal* representation - without borders - but my click detection *needed* borders included! Solution? Add another trait function to check bordered bounds, and make the default implementation just check the existing bounds. For cases like internal Components that may need it, I add a separate implementation. I also switched over all border bounds checks for Widgets to that, since it's a bit more consistent.
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/app.rs b/src/app.rs
index 939b316c..864ec490 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -353,11 +353,11 @@ impl AppState {
}
} else {
for (id, widget) in self.widget_lookup_map.iter_mut() {
- if widget.does_intersect_mouse(&event) {
- let is_id_selected = self.selected_widget == *id;
+ if widget.does_border_intersect_mouse(&event) {
+ let was_id_already_selected = self.selected_widget == *id;
self.selected_widget = *id;
- if is_id_selected {
+ if was_id_already_selected {
let result = widget.handle_mouse_event(event);
return self.convert_widget_event_result(result);
} else {