Add a hotkey to select a random primary color (#622)

* Add shortcut to select a random primary color (#549)

* Rename random primary color message and reduce the number of calls to
generate_uuid

* Add documentation for SelectRandomPrimaryColor message

* Set the alpha value to 255 instead of a random value #622

Co-authored-by: Florent Collin <florentcollin23@gmail.com>
This commit is contained in:
FlorentCollin 2022-05-06 08:50:50 +02:00 committed by Keavon Chambers
parent 07736a9fca
commit c65c33243b
3 changed files with 17 additions and 2 deletions

View File

@ -142,7 +142,8 @@ impl Default for Mapping {
// Colors
entry! {action=ToolMessage::ResetColors, key_down=KeyX, modifiers=[KeyShift, KeyControl]},
entry! {action=ToolMessage::SwapColors, key_down=KeyX, modifiers=[KeyShift]},
// Editor actions
entry! {action=ToolMessage::SelectRandomPrimaryColor, key_down=KeyC, modifiers=[KeyAlt]},
// Editor Actions
entry! {action=FrontendMessage::TriggerFileUpload, key_down=KeyO, modifiers=[KeyControl]},
// Document actions
entry! {action=DocumentMessage::Redo, key_down=KeyZ, modifiers=[KeyControl, KeyShift]},

View File

@ -87,6 +87,7 @@ pub enum ToolMessage {
SelectPrimaryColor {
color: Color,
},
SelectRandomPrimaryColor,
SelectSecondaryColor {
color: Color,
},

View File

@ -103,6 +103,19 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessorMes
update_working_colors(&self.tool_state.document_tool_data, responses);
}
SelectRandomPrimaryColor => {
// Select a random primary color (rgba) based on an UUID
let document_data = &mut self.tool_state.document_tool_data;
let random_number = generate_uuid();
let r = (random_number >> 16) as u8;
let g = (random_number >> 8) as u8;
let b = random_number as u8;
let random_color = Color::from_rgba8(r, g, b, 255);
document_data.primary_color = random_color;
update_working_colors(document_data, responses);
}
SelectSecondaryColor { color } => {
let document_data = &mut self.tool_state.document_tool_data;
document_data.secondary_color = color;
@ -137,7 +150,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessorMes
}
fn actions(&self) -> ActionList {
let mut list = actions!(ToolMessageDiscriminant; ResetColors, SwapColors, ActivateTool);
let mut list = actions!(ToolMessageDiscriminant; SelectRandomPrimaryColor, ResetColors, SwapColors, ActivateTool);
list.extend(self.tool_state.tool_data.active_tool().actions());
list