sprite colors

This commit is contained in:
galister
2025-06-28 19:28:28 +09:00
parent d7c31d8699
commit 247c51c3b7
3 changed files with 19 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ use crate::{
widget::sprite::{SpriteBox, SpriteBoxParams},
};
use super::{parse_color_hex, print_invalid_attrib};
pub fn parse_widget_sprite<'a>(
file: &'a ParserFile,
ctx: &mut ParserContext,
@@ -34,6 +36,13 @@ pub fn parse_widget_sprite<'a>(
glyph = CustomGlyphContent::from_file(&value).ok();
}
}
"color" => {
if let Some(color) = parse_color_hex(&value) {
params.color = Some(color);
} else {
print_invalid_attrib(&key, &value);
}
}
_ => {}
}
}

View File

@@ -14,9 +14,9 @@ layout(set = 1, binding = 0) uniform sampler2D mask_atlas;
void main() {
if (in_content_type == 0u) {
out_color = texture(color_atlas, in_uv);
out_color = texture(color_atlas, in_uv) * in_color;
} else {
out_color.rgb = in_color.rgb;
out_color.a = in_color.a * texture(mask_atlas, in_uv).r;
}
}
}

View File

@@ -15,6 +15,7 @@ use super::{WidgetObj, WidgetState};
#[derive(Default)]
pub struct SpriteBoxParams {
pub glyph_data: Option<CustomGlyphData>,
pub color: Option<drawing::Color>,
}
#[derive(Default)]
@@ -39,7 +40,13 @@ impl WidgetObj for SpriteBox {
top: 0.0,
width: boundary.size.x,
height: boundary.size.y,
color: Some(cosmic_text::Color::rgb(255, 255, 255)),
color: Some(
self
.params
.color
.map(|c| c.into())
.unwrap_or(cosmic_text::Color::rgb(255, 255, 255)),
),
snap_to_physical_pixel: true,
};