pass template_params to context_menu
This commit is contained in:
@@ -18,7 +18,6 @@ use vulkano::{
|
|||||||
sync::GpuFuture,
|
sync::GpuFuture,
|
||||||
};
|
};
|
||||||
use wgui::{
|
use wgui::{
|
||||||
assets::AssetProvider,
|
|
||||||
event::{MouseButtonIndex, MouseDownEvent, MouseMotionEvent, MouseUpEvent, MouseWheelEvent},
|
event::{MouseButtonIndex, MouseDownEvent, MouseMotionEvent, MouseUpEvent, MouseWheelEvent},
|
||||||
gfx::{WGfx, cmd::WGfxClearMode},
|
gfx::{WGfx, cmd::WGfxClearMode},
|
||||||
renderer_vk::{self},
|
renderer_vk::{self},
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ impl TestbedGeneric {
|
|||||||
log::info!("custom attribs {:?}", custom_attribs.pairs);
|
log::info!("custom attribs {:?}", custom_attribs.pairs);
|
||||||
})),
|
})),
|
||||||
"my_context_menu",
|
"my_context_menu",
|
||||||
&mut self.layout,
|
Default::default(),
|
||||||
&mut data.context_menu,
|
&mut data.context_menu,
|
||||||
position,
|
position,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ impl ParserState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
on_custom_attribs: Option<OnCustomAttribsFunc>,
|
on_custom_attribs: Option<OnCustomAttribsFunc>,
|
||||||
template_name: &str,
|
template_name: &str,
|
||||||
layout: &mut Layout,
|
template_params: HashMap<Rc<str>, Rc<str>>,
|
||||||
context_menu: &mut context_menu::ContextMenu,
|
context_menu: &mut context_menu::ContextMenu,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
@@ -292,6 +292,7 @@ impl ParserState {
|
|||||||
|
|
||||||
for attrib in child.attributes() {
|
for attrib in child.attributes() {
|
||||||
let (key, value) = (attrib.name(), attrib.value());
|
let (key, value) = (attrib.name(), attrib.value());
|
||||||
|
|
||||||
match key {
|
match key {
|
||||||
"text" => title = Some(Translation::from_raw_text(value)),
|
"text" => title = Some(Translation::from_raw_text(value)),
|
||||||
"translation" => title = Some(Translation::from_translation_key(value)),
|
"translation" => title = Some(Translation::from_translation_key(value)),
|
||||||
@@ -300,7 +301,7 @@ impl ParserState {
|
|||||||
if !other.starts_with('_') {
|
if !other.starts_with('_') {
|
||||||
anyhow::bail!("unexpected \"{other}\" attribute");
|
anyhow::bail!("unexpected \"{other}\" attribute");
|
||||||
}
|
}
|
||||||
attribs.push(AttribPair::new(key, value));
|
attribs.push(AttribPair::new(key, replace_vars(value, &template_params)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,7 +320,7 @@ impl ParserState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context_menu.open(context_menu::OpenParams {
|
context_menu.open(context_menu::OpenParams {
|
||||||
data: context_menu::Blueprint { cells },
|
cells,
|
||||||
on_custom_attribs,
|
on_custom_attribs,
|
||||||
position,
|
position,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
use std::{collections::HashMap, rc::Rc};
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
rc::Rc,
|
||||||
|
};
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assets::AssetPath,
|
assets::AssetPath,
|
||||||
components::{ComponentTrait, button::ComponentButton},
|
components::{button::ComponentButton, ComponentTrait},
|
||||||
globals::WguiGlobals,
|
globals::WguiGlobals,
|
||||||
i18n::Translation,
|
i18n::Translation,
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
@@ -19,13 +22,9 @@ pub struct Cell {
|
|||||||
pub attribs: Vec<parser::AttribPair>,
|
pub attribs: Vec<parser::AttribPair>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Blueprint {
|
|
||||||
pub cells: Vec<Cell>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct OpenParams {
|
pub struct OpenParams {
|
||||||
pub position: Vec2,
|
pub position: Vec2,
|
||||||
pub data: Blueprint,
|
pub cells: Vec<Cell>,
|
||||||
pub on_custom_attribs: Option<parser::OnCustomAttribsFunc>,
|
pub on_custom_attribs: Option<parser::OnCustomAttribsFunc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ impl ContextMenu {
|
|||||||
|
|
||||||
let id_buttons = state.get_widget_id("buttons")?;
|
let id_buttons = state.get_widget_id("buttons")?;
|
||||||
|
|
||||||
for (idx, cell) in params.data.cells.iter().enumerate() {
|
for (idx, cell) in params.cells.iter().enumerate() {
|
||||||
let mut par = HashMap::new();
|
let mut par = HashMap::new();
|
||||||
par.insert(Rc::from("text"), cell.title.generate(&mut globals.i18n()));
|
par.insert(Rc::from("text"), cell.title.generate(&mut globals.i18n()));
|
||||||
let data_cell = state.parse_template(&doc_params(&globals), "Cell", layout, id_buttons, par)?;
|
let data_cell = state.parse_template(&doc_params(&globals), "Cell", layout, id_buttons, par)?;
|
||||||
@@ -103,7 +102,7 @@ impl ContextMenu {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx < params.data.cells.len() - 1 {
|
if idx < params.cells.len() - 1 {
|
||||||
state.parse_template(
|
state.parse_template(
|
||||||
&doc_params(&globals),
|
&doc_params(&globals),
|
||||||
"Separator",
|
"Separator",
|
||||||
|
|||||||
Reference in New Issue
Block a user