From 38814e9ce823b98e84ce2c28e2508570bed14f56 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 22 Nov 2023 10:04:56 +0000 Subject: [PATCH] Apply unable to generate `fn Layout::nav_next` warning to generated Layout impls --- crates/kas-macros/src/widget.rs | 11 +++++++---- examples/gallery.rs | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/kas-macros/src/widget.rs b/crates/kas-macros/src/widget.rs index 2f1ca92d3..1c60649ed 100644 --- a/crates/kas-macros/src/widget.rs +++ b/crates/kas-macros/src/widget.rs @@ -464,7 +464,6 @@ pub fn widget(attr_span: Span, mut args: WidgetArgs, scope: &mut Scope) -> Resul let (fn_set_rect, fn_nav_next, fn_find_id); let mut fn_nav_next_err = None; let mut fn_draw = None; - let mut gen_layout = false; if let Some(inner) = opt_derive { required_layout_methods = quote! { @@ -693,7 +692,6 @@ pub fn widget(attr_span: Span, mut args: WidgetArgs, scope: &mut Scope) -> Resul self.rect().contains(coord).then(|| self.id()) }; if let Some((_, layout)) = args.layout.take() { - gen_layout = true; fn_nav_next = match layout.nav_next(children.iter().map(|(ident, _, _)| ident)) { Ok(toks) => Some(toks), Err((span, msg)) => { @@ -913,9 +911,8 @@ pub fn widget(attr_span: Span, mut args: WidgetArgs, scope: &mut Scope) -> Resul if !has_item("nav_next") { if let Some(method) = fn_nav_next { layout_impl.items.push(Verbatim(method)); - } else if gen_layout { + } else if let Some((span, msg)) = fn_nav_next_err { // We emit a warning here only if nav_next is not explicitly defined - let (span, msg) = fn_nav_next_err.unwrap(); emit_warning!(span, "unable to generate `fn Layout::nav_next`: {}", msg,); } } @@ -957,6 +954,12 @@ pub fn widget(attr_span: Span, mut args: WidgetArgs, scope: &mut Scope) -> Resul layout_impl.items.push(Verbatim(method)); } } else if let Some(fn_size_rules) = fn_size_rules { + if fn_nav_next.is_none() { + if let Some((span, msg)) = fn_nav_next_err { + emit_warning!(span, "unable to generate `fn Layout::nav_next`: {}", msg,); + } + } + scope.generated.push(quote! { impl #impl_generics ::kas::Layout for #impl_target { #required_layout_methods diff --git a/examples/gallery.rs b/examples/gallery.rs index cfb2d3be1..646e4c7a8 100644 --- a/examples/gallery.rs +++ b/examples/gallery.rs @@ -302,6 +302,9 @@ Demonstration of *as-you-type* formatting from **Markdown**. #[widget{ layout = float! [ pack!(right top, Button::label_msg("↻", MsgDirection).map_any()), + // NOTE: non_navigable! is needed here to avoid requiring a + // nav_next impl on list! (not generable with non-static + // direction). TODO: find a more general solution. list!(self.dir, [self.editor, non_navigable!(self.label)]), ]; }]