From b3a3292811aa627a9a2174ee443d96acbb35c14f Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sat, 14 Dec 2024 09:55:20 +0000 Subject: [PATCH 1/5] widget_derive: remove unnecessary usages of Option --- crates/kas-macros/src/widget_derive.rs | 34 +++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/crates/kas-macros/src/widget_derive.rs b/crates/kas-macros/src/widget_derive.rs index 8a0721fc..21645b1c 100644 --- a/crates/kas-macros/src/widget_derive.rs +++ b/crates/kas-macros/src/widget_derive.rs @@ -129,7 +129,7 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( } }; - let fn_size_rules = Some(quote! { + let fn_size_rules = quote! { #[inline] fn size_rules(&mut self, sizer: ::kas::theme::SizeCx, @@ -137,7 +137,7 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( ) -> ::kas::layout::SizeRules { self.#inner.size_rules(sizer, axis) } - }); + }; let fn_set_rect = quote! { #[inline] fn set_rect( @@ -149,30 +149,30 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( self.#inner.set_rect(cx, rect, hints); } }; - let fn_nav_next = Some(quote! { + let fn_nav_next = quote! { #[inline] fn nav_next(&self, reverse: bool, from: Option) -> Option { self.#inner.nav_next(reverse, from) } - }); - let fn_translation = Some(quote! { + }; + let fn_translation = quote! { #[inline] fn translation(&self) -> ::kas::geom::Offset { self.#inner.translation() } - }); + }; let fn_find_id = quote! { #[inline] fn find_id(&mut self, coord: ::kas::geom::Coord) -> Option<::kas::Id> { self.#inner.find_id(coord) } }; - let fn_draw = Some(quote! { + let fn_draw = quote! { #[inline] fn draw(&mut self, draw: ::kas::theme::DrawCx) { self.#inner.draw(draw); } - }); + }; let data_ty: Type = 'outer: { for (i, field) in fields.iter_mut().enumerate() { @@ -260,9 +260,7 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( layout_impl.items.push(Verbatim(required_layout_methods)); if !has_item("size_rules") { - if let Some(method) = fn_size_rules { - layout_impl.items.push(Verbatim(method)); - } + layout_impl.items.push(Verbatim(fn_size_rules)); } if !has_item("set_rect") { @@ -270,9 +268,7 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( } if !has_item("nav_next") { - if let Some(method) = fn_nav_next { - layout_impl.items.push(Verbatim(method)); - } + layout_impl.items.push(Verbatim(fn_nav_next)); } if let Some(ident) = item_idents @@ -280,8 +276,8 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( .find_map(|(_, ident)| (*ident == "translation").then_some(ident)) { emit_error!(ident, "method not supported in derive mode"); - } else if let Some(method) = fn_translation { - layout_impl.items.push(Verbatim(method)); + } else { + layout_impl.items.push(Verbatim(fn_translation)); } if !has_item("find_id") { @@ -289,11 +285,9 @@ pub fn widget(_attr_span: Span, args: WidgetArgs, scope: &mut Scope) -> Result<( } if !has_item("draw") { - if let Some(method) = fn_draw { - layout_impl.items.push(Verbatim(method)); - } + layout_impl.items.push(Verbatim(fn_draw)); } - } else if let Some(fn_size_rules) = fn_size_rules { + } else { scope.generated.push(quote! { impl #impl_generics ::kas::Layout for #impl_target { #required_layout_methods From 630624e33c7194b8eb5312557afa4013dcb717b8 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sat, 14 Dec 2024 15:52:01 +0000 Subject: [PATCH 2/5] Add feature kas-macros/nightly --- crates/kas-core/Cargo.toml | 2 +- crates/kas-macros/Cargo.toml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/kas-core/Cargo.toml b/crates/kas-core/Cargo.toml index 6ae3dae7..cc67bac2 100644 --- a/crates/kas-core/Cargo.toml +++ b/crates/kas-core/Cargo.toml @@ -23,7 +23,7 @@ minimal = ["winit", "wayland"] # All standard test target features stable = ["minimal", "clipboard", "markdown", "shaping", "spawn", "x11", "serde", "toml", "yaml", "json", "ron", "macros_log", "image"] # Enables all "recommended" features for nightly rustc -nightly = ["stable"] +nightly = ["stable", "kas-macros/nightly"] # Additional, less recommendation-worthy features experimental = ["dark-light", "recursive-layout-widgets", "unsafe_node"] diff --git a/crates/kas-macros/Cargo.toml b/crates/kas-macros/Cargo.toml index 058571d0..3a2a6e79 100644 --- a/crates/kas-macros/Cargo.toml +++ b/crates/kas-macros/Cargo.toml @@ -22,6 +22,9 @@ log = [] # Optimize generated layout widgets recursive-layout-widgets = [] +# Enable reporting of warnings from proc-macros +nightly = ["proc-macro-error2/nightly"] + [dependencies] quote = "1.0" proc-macro2 = { version = "1.0" } From 072eedc77148d79f31df0c2fe761ff8153f02ef8 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sat, 14 Dec 2024 16:11:48 +0000 Subject: [PATCH 3/5] Replace serde_yaml with serde_yaml2 --- Cargo.toml | 2 +- crates/kas-core/Cargo.toml | 4 ++-- crates/kas-core/src/config/format.rs | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf777e64..d7e386c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ rustdoc-args = ["--cfg", "docsrs"] # about target platforms). # # Note: only some examples build in this configuration; others need view, -# markdown, resvg. Recommended also: clipboard, yaml (or some config format). +# markdown, resvg. Recommended also: clipboard, ron (or some config format). minimal = ["wgpu", "winit", "wayland"] # All recommended features for optimal experience default = ["minimal", "view", "image", "resvg", "clipboard", "markdown", "shaping", "spawn"] diff --git a/crates/kas-core/Cargo.toml b/crates/kas-core/Cargo.toml index cc67bac2..47432be4 100644 --- a/crates/kas-core/Cargo.toml +++ b/crates/kas-core/Cargo.toml @@ -43,7 +43,7 @@ markdown = ["kas-text/markdown"] shaping = ["kas-text/shaping"] # Enable support for YAML (de)serialisation -yaml = ["serde", "dep:serde_yaml"] +yaml = ["serde", "dep:serde_yaml2"] # Enable support for JSON (de)serialisation json = ["serde", "dep:serde_json"] @@ -100,7 +100,7 @@ linear-map = "1.2.0" thiserror = "2.0.3" serde = { version = "1.0.123", features = ["derive"], optional = true } serde_json = { version = "1.0.61", optional = true } -serde_yaml = { version = "0.9.9", optional = true } +serde_yaml2 = { version = "0.1.2", optional = true } ron = { version = "0.8.0", package = "ron", optional = true } toml = { version = "0.8.2", package = "toml", optional = true } num_enum = "0.7.0" diff --git a/crates/kas-core/src/config/format.rs b/crates/kas-core/src/config/format.rs index 2570abd1..a714f21a 100644 --- a/crates/kas-core/src/config/format.rs +++ b/crates/kas-core/src/config/format.rs @@ -14,8 +14,12 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[cfg(feature = "yaml")] - #[error("config (de)serialisation to YAML failed")] - Yaml(#[from] serde_yaml::Error), + #[error("config deserialisation failed")] + De(#[from] serde::de::value::Error), + + #[cfg(feature = "yaml")] + #[error("config serialisation to YAML failed")] + YamlSer(#[from] serde_yaml2::ser::Errors), #[cfg(feature = "json")] #[error("config (de)serialisation to JSON failed")] @@ -113,8 +117,8 @@ impl Format { } #[cfg(feature = "yaml")] Format::Yaml => { - let r = std::io::BufReader::new(std::fs::File::open(path)?); - Ok(serde_yaml::from_reader(r)?) + let contents = std::fs::read_to_string(path)?; + Ok(serde_yaml2::from_str(&contents)?) } #[cfg(feature = "ron")] Format::Ron => { @@ -148,7 +152,7 @@ impl Format { } #[cfg(feature = "yaml")] Format::Yaml => { - let text = serde_yaml::to_string(value)?; + let text = serde_yaml2::to_string(value)?; std::fs::write(path, text)?; Ok(()) } From 84ff0322a1799f7fe5da28617ab56b70341bd091 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 30 Dec 2024 10:11:32 +0000 Subject: [PATCH 4/5] Fix: fn List::set_rect must set self.core.rect --- crates/kas-widgets/src/list.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/kas-widgets/src/list.rs b/crates/kas-widgets/src/list.rs index 35871f35..267354b8 100644 --- a/crates/kas-widgets/src/list.rs +++ b/crates/kas-widgets/src/list.rs @@ -108,6 +108,7 @@ impl_scope! { } fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect, hints: AlignHints) { + self.core.rect = rect; let dim = (self.direction, self.widgets.len()); let mut setter = RowSetter::, _>::new(rect, dim, &mut self.layout); From dfa5e4d734683ac1802df1713a05601f4a63a67a Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 30 Dec 2024 10:23:00 +0000 Subject: [PATCH 5/5] Adjust kas-macros feature selection for tests --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index efeb0e81..a3cc50e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,7 +87,7 @@ jobs: run: sudo apt-get install -y libxkbcommon-dev libxcb-shape0-dev libxcb-xfixes0-dev - name: Test kas-macros - run: cargo test --manifest-path crates/kas-macros/Cargo.toml --all-features + run: cargo test --manifest-path crates/kas-macros/Cargo.toml --features log - name: Test kas-core run: cargo test --manifest-path crates/kas-core/Cargo.toml --features stable - name: Test kas-widgets