parent
53098fad7b
commit
6e34152fa0
|
|
@ -21,8 +21,7 @@ use crate::{
|
||||||
input_state::{InputState, MultiTouchInfo, PointerEvent},
|
input_state::{InputState, MultiTouchInfo, PointerEvent},
|
||||||
interaction,
|
interaction,
|
||||||
layers::GraphicLayers,
|
layers::GraphicLayers,
|
||||||
load,
|
load::{self, Bytes, Loaders, SizedTexture},
|
||||||
load::{Bytes, Loaders, SizedTexture},
|
|
||||||
memory::{Options, Theme},
|
memory::{Options, Theme},
|
||||||
os::OperatingSystem,
|
os::OperatingSystem,
|
||||||
output::FullOutput,
|
output::FullOutput,
|
||||||
|
|
@ -32,10 +31,10 @@ use crate::{
|
||||||
viewport::ViewportClass,
|
viewport::ViewportClass,
|
||||||
Align2, CursorIcon, DeferredViewportUiCallback, FontDefinitions, Grid, Id, ImmediateViewport,
|
Align2, CursorIcon, DeferredViewportUiCallback, FontDefinitions, Grid, Id, ImmediateViewport,
|
||||||
ImmediateViewportRendererCallback, Key, KeyboardShortcut, Label, LayerId, Memory,
|
ImmediateViewportRendererCallback, Key, KeyboardShortcut, Label, LayerId, Memory,
|
||||||
ModifierNames, NumExt as _, Order, Painter, RawInput, Response, RichText, ScrollArea, Sense,
|
ModifierNames, Modifiers, NumExt as _, Order, Painter, RawInput, Response, RichText,
|
||||||
Style, TextStyle, TextureHandle, TextureOptions, Ui, ViewportBuilder, ViewportCommand,
|
ScrollArea, Sense, Style, TextStyle, TextureHandle, TextureOptions, Ui, ViewportBuilder,
|
||||||
ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, ViewportOutput, Widget as _,
|
ViewportCommand, ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, ViewportOutput,
|
||||||
WidgetRect, WidgetText,
|
Widget as _, WidgetRect, WidgetText,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
|
|
@ -1484,35 +1483,48 @@ impl Context {
|
||||||
self.send_cmd(crate::OutputCommand::CopyImage(image));
|
self.send_cmd(crate::OutputCommand::CopyImage(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_show_modifier_symbols(&self) -> bool {
|
||||||
|
let ModifierNames {
|
||||||
|
alt,
|
||||||
|
ctrl,
|
||||||
|
shift,
|
||||||
|
mac_cmd,
|
||||||
|
..
|
||||||
|
} = ModifierNames::SYMBOLS;
|
||||||
|
|
||||||
|
let font_id = TextStyle::Body.resolve(&self.style());
|
||||||
|
self.fonts(|f| {
|
||||||
|
let mut lock = f.lock();
|
||||||
|
let font = lock.fonts.font(&font_id);
|
||||||
|
font.has_glyphs(alt)
|
||||||
|
&& font.has_glyphs(ctrl)
|
||||||
|
&& font.has_glyphs(shift)
|
||||||
|
&& font.has_glyphs(mac_cmd)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Format the given modifiers in a human-readable way (e.g. `Ctrl+Shift+X`).
|
||||||
|
pub fn format_modifiers(&self, modifiers: Modifiers) -> String {
|
||||||
|
let os = self.os();
|
||||||
|
|
||||||
|
let is_mac = os.is_mac();
|
||||||
|
|
||||||
|
if is_mac && self.can_show_modifier_symbols() {
|
||||||
|
ModifierNames::SYMBOLS.format(&modifiers, is_mac)
|
||||||
|
} else {
|
||||||
|
ModifierNames::NAMES.format(&modifiers, is_mac)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Format the given shortcut in a human-readable way (e.g. `Ctrl+Shift+X`).
|
/// Format the given shortcut in a human-readable way (e.g. `Ctrl+Shift+X`).
|
||||||
///
|
///
|
||||||
/// Can be used to get the text for [`crate::Button::shortcut_text`].
|
/// Can be used to get the text for [`crate::Button::shortcut_text`].
|
||||||
pub fn format_shortcut(&self, shortcut: &KeyboardShortcut) -> String {
|
pub fn format_shortcut(&self, shortcut: &KeyboardShortcut) -> String {
|
||||||
let os = self.os();
|
let os = self.os();
|
||||||
|
|
||||||
let is_mac = matches!(os, OperatingSystem::Mac | OperatingSystem::IOS);
|
let is_mac = os.is_mac();
|
||||||
|
|
||||||
let can_show_symbols = || {
|
if is_mac && self.can_show_modifier_symbols() {
|
||||||
let ModifierNames {
|
|
||||||
alt,
|
|
||||||
ctrl,
|
|
||||||
shift,
|
|
||||||
mac_cmd,
|
|
||||||
..
|
|
||||||
} = ModifierNames::SYMBOLS;
|
|
||||||
|
|
||||||
let font_id = TextStyle::Body.resolve(&self.style());
|
|
||||||
self.fonts(|f| {
|
|
||||||
let mut lock = f.lock();
|
|
||||||
let font = lock.fonts.font(&font_id);
|
|
||||||
font.has_glyphs(alt)
|
|
||||||
&& font.has_glyphs(ctrl)
|
|
||||||
&& font.has_glyphs(shift)
|
|
||||||
&& font.has_glyphs(mac_cmd)
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
if is_mac && can_show_symbols() {
|
|
||||||
shortcut.format(&ModifierNames::SYMBOLS, is_mac)
|
shortcut.format(&ModifierNames::SYMBOLS, is_mac)
|
||||||
} else {
|
} else {
|
||||||
shortcut.format(&ModifierNames::NAMES, is_mac)
|
shortcut.format(&ModifierNames::NAMES, is_mac)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue