wgui: new_pass attrib, refactoring
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
# Universal widget attributes
|
# Universal widget attributes
|
||||||
|
|
||||||
### They can be used in any widget/component
|
_They can be used in any widget/component._
|
||||||
|
|
||||||
`display`: "flex" | "block" | "grid"
|
`display`: "flex" | "block" | "grid"
|
||||||
|
|
||||||
@@ -60,6 +60,16 @@
|
|||||||
|
|
||||||
`width`, `height`: **float** | **percent**
|
`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
|
# Widgets
|
||||||
|
|
||||||
## div widget
|
## div widget
|
||||||
|
|||||||
@@ -248,6 +248,10 @@ fn draw_widget(
|
|||||||
|
|
||||||
let mut widget_state = widget.state();
|
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) {
|
let (scroll_shift, wants_redraw, info) = match widget::get_scrollbar_info(l) {
|
||||||
Some(info) => {
|
Some(info) => {
|
||||||
let (scrolling, wants_redraw) = widget_state.get_scroll_shift_smooth(&info, l, params.timestep_alpha);
|
let (scrolling, wants_redraw) = widget_state.get_scroll_shift_smooth(&info, l, params.timestep_alpha);
|
||||||
|
|||||||
@@ -774,18 +774,24 @@ fn process_component(ctx: &mut ParserContext, component: Component, widget_id: W
|
|||||||
ctx.insert_component(widget_id, component, component_id);
|
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 {
|
for pair in attribs {
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
match pair.attrib.as_ref() {
|
match pair.attrib.as_ref() {
|
||||||
"id" => {
|
"id" => {
|
||||||
// Attach a specific widget to name-ID map (just like getElementById)
|
// 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" => {
|
"interactable" => {
|
||||||
if matches!(&pair.value.parse::<i32>(), Ok(0)) {
|
if let Some(num) = parse_i32(&pair.value) {
|
||||||
log::info!("setting {widget_id:?} to noninteractable.");
|
widget.widget.state().interactable = num != 0;
|
||||||
ctx.layout.state.widgets.get(widget_id).unwrap().state().interactable = false;
|
|
||||||
} else {
|
} else {
|
||||||
print_invalid_attrib(&pair.attrib, &pair.value);
|
print_invalid_attrib(&pair.attrib, &pair.value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
layout::WidgetID,
|
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,
|
widget::div::WidgetDiv,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ pub fn parse_widget_div<'a>(
|
|||||||
|
|
||||||
let (widget, _) = ctx.layout.add_child(parent_id, WidgetDiv::create(), style)?;
|
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)?;
|
parse_children(file, ctx, node, widget.id)?;
|
||||||
|
|
||||||
Ok(widget.id)
|
Ok(widget.id)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub fn parse_widget_label<'a>(
|
|||||||
.layout
|
.layout
|
||||||
.add_child(parent_id, WidgetLabel::create(&mut globals.get(), params), style)?;
|
.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)?;
|
parse_children(file, ctx, node, widget.id)?;
|
||||||
|
|
||||||
Ok(widget.id)
|
Ok(widget.id)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ pub fn parse_widget_rectangle<'a>(
|
|||||||
.layout
|
.layout
|
||||||
.add_child(parent_id, WidgetRectangle::create(params), style)?;
|
.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)?;
|
parse_children(file, ctx, node, widget.id)?;
|
||||||
|
|
||||||
Ok(widget.id)
|
Ok(widget.id)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ pub fn parse_widget_sprite<'a>(
|
|||||||
|
|
||||||
let (widget, _) = 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, widget.id, attribs);
|
parse_widget_universal(ctx, &widget, attribs);
|
||||||
parse_children(file, ctx, node, widget.id)?;
|
parse_children(file, ctx, node, widget.id)?;
|
||||||
|
|
||||||
Ok(widget.id)
|
Ok(widget.id)
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ pub struct WidgetState {
|
|||||||
pub obj: Box<dyn WidgetObj>,
|
pub obj: Box<dyn WidgetObj>,
|
||||||
pub event_listeners: EventListenerCollection,
|
pub event_listeners: EventListenerCollection,
|
||||||
pub interactable: bool,
|
pub interactable: bool,
|
||||||
|
pub new_pass: bool, // force a new render pass
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WidgetState {
|
impl WidgetState {
|
||||||
@@ -104,6 +105,7 @@ impl WidgetState {
|
|||||||
obj,
|
obj,
|
||||||
event_listeners: EventListenerCollection::default(),
|
event_listeners: EventListenerCollection::default(),
|
||||||
interactable: true,
|
interactable: true,
|
||||||
|
new_pass: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user