Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Fixed _input being falsely detected when a Godot GUI element is on …
Browse files Browse the repository at this point in the history
…top of the other element.
  • Loading branch information
jacobsky committed Sep 8, 2021
1 parent b9693a8 commit 1b7097e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion egui_stylist_addon/src/stylist.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use egui_stylist::StylerState;
use gdnative::api::{FileDialog};
use gdnative::api::FileDialog;
use gdnative::prelude::*;
use godot_egui::GodotEgui;

Expand Down
8 changes: 2 additions & 6 deletions godot_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub struct GodotEgui {
theme: Option<Ref<gdnative::api::Resource>>,
}


#[gdnative::methods]
impl GodotEgui {
/// Constructs a new egui node
Expand Down Expand Up @@ -129,16 +128,13 @@ impl GodotEgui {

/// Callback to listen for input. Translates input back to egui events.
#[export]
fn _input(&mut self, owner: TRef<Control>, event: Ref<InputEvent>) {
fn _gui_input(&mut self, owner: TRef<Control>, event: Ref<InputEvent>) {
let event = unsafe { event.assume_safe() };
let mut raw_input = self.raw_input.borrow_mut();

// Transforms mouse positions in viewport coordinates to egui coordinates.
// NOTE: The egui is painted inside a control node, so its global rect offset must be taken into account
let mouse_pos_to_egui = |mouse_pos: Vector2| {
let transformed_pos = mouse_pos - owner.get_global_rect().origin.to_vector();
egui::Pos2 { x: transformed_pos.x, y: transformed_pos.y }
};
let mouse_pos_to_egui = |mouse_pos: Vector2| egui::Pos2 { x: mouse_pos.x, y: mouse_pos.y };

if let Some(motion_ev) = event.cast::<InputEventMouseMotion>() {
self.maybe_set_mouse_input_as_handled(owner);
Expand Down

0 comments on commit 1b7097e

Please sign in to comment.