wgui: new_pass attrib, refactoring
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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::<i32>(), 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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ pub struct WidgetState {
|
||||
pub obj: Box<dyn WidgetObj>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user