mirror of
https://github.com/danbulant/cushy
synced 2026-07-06 19:50:40 +00:00
Fixing style inheritance
This commit is contained in:
parent
0adb43a234
commit
1ea9938198
3 changed files with 29 additions and 8 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -498,9 +498,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.16"
|
version = "0.8.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
|
checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
@ -1062,7 +1062,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kludgine"
|
name = "kludgine"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/khonsulabs/kludgine#52f58c39b0ab4e1e280d27f7228e8ccd9a377f50"
|
source = "git+https://github.com/khonsulabs/kludgine#90d2035c22bd92ddc5e7edf6c933886c55749bd3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"alot",
|
"alot",
|
||||||
|
|
@ -2135,9 +2135,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.40"
|
version = "2.0.41"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13fa70a4ee923979ffb522cacce59d34421ebdea5625e1073c4326ef9d2dd42e"
|
checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ impl Styles {
|
||||||
name.name().into_owned(),
|
name.name().into_owned(),
|
||||||
StoredComponent {
|
StoredComponent {
|
||||||
inherited: false,
|
inherited: false,
|
||||||
inheritable: false,
|
inheritable: true,
|
||||||
component: component.into_value().into_component_value(),
|
component: component.into_value().into_component_value(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -195,7 +195,7 @@ impl Styles {
|
||||||
.unwrap_or_else(|err| err.as_ref().clone())
|
.unwrap_or_else(|err| err.as_ref().clone())
|
||||||
.components
|
.components
|
||||||
{
|
{
|
||||||
if value.inherited || !value.inheritable {
|
if !value.inheritable || self.0.components.contains_key(&name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,6 +203,23 @@ impl Styles {
|
||||||
self.insert_named(name, value);
|
self.insert_named(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this collection of styles without any local style definitions.
|
||||||
|
#[must_use]
|
||||||
|
pub fn into_inherited(self) -> Self {
|
||||||
|
if self.0.components.values().any(|stored| !stored.inheritable) {
|
||||||
|
Self(Arc::new(StyleData {
|
||||||
|
components: Arc::try_unwrap(self.0)
|
||||||
|
.unwrap_or_else(|err| err.as_ref().clone())
|
||||||
|
.components
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(_, stored)| stored.inheritable)
|
||||||
|
.collect(),
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Styles {
|
impl Debug for Styles {
|
||||||
|
|
|
||||||
|
|
@ -607,7 +607,11 @@ impl Node {
|
||||||
fn child_styles(&self) -> Styles {
|
fn child_styles(&self) -> Styles {
|
||||||
let mut effective_styles = self.effective_styles.clone();
|
let mut effective_styles = self.effective_styles.clone();
|
||||||
if let Some(associated) = &self.associated_styles {
|
if let Some(associated) = &self.associated_styles {
|
||||||
effective_styles.inherit_from(associated.get());
|
let mut merged = associated.get();
|
||||||
|
merged.inherit_from(effective_styles);
|
||||||
|
effective_styles = merged;
|
||||||
|
} else {
|
||||||
|
effective_styles = effective_styles.into_inherited();
|
||||||
}
|
}
|
||||||
effective_styles
|
effective_styles
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue