scissor stack fixes, proper render & event transformations

This commit is contained in:
Aleksander
2025-09-29 22:04:16 +02:00
parent b73870236f
commit a1edc2f0b8
24 changed files with 361 additions and 218 deletions

View File

@@ -1,12 +1,11 @@
use crate::{
components::{button, Component},
components::{Component, button},
drawing::Color,
i18n::Translation,
layout::WidgetID,
parser::{
parse_children, process_component,
AttribPair, ParserContext, ParserFile, parse_children, process_component,
style::{parse_color_opt, parse_round, parse_style, parse_text_style},
AttribPair, ParserContext, ParserFile,
},
widget::util::WLength,
};
@@ -30,27 +29,27 @@ pub fn parse_component_button<'a, U1, U2>(
for pair in attribs {
let (key, value) = (pair.attrib.as_ref(), pair.value.as_ref());
match key.as_ref() {
match key {
"text" => {
translation = Some(Translation::from_raw_text(&value));
translation = Some(Translation::from_raw_text(value));
}
"translation" => {
translation = Some(Translation::from_translation_key(&value));
translation = Some(Translation::from_translation_key(value));
}
"round" => {
parse_round(&value, &mut round);
parse_round(value, &mut round);
}
"color" => {
parse_color_opt(&value, &mut color);
parse_color_opt(value, &mut color);
}
"border_color" => {
parse_color_opt(&value, &mut border_color);
parse_color_opt(value, &mut border_color);
}
"hover_color" => {
parse_color_opt(&value, &mut hover_color);
parse_color_opt(value, &mut hover_color);
}
"hover_border_color" => {
parse_color_opt(&value, &mut hover_border_color);
parse_color_opt(value, &mut hover_border_color);
}
_ => {}
}
@@ -58,7 +57,7 @@ pub fn parse_component_button<'a, U1, U2>(
let globals = ctx.layout.state.globals.clone();
let (new_id, component) = button::construct(
let (widget, component) = button::construct(
&mut globals.get(),
ctx.layout,
ctx.listeners,
@@ -75,8 +74,8 @@ pub fn parse_component_button<'a, U1, U2>(
},
)?;
process_component(ctx, Component(component), new_id, attribs);
parse_children(file, ctx, node, new_id)?;
process_component(ctx, Component(component), widget.id, attribs);
parse_children(file, ctx, node, widget.id)?;
Ok(new_id)
Ok(widget.id)
}

View File

@@ -1,11 +1,11 @@
use crate::{
components::{checkbox, Component},
components::{Component, checkbox},
i18n::Translation,
layout::WidgetID,
parser::{parse_check_f32, parse_check_i32, process_component, style::parse_style, AttribPair, ParserContext},
parser::{AttribPair, ParserContext, parse_check_f32, parse_check_i32, process_component, style::parse_style},
};
pub fn parse_component_checkbox<'a, U1, U2>(
pub fn parse_component_checkbox<U1, U2>(
ctx: &mut ParserContext<U1, U2>,
parent_id: WidgetID,
attribs: &[AttribPair],
@@ -35,7 +35,7 @@ pub fn parse_component_checkbox<'a, U1, U2>(
}
}
let (new_id, component) = checkbox::construct(
let (widget, component) = checkbox::construct(
ctx.layout,
ctx.listeners,
parent_id,
@@ -47,7 +47,7 @@ pub fn parse_component_checkbox<'a, U1, U2>(
},
)?;
process_component(ctx, Component(component), new_id, attribs);
process_component(ctx, Component(component), widget.id, attribs);
Ok(new_id)
Ok(widget.id)
}

View File

@@ -1,10 +1,10 @@
use crate::{
components::{slider, Component},
components::{Component, slider},
layout::WidgetID,
parser::{parse_check_f32, process_component, style::parse_style, AttribPair, ParserContext},
parser::{AttribPair, ParserContext, parse_check_f32, process_component, style::parse_style},
};
pub fn parse_component_slider<'a, U1, U2>(
pub fn parse_component_slider<U1, U2>(
ctx: &mut ParserContext<U1, U2>,
parent_id: WidgetID,
attribs: &[AttribPair],
@@ -31,7 +31,7 @@ pub fn parse_component_slider<'a, U1, U2>(
}
}
let (new_id, component) = slider::construct(
let (widget, component) = slider::construct(
ctx.layout,
ctx.listeners,
parent_id,
@@ -45,7 +45,7 @@ pub fn parse_component_slider<'a, U1, U2>(
},
)?;
process_component(ctx, Component(component), new_id, attribs);
process_component(ctx, Component(component), widget.id, attribs);
Ok(new_id)
Ok(widget.id)
}

View File

@@ -530,9 +530,9 @@ fn parse_widget_other_internal<U1, U2>(
Ok(())
}
fn parse_widget_other<'a, U1, U2>(
fn parse_widget_other<U1, U2>(
xml_tag_name: &str,
file: &'a ParserFile,
file: &ParserFile,
ctx: &mut ParserContext<U1, U2>,
parent_id: WidgetID,
attribs: &[AttribPair],
@@ -548,7 +548,7 @@ fn parse_widget_other<'a, U1, U2>(
parse_widget_other_internal(&template, template_parameters, file, ctx, parent_id)
}
fn parse_tag_include<'a, U1, U2>(
fn parse_tag_include<U1, U2>(
file: &ParserFile,
ctx: &mut ParserContext<U1, U2>,
parent_id: WidgetID,
@@ -641,7 +641,7 @@ fn process_attrib<'a, U1, U2>(
let name = &value[1..];
match ctx.get_var(name) {
Some(name) => AttribPair::new(key, name.clone()),
Some(name) => AttribPair::new(key, name),
None => AttribPair::new(key, "undefined"),
}
} else {
@@ -655,7 +655,7 @@ fn raw_attribs<'a>(node: &'a roxmltree::Node<'a, 'a>) -> Vec<AttribPair> {
let (key, value) = (attrib.name(), attrib.value());
res.push(AttribPair::new(key, value));
}
return res;
res
}
fn process_attribs<'a, U1, U2>(
@@ -761,7 +761,7 @@ fn parse_tag_macro<U1, U2>(file: &ParserFile, ctx: &mut ParserContext<U1, U2>, n
ctx.insert_macro_attrib(name, MacroAttribs { attribs: macro_attribs });
}
fn process_component<'a, U1, U2>(
fn process_component<U1, U2>(
ctx: &mut ParserContext<U1, U2>,
component: Component,
widget_id: WidgetID,
@@ -782,7 +782,7 @@ fn process_component<'a, U1, U2>(
ctx.insert_component(widget_id, component, component_id);
}
fn parse_widget_universal<'a, U1, U2>(ctx: &mut ParserContext<U1, U2>, widget_id: WidgetID, attribs: &[AttribPair]) {
fn parse_widget_universal<U1, U2>(ctx: &mut ParserContext<U1, U2>, widget_id: WidgetID, attribs: &[AttribPair]) {
for pair in attribs {
#[allow(clippy::single_match)]
match pair.attrib.as_ref() {
@@ -957,7 +957,7 @@ impl CustomAttribsInfo<'_> {
CustomAttribsInfoOwned {
parent_id: self.parent_id,
widget_id: self.widget_id,
pairs: self.pairs.iter().cloned().collect(),
pairs: self.pairs.to_vec(),
}
}
}

View File

@@ -6,8 +6,8 @@ use taffy::{
use crate::{
drawing,
parser::{
is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val, print_invalid_attrib,
print_invalid_value, AttribPair,
AttribPair, is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val,
print_invalid_attrib, print_invalid_value,
},
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
widget::util::WLength,
@@ -54,7 +54,7 @@ pub fn parse_text_style(attribs: &[AttribPair]) -> TextStyle {
style.color = Some(color);
}
}
"align" => match value.as_ref() {
"align" => match value {
"left" => style.align = Some(HorizontalAlign::Left),
"right" => style.align = Some(HorizontalAlign::Right),
"center" => style.align = Some(HorizontalAlign::Center),
@@ -64,7 +64,7 @@ pub fn parse_text_style(attribs: &[AttribPair]) -> TextStyle {
print_invalid_attrib(key, value);
}
},
"weight" => match value.as_ref() {
"weight" => match value {
"normal" => style.weight = Some(FontWeight::Normal),
"bold" => style.weight = Some(FontWeight::Bold),
_ => {
@@ -111,8 +111,8 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
for pair in attribs {
let (key, value) = (pair.attrib.as_ref(), pair.value.as_ref());
match key.as_ref() {
"display" => match value.as_ref() {
match key {
"display" => match value {
"flex" => style.display = Display::Flex,
"block" => style.display = Display::Block,
"grid" => style.display = Display::Grid,
@@ -176,7 +176,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
style.padding.bottom = dim;
}
}
"overflow" => match value.as_ref() {
"overflow" => match value {
"hidden" => {
style.overflow.x = Overflow::Hidden;
style.overflow.y = Overflow::Hidden;
@@ -197,7 +197,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"overflow_x" => match value.as_ref() {
"overflow_x" => match value {
"hidden" => style.overflow.x = Overflow::Hidden,
"visible" => style.overflow.x = Overflow::Visible,
"clip" => style.overflow.x = Overflow::Clip,
@@ -206,7 +206,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"overflow_y" => match value.as_ref() {
"overflow_y" => match value {
"hidden" => style.overflow.y = Overflow::Hidden,
"visible" => style.overflow.y = Overflow::Visible,
"clip" => style.overflow.y = Overflow::Clip,
@@ -265,21 +265,21 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
style.flex_shrink = val;
}
}
"position" => match value.as_ref() {
"position" => match value {
"absolute" => style.position = taffy::Position::Absolute,
"relative" => style.position = taffy::Position::Relative,
_ => {
print_invalid_attrib(key, value);
}
},
"box_sizing" => match value.as_ref() {
"box_sizing" => match value {
"border_box" => style.box_sizing = BoxSizing::BorderBox,
"content_box" => style.box_sizing = BoxSizing::ContentBox,
_ => {
print_invalid_attrib(key, value);
}
},
"align_self" => match value.as_ref() {
"align_self" => match value {
"baseline" => style.align_self = Some(AlignSelf::Baseline),
"center" => style.align_self = Some(AlignSelf::Center),
"end" => style.align_self = Some(AlignSelf::End),
@@ -291,7 +291,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"justify_self" => match value.as_ref() {
"justify_self" => match value {
"center" => style.justify_self = Some(JustifySelf::Center),
"end" => style.justify_self = Some(JustifySelf::End),
"flex_end" => style.justify_self = Some(JustifySelf::FlexEnd),
@@ -302,7 +302,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"align_items" => match value.as_ref() {
"align_items" => match value {
"baseline" => style.align_items = Some(AlignItems::Baseline),
"center" => style.align_items = Some(AlignItems::Center),
"end" => style.align_items = Some(AlignItems::End),
@@ -314,7 +314,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"align_content" => match value.as_ref() {
"align_content" => match value {
"center" => style.align_content = Some(AlignContent::Center),
"end" => style.align_content = Some(AlignContent::End),
"flex_end" => style.align_content = Some(AlignContent::FlexEnd),
@@ -328,7 +328,7 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"justify_content" => match value.as_ref() {
"justify_content" => match value {
"center" => style.justify_content = Some(JustifyContent::Center),
"end" => style.justify_content = Some(JustifyContent::End),
"flex_end" => style.justify_content = Some(JustifyContent::FlexEnd),
@@ -342,13 +342,13 @@ pub fn parse_style(attribs: &[AttribPair]) -> taffy::Style {
print_invalid_attrib(key, value);
}
},
"flex_wrap" => match value.as_ref() {
"flex_wrap" => match value {
"wrap" => style.flex_wrap = FlexWrap::Wrap,
"no_wrap" => style.flex_wrap = FlexWrap::NoWrap,
"wrap_reverse" => style.flex_wrap = FlexWrap::WrapReverse,
_ => {}
},
"flex_direction" => match value.as_ref() {
"flex_direction" => match value {
"column_reverse" => style.flex_direction = FlexDirection::ColumnReverse,
"column" => style.flex_direction = FlexDirection::Column,
"row_reverse" => style.flex_direction = FlexDirection::RowReverse,

View File

@@ -1,6 +1,6 @@
use crate::{
layout::WidgetID,
parser::{parse_children, parse_widget_universal, style::parse_style, AttribPair, ParserContext, ParserFile},
parser::{AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, style::parse_style},
widget::div::WidgetDiv,
};
@@ -13,10 +13,10 @@ pub fn parse_widget_div<'a, U1, U2>(
) -> anyhow::Result<WidgetID> {
let style = parse_style(attribs);
let (new_id, _) = ctx.layout.add_child(parent_id, WidgetDiv::create(), style)?;
let (widget, _) = ctx.layout.add_child(parent_id, WidgetDiv::create(), style)?;
parse_widget_universal(ctx, new_id, attribs);
parse_children(file, ctx, node, new_id)?;
parse_widget_universal(ctx, widget.id, attribs);
parse_children(file, ctx, node, widget.id)?;
Ok(new_id)
Ok(widget.id)
}

View File

@@ -2,9 +2,8 @@ use crate::{
i18n::Translation,
layout::WidgetID,
parser::{
parse_children, parse_widget_universal,
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal,
style::{parse_style, parse_text_style},
AttribPair, ParserContext, ParserFile,
},
widget::label::{WidgetLabel, WidgetLabelParams},
};
@@ -40,12 +39,12 @@ pub fn parse_widget_label<'a, U1, U2>(
let globals = ctx.layout.state.globals.clone();
let (new_id, _) = ctx
let (widget, _) = ctx
.layout
.add_child(parent_id, WidgetLabel::create(&mut globals.get(), params), style)?;
parse_widget_universal(ctx, new_id, attribs);
parse_children(file, ctx, node, new_id)?;
parse_widget_universal(ctx, widget.id, attribs);
parse_children(file, ctx, node, widget.id)?;
Ok(new_id)
Ok(widget.id)
}

View File

@@ -2,9 +2,8 @@ use crate::{
drawing::GradientMode,
layout::WidgetID,
parser::{
parse_children, parse_widget_universal, print_invalid_attrib,
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, print_invalid_attrib,
style::{parse_color, parse_round, parse_style},
AttribPair, ParserContext, ParserFile,
},
widget::rectangle::{WidgetRectangle, WidgetRectangleParams},
};
@@ -17,7 +16,7 @@ pub fn parse_widget_rectangle<'a, U1, U2>(
attribs: &[AttribPair],
) -> anyhow::Result<WidgetID> {
let mut params = WidgetRectangleParams::default();
let style = parse_style(&attribs);
let style = parse_style(attribs);
for pair in attribs {
let (key, value) = (pair.attrib.as_ref(), pair.value.as_ref());
@@ -56,12 +55,12 @@ pub fn parse_widget_rectangle<'a, U1, U2>(
}
}
let (new_id, _) = ctx
let (widget, _) = ctx
.layout
.add_child(parent_id, WidgetRectangle::create(params), style)?;
parse_widget_universal(ctx, new_id, attribs);
parse_children(file, ctx, node, new_id)?;
parse_widget_universal(ctx, widget.id, attribs);
parse_children(file, ctx, node, widget.id)?;
Ok(new_id)
Ok(widget.id)
}

View File

@@ -1,6 +1,6 @@
use crate::{
layout::WidgetID,
parser::{parse_children, parse_widget_universal, style::parse_style, AttribPair, ParserContext, ParserFile},
parser::{AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, style::parse_style},
renderer_vk::text::custom_glyph::{CustomGlyphContent, CustomGlyphData},
widget::sprite::{WidgetSprite, WidgetSpriteParams},
};
@@ -15,7 +15,7 @@ pub fn parse_widget_sprite<'a, U1, U2>(
attribs: &[AttribPair],
) -> anyhow::Result<WidgetID> {
let mut params = WidgetSpriteParams::default();
let style = parse_style(&attribs);
let style = parse_style(attribs);
let mut glyph = None;
for pair in attribs {
@@ -54,10 +54,10 @@ pub fn parse_widget_sprite<'a, U1, U2>(
log::warn!("No source for sprite node!");
}
let (new_id, _) = ctx.layout.add_child(parent_id, WidgetSprite::create(params), style)?;
let (widget, _) = ctx.layout.add_child(parent_id, WidgetSprite::create(params), style)?;
parse_widget_universal(ctx, new_id, attribs);
parse_children(file, ctx, node, new_id)?;
parse_widget_universal(ctx, widget.id, attribs);
parse_children(file, ctx, node, widget.id)?;
Ok(new_id)
Ok(widget.id)
}