Added ghost elements to avoid focusing on them
This commit is contained in:
+29
-4
@@ -31,11 +31,21 @@ pub type BoxedComponent = Box<dyn Component + Send + Sync>;
|
||||
pub trait Element: Send + Sync {
|
||||
/// Called to perform rendering for the element.
|
||||
#[allow(unused)]
|
||||
fn render(&mut self, scope: &mut RenderScope, render_context: &crate::render_scope::RenderContext) {}
|
||||
fn render(
|
||||
&mut self,
|
||||
scope: &mut RenderScope,
|
||||
render_context: &crate::render_scope::RenderContext,
|
||||
) {
|
||||
}
|
||||
|
||||
/// Called after rendering, for follow-up logic or cleanup.
|
||||
#[allow(unused)]
|
||||
fn after_render(&mut self, scope: &mut RenderScope, render_context: &crate::render_scope::RenderContext) {}
|
||||
fn after_render(
|
||||
&mut self,
|
||||
scope: &mut RenderScope,
|
||||
render_context: &crate::render_scope::RenderContext,
|
||||
) {
|
||||
}
|
||||
|
||||
/// Called to draw child widgets, if any.
|
||||
#[allow(unused)]
|
||||
@@ -44,6 +54,10 @@ pub trait Element: Send + Sync {
|
||||
#[allow(unused)]
|
||||
fn event(&mut self, event: &dyn Event) {}
|
||||
|
||||
fn is_ghost(&mut self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Returns a type-erased reference to this object.
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
@@ -138,10 +152,21 @@ impl Widget {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_ghost(&self) -> bool {
|
||||
match self {
|
||||
Self::Dynamic(w) => w.element.lock().unwrap().is_ghost(),
|
||||
Self::Static(w) => w.element.lock().unwrap().is_ghost(),
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
Self::Dynamic(w) => {
|
||||
*w.focused.lock().unwrap() = f && !w.element.lock().unwrap().is_ghost()
|
||||
}
|
||||
Self::Static(w) => {
|
||||
*w.focused.lock().unwrap() = f && !w.element.lock().unwrap().is_ghost()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user