dropdown for capture_method + random tweaks
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use crate::{
|
||||
components::{Component, ComponentBase, ComponentTrait, RefreshData, checkbox::ComponentCheckbox},
|
||||
components::{checkbox::ComponentCheckbox, Component, ComponentBase, ComponentTrait, RefreshData},
|
||||
event::CallbackDataCommon,
|
||||
layout::WidgetPair,
|
||||
widget::{ConstructEssentials, div::WidgetDiv},
|
||||
widget::{div::WidgetDiv, ConstructEssentials},
|
||||
};
|
||||
|
||||
pub struct RadioValueChangeEvent {
|
||||
|
||||
@@ -9,11 +9,11 @@ use crate::{
|
||||
layout::{self, LayoutTask, LayoutTasks, WidgetID, WidgetPair},
|
||||
renderer_vk::text::{FontWeight, TextStyle},
|
||||
widget::{
|
||||
ConstructEssentials,
|
||||
div::WidgetDiv,
|
||||
label::{WidgetLabel, WidgetLabelParams},
|
||||
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
||||
util::WLength,
|
||||
ConstructEssentials,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -259,11 +259,11 @@ impl ParserState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn context_menu_create_blueprint(
|
||||
pub(crate) fn context_menu_parse_cells(
|
||||
&mut self,
|
||||
template_name: &str,
|
||||
template_params: &HashMap<Rc<str>, Rc<str>>,
|
||||
) -> anyhow::Result<context_menu::Blueprint> {
|
||||
) -> anyhow::Result<Vec<context_menu::Cell>> {
|
||||
let Some(template) = self.data.templates.get(template_name) else {
|
||||
anyhow::bail!("no template named \"{template_name}\" found");
|
||||
};
|
||||
@@ -283,6 +283,7 @@ impl ParserState {
|
||||
"" => {}
|
||||
"cell" => {
|
||||
let mut title: Option<Translation> = None;
|
||||
let mut tooltip: Option<Translation> = None;
|
||||
let mut action_name: Option<Rc<str>> = None;
|
||||
let mut attribs = Vec::<AttribPair>::new();
|
||||
|
||||
@@ -292,6 +293,8 @@ impl ParserState {
|
||||
match key {
|
||||
"text" => title = Some(Translation::from_raw_text(value)),
|
||||
"translation" => title = Some(Translation::from_translation_key(value)),
|
||||
"tooltip" => tooltip = Some(Translation::from_translation_key(value)),
|
||||
"tooltip_str" => tooltip = Some(Translation::from_raw_text(value)),
|
||||
"action" => action_name = Some(value.into()),
|
||||
other => {
|
||||
if !other.starts_with('_') {
|
||||
@@ -305,6 +308,7 @@ impl ParserState {
|
||||
let title = title.context("No text/translation provided")?;
|
||||
cells.push(context_menu::Cell {
|
||||
title,
|
||||
tooltip,
|
||||
action_name,
|
||||
attribs,
|
||||
});
|
||||
@@ -316,9 +320,7 @@ impl ParserState {
|
||||
}
|
||||
|
||||
Ok(
|
||||
context_menu::Blueprint {
|
||||
cells,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,19 +15,23 @@ use crate::{
|
||||
|
||||
pub struct Cell {
|
||||
pub title: Translation,
|
||||
pub tooltip: Option<Translation>,
|
||||
pub action_name: Option<Rc<str>>,
|
||||
pub attribs: Vec<parser::AttribPair>,
|
||||
}
|
||||
|
||||
pub(crate) struct Blueprint {
|
||||
pub cells: Vec<Cell>,
|
||||
pub enum Blueprint {
|
||||
Cells(Vec<Cell>),
|
||||
Template {
|
||||
template_name: Rc<str>,
|
||||
template_params: HashMap<Rc<str>, Rc<str>>,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct OpenParams {
|
||||
pub on_custom_attribs: Option<parser::OnCustomAttribsFunc>,
|
||||
pub template_name: Rc<str>,
|
||||
pub template_params: HashMap<Rc<str>, Rc<str>>,
|
||||
pub position: Vec2,
|
||||
pub blueprint: Blueprint,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -74,11 +78,17 @@ impl ContextMenu {
|
||||
|
||||
fn open_process(
|
||||
&mut self,
|
||||
params: &mut OpenParams,
|
||||
params: OpenParams,
|
||||
layout: &mut Layout,
|
||||
parser_state: &mut ParserState,
|
||||
) -> anyhow::Result<()> {
|
||||
let blueprint = parser_state.context_menu_create_blueprint(¶ms.template_name, ¶ms.template_params)?;
|
||||
let cells = match params.blueprint {
|
||||
Blueprint::Template {
|
||||
template_name,
|
||||
template_params,
|
||||
} => parser_state.context_menu_parse_cells(&template_name, &template_params)?,
|
||||
Blueprint::Cells(cells) => cells,
|
||||
};
|
||||
|
||||
let globals = layout.state.globals.clone();
|
||||
|
||||
@@ -100,9 +110,13 @@ impl ContextMenu {
|
||||
|
||||
let id_buttons = inner_parser.get_widget_id("buttons")?;
|
||||
|
||||
for (idx, cell) in blueprint.cells.iter().enumerate() {
|
||||
for (idx, cell) in cells.iter().enumerate() {
|
||||
let mut par = HashMap::new();
|
||||
par.insert(Rc::from("text"), cell.title.generate(&mut globals.i18n()));
|
||||
if let Some(tooltip) = cell.tooltip.as_ref() {
|
||||
par.insert(Rc::from("tooltip_str"), tooltip.generate(&mut globals.i18n()));
|
||||
}
|
||||
|
||||
let mut data_cell = inner_parser.parse_template(&doc_params, "Cell", layout, id_buttons, par)?;
|
||||
|
||||
let button = data_cell.fetch_component_as::<ComponentButton>("button")?;
|
||||
@@ -112,7 +126,7 @@ impl ContextMenu {
|
||||
.tasks
|
||||
.handle_button(&button, Task::ActionClicked(cell.action_name.clone()));
|
||||
|
||||
if let Some(c) = &mut params.on_custom_attribs {
|
||||
if let Some(c) = params.on_custom_attribs.as_ref() {
|
||||
(*c)(parser::CustomAttribsInfo {
|
||||
pairs: &cell.attribs,
|
||||
parent_id: id_buttons,
|
||||
@@ -121,7 +135,7 @@ impl ContextMenu {
|
||||
});
|
||||
}
|
||||
|
||||
if idx < blueprint.cells.len() - 1 {
|
||||
if idx < cells.len() - 1 {
|
||||
inner_parser.parse_template(&doc_params, "Separator", layout, id_buttons, Default::default())?;
|
||||
}
|
||||
}
|
||||
@@ -129,8 +143,8 @@ impl ContextMenu {
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, layout: &mut Layout, parser_state: &mut ParserState) -> anyhow::Result<TickResult> {
|
||||
if let Some(mut p) = self.pending_open.take() {
|
||||
self.open_process(&mut p, layout, parser_state)?;
|
||||
if let Some(p) = self.pending_open.take() {
|
||||
self.open_process(p, layout, parser_state)?;
|
||||
let _ = self.tasks.drain();
|
||||
return Ok(TickResult::Opened);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user