Add the Pivot Assist widget

Part of #525
This commit is contained in:
Keavon Chambers
2022-08-29 00:08:01 -07:00
parent 440a9a6dd6
commit 1e723b8c86
10 changed files with 199 additions and 4 deletions
@@ -125,6 +125,12 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
let callback_message = (optional_input.on_update.callback)(optional_input);
responses.push_back(callback_message);
}
Widget::PivotAssist(pivot_assist) => {
let update_value = value.as_str().expect("RadioInput update was not of type: u64");
pivot_assist.position = update_value.into();
let callback_message = (pivot_assist.on_update.callback)(pivot_assist);
responses.push_back(callback_message);
}
Widget::PopoverButton(_) => {}
Widget::RadioInput(radio_input) => {
let update_value = value.as_u64().expect("RadioInput update was not of type: u64");
@@ -1,3 +1,4 @@
use super::widgets::assist_widgets::*;
use super::widgets::button_widgets::*;
use super::widgets::input_widgets::*;
use super::widgets::label_widgets::*;
@@ -278,6 +279,7 @@ pub enum Widget {
InvisibleStandinInput(InvisibleStandinInput),
NumberInput(NumberInput),
OptionalInput(OptionalInput),
PivotAssist(PivotAssist),
PopoverButton(PopoverButton),
RadioInput(RadioInput),
Separator(Separator),
@@ -0,0 +1,48 @@
use derivative::*;
use serde::{Deserialize, Serialize};
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
#[derive(Clone, Default, Derivative, Serialize, Deserialize)]
#[derivative(Debug, PartialEq)]
pub struct PivotAssist {
pub position: PivotPosition,
// Callbacks
#[serde(skip)]
#[derivative(Debug = "ignore", PartialEq = "ignore")]
pub on_update: WidgetCallback<PivotAssist>,
}
#[derive(Clone, Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
pub enum PivotPosition {
#[default]
None,
TopLeft,
TopCenter,
TopRight,
CenterLeft,
Center,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight,
}
impl From<&str> for PivotPosition {
fn from(input: &str) -> Self {
match input {
"None" => PivotPosition::None,
"TopLeft" => PivotPosition::TopLeft,
"TopCenter" => PivotPosition::TopCenter,
"TopRight" => PivotPosition::TopRight,
"CenterLeft" => PivotPosition::CenterLeft,
"Center" => PivotPosition::Center,
"CenterRight" => PivotPosition::CenterRight,
"BottomLeft" => PivotPosition::BottomLeft,
"BottomCenter" => PivotPosition::BottomCenter,
"BottomRight" => PivotPosition::BottomRight,
_ => panic!("Failed parsing unrecognized PivotPosition enum value '{}'", input),
}
}
}
@@ -1,3 +1,4 @@
pub mod assist_widgets;
pub mod button_widgets;
pub mod input_widgets;
pub mod label_widgets;