I'm not sure if you're still in need of a solution here, but I have figured out a way to do this without needing to create a larger collision area than the line itself (which is also difficult to get correct if the line can be at any arbitrary angle).
I am not sure if this solution is performant as I've not tested in volume whatsoever, but it does seem to work quite well in limited testing.
The solution is to first create a
RayCast2D combo to define a ray from one end of the line (set to the ray's
.position property) to the other (set to the ray's
.cast_to property). Store this RayCast2D node together with the Line2D node it is associated with in a member variable for later lookup. Be sure to exclude any nodes that may collide with the line but you don't care about with the
.add_exception() of RayCast2D.
Then, create a
CollisionPolygon2D combo that will define the "mouse collision pointer". I set this area to be a size of 4px by 4px, but you can tweak it according to your requirements (this enables the desired "mouse detection area to be slightly wider than the wire" behavior).
Store the collision polygon as a member variable and create a function to update this collision polygon's position to match the mouse position, and call it from
_physics_process() to ensure this collision polygon is always centered at the mouse's current position.
_physics_process() add a loop that iterates the aforementioned ray+line list, checking each ray's
is_colliding(). You can even extend this data structure to store previous state, therefore allowing "entry" & "exit" event detection over the line's ray, allowing you to change its color (etc.) as you mentioned was desirable and is done here.
I attempted to distill the working code into a smaller example here but that turned out to be a challenge, so I just went ahead and pushed the project in which I implemented this to Github here (hence where all the above links came from), and also deployed a runnable version here. I hope it helps!