Added focus on widget #26
This commit is contained in:
@@ -69,6 +69,7 @@ pub struct WidgetLoad(BoxedElement, HashMap<TypeId, BoxedComponent>);
|
|||||||
pub struct StaticWidget {
|
pub struct StaticWidget {
|
||||||
element: Mutex<BoxedElement>,
|
element: Mutex<BoxedElement>,
|
||||||
components: Mutex<HashMap<TypeId, BoxedComponent>>,
|
components: Mutex<HashMap<TypeId, BoxedComponent>>,
|
||||||
|
focused: Mutex<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A widget with dynamic content and dependency tracking.
|
/// A widget with dynamic content and dependency tracking.
|
||||||
@@ -81,6 +82,7 @@ pub struct DynWidget {
|
|||||||
load: Mutex<Box<dyn FnMut() -> WidgetLoad + Send + Sync>>,
|
load: Mutex<Box<dyn FnMut() -> WidgetLoad + Send + Sync>>,
|
||||||
dependencies: Mutex<Vec<Box<dyn DependencyHandler>>>,
|
dependencies: Mutex<Vec<Box<dyn DependencyHandler>>>,
|
||||||
injection: Mutex<Option<Box<dyn FnMut(WidgetLoad) -> WidgetLoad + Send + Sync>>>,
|
injection: Mutex<Option<Box<dyn FnMut(WidgetLoad) -> WidgetLoad + Send + Sync>>>,
|
||||||
|
focused: Mutex<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A reference-counted wrapper around either a static or dynamic widget.
|
/// A reference-counted wrapper around either a static or dynamic widget.
|
||||||
@@ -129,6 +131,20 @@ impl Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
|
pub fn is_focused(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Dynamic(w) => *w.focused.lock().unwrap(),
|
||||||
|
Self::Static(w) => *w.focused.lock().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_focused(&self, f: bool) {
|
||||||
|
match self {
|
||||||
|
Self::Dynamic(w) => *w.focused.lock().unwrap() = f,
|
||||||
|
Self::Static(w) => *w.focused.lock().unwrap() = f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_elem(&self) -> MutexGuard<BoxedElement> {
|
pub fn get_elem(&self) -> MutexGuard<BoxedElement> {
|
||||||
match self {
|
match self {
|
||||||
Widget::Static(w) => w.get_elem(),
|
Widget::Static(w) => w.get_elem(),
|
||||||
@@ -232,6 +248,7 @@ impl Widget {
|
|||||||
wrapper.call(self, e);
|
wrapper.call(self, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.is_focused() {
|
||||||
match &**self {
|
match &**self {
|
||||||
Widget::Dynamic(w) => {
|
Widget::Dynamic(w) => {
|
||||||
w.get_elem().event(e);
|
w.get_elem().event(e);
|
||||||
@@ -242,6 +259,7 @@ impl Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl StaticWidget {
|
impl StaticWidget {
|
||||||
fn after_render(&self) {}
|
fn after_render(&self) {}
|
||||||
@@ -255,6 +273,7 @@ impl StaticWidget {
|
|||||||
Self {
|
Self {
|
||||||
element: Mutex::new(e),
|
element: Mutex::new(e),
|
||||||
components: Mutex::new(HashMap::new()),
|
components: Mutex::new(HashMap::new()),
|
||||||
|
focused: Mutex::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +318,7 @@ impl DynWidget {
|
|||||||
load: Mutex::new(Box::new(e)),
|
load: Mutex::new(Box::new(e)),
|
||||||
dependencies: Mutex::new(Vec::new()),
|
dependencies: Mutex::new(Vec::new()),
|
||||||
injection: Mutex::new(None),
|
injection: Mutex::new(None),
|
||||||
|
focused: Mutex::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user