From d30ea7e584504ce0dacb11c76123021f9b19ffa0 Mon Sep 17 00:00:00 2001 From: John Mitchell <startoaster23@gmail.com> Date: Mon, 14 Nov 2022 12:32:18 -0500 Subject: [PATCH] Added the ability to grab the current focus. --- src/context.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/context.rs b/src/context.rs index ce07ef4..14ab8ef 100644 --- a/src/context.rs +++ b/src/context.rs @@ -113,10 +113,19 @@ impl KayakRootContext { } } + /// Adds a kayak plugin and runs the build function on the context. pub fn add_plugin(&mut self, plugin: impl KayakUIPlugin) { plugin.build(self) } + /// Retreives the current entity that has focus or None if nothing is focused. + pub fn get_current_focus(&self) -> Option<Entity> { + if let Ok(tree) = self.focus_tree.try_read() { + return tree.current().and_then(|a| Some(a.0)); + } + None + } + /// Get's the layout for th given widget index. pub(crate) fn get_layout(&self, id: &WrappedIndex) -> Option<Rect> { if let Ok(cache) = self.layout_cache.try_read() { -- GitLab