Clean up MenuList types and fix many Vue and Clippy warnings

Also remove hard-coded-in-Vue Graphite logo in the menu bar in favor of a Rust definition.
This commit is contained in:
Keavon Chambers
2022-08-25 14:41:16 -07:00
parent 1a90a4db86
commit 3a84de32ac
27 changed files with 361 additions and 374 deletions
@@ -30,18 +30,31 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
self.send_layout(layout_target, responses, &action_input_mapping);
}
UpdateLayout { layout_target, widget_id, value } => {
let layout = &mut self.layouts[layout_target as usize];
let widget_holder = layout.iter_mut().find(|widget| widget.widget_id == widget_id);
if widget_holder.is_none() {
log::trace!(
"Could not find widget_id:{} on layout_target:{:?}. This could be an indication of a problem or just a user clicking off of an actively edited layer",
// Look up the layout
let layout = if let Some(layout) = self.layouts.get_mut(layout_target as usize) {
layout
} else {
log::warn!(
"UpdateLayout was called referencing an invalid layout. `widget_id: {}`, `layout_target: {:?}`",
widget_id,
layout_target
);
return;
}
};
let widget_holder = if let Some(widget_holder) = layout.iter_mut().find(|widget| widget.widget_id == widget_id) {
widget_holder
} else {
log::warn!(
"UpdateLayout was called referencing an invalid widget ID, although the layout target was valid. `widget_id: {}`, `layout_target: {:?}`",
widget_id,
layout_target
);
return;
};
#[remain::sorted]
match &mut widget_holder.unwrap().widget {
match &mut widget_holder.widget {
Widget::CheckboxInput(checkbox_input) => {
let update_value = value.as_bool().expect("CheckboxInput update was not of type: bool");
checkbox_input.checked = update_value;
@@ -9,9 +9,9 @@ use serde::{Deserialize, Serialize};
use super::input_widgets::InvisibleStandinInput;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct MenuEntryGroups(pub Vec<Vec<MenuEntry>>);
pub struct MenuBarEntryChildren(pub Vec<Vec<MenuBarEntry>>);
impl MenuEntryGroups {
impl MenuBarEntryChildren {
pub fn empty() -> Self {
Self(Vec::new())
}
@@ -31,15 +31,23 @@ impl MenuEntryGroups {
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MenuEntry {
pub struct MenuBarEntry {
pub label: String,
pub icon: Option<String>,
pub children: MenuEntryGroups,
pub action: WidgetHolder,
pub shortcut: Option<ActionKeys>,
pub action: WidgetHolder,
pub children: MenuBarEntryChildren,
}
impl MenuEntry {
impl MenuBarEntry {
pub fn new_root(label: String, children: MenuBarEntryChildren) -> Self {
Self {
label,
children,
..Default::default()
}
}
pub fn create_action(callback: impl Fn(&()) -> Message + 'static) -> WidgetHolder {
WidgetHolder::new(Widget::InvisibleStandinInput(InvisibleStandinInput {
on_update: WidgetCallback::new(callback),
@@ -47,54 +55,46 @@ impl MenuEntry {
}
pub fn no_action() -> WidgetHolder {
MenuEntry::create_action(|_| Message::NoOp)
MenuBarEntry::create_action(|_| Message::NoOp)
}
}
impl Default for MenuEntry {
impl Default for MenuBarEntry {
fn default() -> Self {
Self {
action: MenuEntry::create_action(|_| DialogMessage::RequestComingSoonDialog { issue: None }.into()),
label: "".into(),
icon: None,
children: MenuEntryGroups::empty(),
shortcut: None,
action: MenuBarEntry::no_action(),
children: MenuBarEntryChildren::empty(),
}
}
}
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct MenuColumn {
pub label: String,
pub children: MenuEntryGroups,
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct MenuLayout {
pub layout: Vec<MenuColumn>,
pub layout: Vec<MenuBarEntry>,
}
impl MenuLayout {
pub fn new(layout: Vec<MenuColumn>) -> Self {
pub fn new(layout: Vec<MenuBarEntry>) -> Self {
Self { layout }
}
pub fn iter(&self) -> impl Iterator<Item = &WidgetHolder> + '_ {
MenuLayoutIter {
stack: self.layout.iter().flat_map(|column| column.children.0.iter()).flat_map(|group| group.iter()).collect(),
}
MenuLayoutIter { stack: self.layout.iter().collect() }
}
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut WidgetHolder> + '_ {
MenuLayoutIterMut {
stack: self.layout.iter_mut().flat_map(|column| column.children.0.iter_mut()).flat_map(|group| group.iter_mut()).collect(),
stack: self.layout.iter_mut().collect(),
}
}
}
#[derive(Debug, Default)]
pub struct MenuLayoutIter<'a> {
pub stack: Vec<&'a MenuEntry>,
pub stack: Vec<&'a MenuBarEntry>,
}
impl<'a> Iterator for MenuLayoutIter<'a> {
@@ -114,7 +114,7 @@ impl<'a> Iterator for MenuLayoutIter<'a> {
}
pub struct MenuLayoutIterMut<'a> {
pub stack: Vec<&'a mut MenuEntry>,
pub stack: Vec<&'a mut MenuBarEntry>,
}
impl<'a> Iterator for MenuLayoutIterMut<'a> {