Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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"]
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 9 additions & 5 deletions crates/kas-core/src/config/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(())
}
Expand Down
3 changes: 3 additions & 0 deletions crates/kas-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
34 changes: 14 additions & 20 deletions crates/kas-macros/src/widget_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ 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,
axis: ::kas::layout::AxisInfo,
) -> ::kas::layout::SizeRules {
self.#inner.size_rules(sizer, axis)
}
});
};
let fn_set_rect = quote! {
#[inline]
fn set_rect(
Expand All @@ -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<usize>) -> Option<usize> {
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() {
Expand Down Expand Up @@ -260,40 +260,34 @@ 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") {
layout_impl.items.push(Verbatim(fn_set_rect));
}

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
.iter()
.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") {
layout_impl.items.push(Verbatim(fn_find_id));
}

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
Expand Down
1 change: 1 addition & 0 deletions crates/kas-widgets/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<D, Vec<i32>, _>::new(rect, dim, &mut self.layout);

Expand Down