Skip to content

Commit c65c332

Browse files
FlorentCollinFlorent Collin
authored andcommitted
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 <[email protected]>
1 parent 07736a9 commit c65c332

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

editor/src/input/input_mapper.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ impl Default for Mapping {
142142
// Colors
143143
entry! {action=ToolMessage::ResetColors, key_down=KeyX, modifiers=[KeyShift, KeyControl]},
144144
entry! {action=ToolMessage::SwapColors, key_down=KeyX, modifiers=[KeyShift]},
145-
// Editor actions
145+
entry! {action=ToolMessage::SelectRandomPrimaryColor, key_down=KeyC, modifiers=[KeyAlt]},
146+
// Editor Actions
146147
entry! {action=FrontendMessage::TriggerFileUpload, key_down=KeyO, modifiers=[KeyControl]},
147148
// Document actions
148149
entry! {action=DocumentMessage::Redo, key_down=KeyZ, modifiers=[KeyControl, KeyShift]},

editor/src/viewport_tools/tool_message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub enum ToolMessage {
8787
SelectPrimaryColor {
8888
color: Color,
8989
},
90+
SelectRandomPrimaryColor,
9091
SelectSecondaryColor {
9192
color: Color,
9293
},

editor/src/viewport_tools/tool_message_handler.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessorMes
103103

104104
update_working_colors(&self.tool_state.document_tool_data, responses);
105105
}
106+
SelectRandomPrimaryColor => {
107+
// Select a random primary color (rgba) based on an UUID
108+
let document_data = &mut self.tool_state.document_tool_data;
109+
110+
let random_number = generate_uuid();
111+
let r = (random_number >> 16) as u8;
112+
let g = (random_number >> 8) as u8;
113+
let b = random_number as u8;
114+
let random_color = Color::from_rgba8(r, g, b, 255);
115+
document_data.primary_color = random_color;
116+
117+
update_working_colors(document_data, responses);
118+
}
106119
SelectSecondaryColor { color } => {
107120
let document_data = &mut self.tool_state.document_tool_data;
108121
document_data.secondary_color = color;
@@ -137,7 +150,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessorMes
137150
}
138151

139152
fn actions(&self) -> ActionList {
140-
let mut list = actions!(ToolMessageDiscriminant; ResetColors, SwapColors, ActivateTool);
153+
let mut list = actions!(ToolMessageDiscriminant; SelectRandomPrimaryColor, ResetColors, SwapColors, ActivateTool);
141154
list.extend(self.tool_state.tool_data.active_tool().actions());
142155

143156
list

0 commit comments

Comments
 (0)