Added DynamicSubviewPort class

This commit is contained in:
Otto 2024-10-09 00:23:50 +03:00
parent f14cd281b7
commit fe0863aea6
2 changed files with 59 additions and 1 deletions

View file

@ -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<SubViewport>
}
use godot::classes::ISubViewport;
#[godot_api]
impl ISubViewport for DynamicSubViewport {
fn init(base: Base<SubViewport>) -> 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());
// },
// _ => {}
// }
// }
_ => {}
}
}
}

View file

@ -1,3 +1,4 @@
pub mod scrambling_text;
pub mod manager;
pub mod config;
pub mod dynamic_subviewport;