Skip to content

Select random primary color #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion editor/src/input/input_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]},
Expand Down
1 change: 1 addition & 0 deletions editor/src/viewport_tools/tool_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub enum ToolMessage {
SelectPrimaryColor {
color: Color,
},
SelectRandomPrimaryColor,
SelectSecondaryColor {
color: Color,
},
Expand Down
15 changes: 14 additions & 1 deletion editor/src/viewport_tools/tool_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down