diff --git a/wgui/doc/widgets.md b/wgui/doc/widgets.md index d6f24a92..b63d175c 100644 --- a/wgui/doc/widgets.md +++ b/wgui/doc/widgets.md @@ -22,7 +22,7 @@ # Universal widget attributes -### They can be used in any widget/component +_They can be used in any widget/component._ `display`: "flex" | "block" | "grid" @@ -60,6 +60,16 @@ `width`, `height`: **float** | **percent** +### Advanced attributes + +`interactable`: "1" | "0" + +_Set to 0 if you want to exclude this widget from altering the event state_ + +`new_pass`: "1" | "0" + +_Set to 1 if you want to render overlapping pop-ups to properly render your widgets in order. Wgui renders with as few Vulkan drawcalls as possible, so this is your responsibility._ + # Widgets ## div widget diff --git a/wgui/src/drawing.rs b/wgui/src/drawing.rs index d18f2ef1..0f32a467 100644 --- a/wgui/src/drawing.rs +++ b/wgui/src/drawing.rs @@ -248,6 +248,10 @@ fn draw_widget( let mut widget_state = widget.state(); + if widget_state.new_pass { + state.primitives.push(RenderPrimitive::NewPass); + } + let (scroll_shift, wants_redraw, info) = match widget::get_scrollbar_info(l) { Some(info) => { let (scrolling, wants_redraw) = widget_state.get_scroll_shift_smooth(&info, l, params.timestep_alpha); diff --git a/wgui/src/parser/mod.rs b/wgui/src/parser/mod.rs index bdc96df0..39548500 100644 --- a/wgui/src/parser/mod.rs +++ b/wgui/src/parser/mod.rs @@ -774,18 +774,24 @@ fn process_component(ctx: &mut ParserContext, component: Component, widget_id: W ctx.insert_component(widget_id, component, component_id); } -fn parse_widget_universal(ctx: &mut ParserContext, widget_id: WidgetID, attribs: &[AttribPair]) { +fn parse_widget_universal(ctx: &mut ParserContext, widget: &WidgetPair, attribs: &[AttribPair]) { for pair in attribs { #[allow(clippy::single_match)] match pair.attrib.as_ref() { "id" => { // Attach a specific widget to name-ID map (just like getElementById) - ctx.insert_id(&pair.value, widget_id); + ctx.insert_id(&pair.value, widget.id); + } + "new_pass" => { + if let Some(num) = parse_i32(&pair.value) { + widget.widget.state().new_pass = num != 0; + } else { + print_invalid_attrib(&pair.attrib, &pair.value); + } } "interactable" => { - if matches!(&pair.value.parse::(), Ok(0)) { - log::info!("setting {widget_id:?} to noninteractable."); - ctx.layout.state.widgets.get(widget_id).unwrap().state().interactable = false; + if let Some(num) = parse_i32(&pair.value) { + widget.widget.state().interactable = num != 0; } else { print_invalid_attrib(&pair.attrib, &pair.value); } diff --git a/wgui/src/parser/widget_div.rs b/wgui/src/parser/widget_div.rs index bf5c94ac..5c5fdbb9 100644 --- a/wgui/src/parser/widget_div.rs +++ b/wgui/src/parser/widget_div.rs @@ -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, }; @@ -15,7 +15,7 @@ pub fn parse_widget_div<'a>( let (widget, _) = ctx.layout.add_child(parent_id, WidgetDiv::create(), style)?; - parse_widget_universal(ctx, widget.id, attribs); + parse_widget_universal(ctx, &widget, attribs); parse_children(file, ctx, node, widget.id)?; Ok(widget.id) diff --git a/wgui/src/parser/widget_label.rs b/wgui/src/parser/widget_label.rs index c84edced..2ef6ddc8 100644 --- a/wgui/src/parser/widget_label.rs +++ b/wgui/src/parser/widget_label.rs @@ -43,8 +43,8 @@ pub fn parse_widget_label<'a>( .layout .add_child(parent_id, WidgetLabel::create(&mut globals.get(), params), style)?; - parse_widget_universal(ctx, widget.id, attribs); + parse_widget_universal(ctx, &widget, attribs); parse_children(file, ctx, node, widget.id)?; Ok(widget.id) -} \ No newline at end of file +} diff --git a/wgui/src/parser/widget_rectangle.rs b/wgui/src/parser/widget_rectangle.rs index 22715d01..86ee2233 100644 --- a/wgui/src/parser/widget_rectangle.rs +++ b/wgui/src/parser/widget_rectangle.rs @@ -59,8 +59,8 @@ pub fn parse_widget_rectangle<'a>( .layout .add_child(parent_id, WidgetRectangle::create(params), style)?; - parse_widget_universal(ctx, widget.id, attribs); + parse_widget_universal(ctx, &widget, attribs); parse_children(file, ctx, node, widget.id)?; Ok(widget.id) -} \ No newline at end of file +} diff --git a/wgui/src/parser/widget_sprite.rs b/wgui/src/parser/widget_sprite.rs index 02b922bc..9181037c 100644 --- a/wgui/src/parser/widget_sprite.rs +++ b/wgui/src/parser/widget_sprite.rs @@ -59,8 +59,8 @@ pub fn parse_widget_sprite<'a>( let (widget, _) = ctx.layout.add_child(parent_id, WidgetSprite::create(params), style)?; - parse_widget_universal(ctx, widget.id, attribs); + parse_widget_universal(ctx, &widget, attribs); parse_children(file, ctx, node, widget.id)?; Ok(widget.id) -} \ No newline at end of file +} diff --git a/wgui/src/widget/mod.rs b/wgui/src/widget/mod.rs index 070348ac..54abea7f 100644 --- a/wgui/src/widget/mod.rs +++ b/wgui/src/widget/mod.rs @@ -81,6 +81,7 @@ pub struct WidgetState { pub obj: Box, pub event_listeners: EventListenerCollection, pub interactable: bool, + pub new_pass: bool, // force a new render pass } impl WidgetState { @@ -104,6 +105,7 @@ impl WidgetState { obj, event_listeners: EventListenerCollection::default(), interactable: true, + new_pass: false, } } }