From fe0863aea60bd62ef383e9574a2ad3b3a668c9d2 Mon Sep 17 00:00:00 2001 From: XTRA Date: Wed, 9 Oct 2024 00:23:50 +0300 Subject: [PATCH] Added DynamicSubviewPort class --- src/classes/dynamic_subviewport.rs | 57 ++++++++++++++++++++++++++++++ src/classes/mod.rs | 3 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/classes/dynamic_subviewport.rs diff --git a/src/classes/dynamic_subviewport.rs b/src/classes/dynamic_subviewport.rs new file mode 100644 index 0000000..57e34af --- /dev/null +++ b/src/classes/dynamic_subviewport.rs @@ -0,0 +1,57 @@ +use godot::classes::notify::NodeNotification; +use godot::prelude::*; +use godot::classes::SubViewport; + +#[derive(GodotClass)] +#[class(base=SubViewport)] +struct DynamicSubViewport { + base: Base +} + +use godot::classes::ISubViewport; + +#[godot_api] +impl ISubViewport for DynamicSubViewport { + + fn init(base: Base) -> Self { + Self { + base, + } + } + + fn on_notification(&mut self, what: NodeNotification) { + match what { + NodeNotification::READY => { + let root = self.base_mut().get_tree().unwrap().get_root(); + match root { + Some(v) => { + self.base_mut().set_size(v.get_size()); + }, + _ => {} + } + } + NodeNotification::PHYSICS_PROCESS => { + let root = self.base_mut().get_tree().unwrap().get_root(); + match root { + Some(v) => { + self.base_mut().set_size(v.get_size()); + }, + _ => {} + } + } + // FIXME: WM_SIZE_CHANGED is not what we are looking for, find a better way of detecting + // when the viewport size is changed so we don't have to make the viewport the same size as root every frame + + // NodeNotification::WM_SIZE_CHANGED => { + // let root = self.base_mut().get_tree().unwrap().get_root(); + // match root { + // Some(v) => { + // self.base_mut().set_size(v.get_size()); + // }, + // _ => {} + // } + // } + _ => {} + } + } +} \ No newline at end of file diff --git a/src/classes/mod.rs b/src/classes/mod.rs index 5b2b6f1..8620d84 100644 --- a/src/classes/mod.rs +++ b/src/classes/mod.rs @@ -1,3 +1,4 @@ pub mod scrambling_text; pub mod manager; -pub mod config; \ No newline at end of file +pub mod config; +pub mod dynamic_subviewport; \ No newline at end of file