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