Skip to content

Commit

Permalink
Make HintInfo label use Cow<'static, str> instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
mTvare6 committed Jan 13, 2025
1 parent 3582126 commit 0a85612
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
key_groups: vec![KeysGroup(vec![Key::Control]).into()],
key_groups_mac: None,
mouse: None,
label: String::from("Snap 15°"),
label: "Snap 15°".into(),
plus: false,
slash: false,
}]),
Expand Down Expand Up @@ -129,7 +129,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
key_groups: vec![KeysGroup(vec![Key::Control]).into()],
key_groups_mac: None,
mouse: None,
label: String::from("Increments"),
label: "Increments".into(),
plus: false,
slash: false,
}]),
Expand Down
17 changes: 9 additions & 8 deletions editor/src/messages/tool/utility_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::node_graph_executor::NodeGraphExecutor;
use graphene_core::raster::color::Color;
use graphene_core::text::FontCache;

use std::borrow::Cow;
use std::fmt::{self, Debug};

pub struct ToolActionHandlerData<'a> {
Expand Down Expand Up @@ -492,15 +493,15 @@ pub struct HintInfo {
/// No such icon is shown if `None` is given, and it can be combined with `key_groups` if desired.
pub mouse: Option<MouseMotion>,
/// The text describing what occurs with this input combination.
pub label: String,
pub label: Cow<'static, str>,
/// Draws a prepended "+" symbol which indicates that this is a refinement upon a previous hint in the group.
pub plus: bool,
/// Draws a prepended "/" symbol which indicates that this is an alternative to a previous hint in the group.
pub slash: bool,
}

impl HintInfo {
pub fn keys(keys: impl IntoIterator<Item = Key>, label: impl Into<String>) -> Self {
pub fn keys(keys: impl IntoIterator<Item = Key>, label: impl Into<Cow<'static, str>>) -> Self {
let keys: Vec<_> = keys.into_iter().collect();
Self {
key_groups: vec![KeysGroup(keys).into()],
Expand All @@ -512,7 +513,7 @@ impl HintInfo {
}
}

pub fn multi_keys(multi_keys: impl IntoIterator<Item = impl IntoIterator<Item = Key>>, label: impl Into<String>) -> Self {
pub fn multi_keys(multi_keys: impl IntoIterator<Item = impl IntoIterator<Item = Key>>, label: impl Into<Cow<'static, str>>) -> Self {
let key_groups = multi_keys.into_iter().map(|keys| KeysGroup(keys.into_iter().collect()).into()).collect();
Self {
key_groups,
Expand All @@ -524,7 +525,7 @@ impl HintInfo {
}
}

pub fn mouse(mouse_motion: MouseMotion, label: impl Into<String>) -> Self {
pub fn mouse(mouse_motion: MouseMotion, label: impl Into<Cow<'static, str>>) -> Self {
Self {
key_groups: vec![],
key_groups_mac: None,
Expand All @@ -535,7 +536,7 @@ impl HintInfo {
}
}

pub fn label(label: impl Into<String>) -> Self {
pub fn label(label: impl Into<Cow<'static, str>>) -> Self {
Self {
key_groups: vec![],
key_groups_mac: None,
Expand All @@ -546,7 +547,7 @@ impl HintInfo {
}
}

pub fn keys_and_mouse(keys: impl IntoIterator<Item = Key>, mouse_motion: MouseMotion, label: impl Into<String>) -> Self {
pub fn keys_and_mouse(keys: impl IntoIterator<Item = Key>, mouse_motion: MouseMotion, label: impl Into<Cow<'static, str>>) -> Self {
let keys: Vec<_> = keys.into_iter().collect();
Self {
key_groups: vec![KeysGroup(keys).into()],
Expand All @@ -558,7 +559,7 @@ impl HintInfo {
}
}

pub fn multi_keys_and_mouse(multi_keys: impl IntoIterator<Item = impl IntoIterator<Item = Key>>, mouse_motion: MouseMotion, label: impl Into<String>) -> Self {
pub fn multi_keys_and_mouse(multi_keys: impl IntoIterator<Item = impl IntoIterator<Item = Key>>, mouse_motion: MouseMotion, label: impl Into<Cow<'static, str>>) -> Self {
let key_groups = multi_keys.into_iter().map(|keys| KeysGroup(keys.into_iter().collect()).into()).collect();
Self {
key_groups,
Expand All @@ -570,7 +571,7 @@ impl HintInfo {
}
}

pub fn arrow_keys(label: impl Into<String>) -> Self {
pub fn arrow_keys(label: impl Into<Cow<'static, str>>) -> Self {
let multi_keys = [[Key::ArrowUp], [Key::ArrowRight], [Key::ArrowDown], [Key::ArrowLeft]];
Self::multi_keys(multi_keys, label)
}
Expand Down

0 comments on commit 0a85612

Please sign in to comment.