@@ -21,8 +21,7 @@ use crate::{
21
21
input_state:: { InputState , MultiTouchInfo , PointerEvent } ,
22
22
interaction,
23
23
layers:: GraphicLayers ,
24
- load,
25
- load:: { Bytes , Loaders , SizedTexture } ,
24
+ load:: { self , Bytes , Loaders , SizedTexture } ,
26
25
memory:: { Options , Theme } ,
27
26
os:: OperatingSystem ,
28
27
output:: FullOutput ,
@@ -32,10 +31,10 @@ use crate::{
32
31
viewport:: ViewportClass ,
33
32
Align2 , CursorIcon , DeferredViewportUiCallback , FontDefinitions , Grid , Id , ImmediateViewport ,
34
33
ImmediateViewportRendererCallback , Key , KeyboardShortcut , Label , LayerId , Memory ,
35
- ModifierNames , NumExt as _, Order , Painter , RawInput , Response , RichText , ScrollArea , Sense ,
36
- Style , TextStyle , TextureHandle , TextureOptions , Ui , ViewportBuilder , ViewportCommand ,
37
- ViewportId , ViewportIdMap , ViewportIdPair , ViewportIdSet , ViewportOutput , Widget as _ ,
38
- WidgetRect , WidgetText ,
34
+ ModifierNames , Modifiers , NumExt as _, Order , Painter , RawInput , Response , RichText ,
35
+ ScrollArea , Sense , Style , TextStyle , TextureHandle , TextureOptions , Ui , ViewportBuilder ,
36
+ ViewportCommand , ViewportId , ViewportIdMap , ViewportIdPair , ViewportIdSet , ViewportOutput ,
37
+ Widget as _ , WidgetRect , WidgetText ,
39
38
} ;
40
39
41
40
#[ cfg( feature = "accesskit" ) ]
@@ -1484,35 +1483,48 @@ impl Context {
1484
1483
self . send_cmd ( crate :: OutputCommand :: CopyImage ( image) ) ;
1485
1484
}
1486
1485
1486
+ fn can_show_modifier_symbols ( & self ) -> bool {
1487
+ let ModifierNames {
1488
+ alt,
1489
+ ctrl,
1490
+ shift,
1491
+ mac_cmd,
1492
+ ..
1493
+ } = ModifierNames :: SYMBOLS ;
1494
+
1495
+ let font_id = TextStyle :: Body . resolve ( & self . style ( ) ) ;
1496
+ self . fonts ( |f| {
1497
+ let mut lock = f. lock ( ) ;
1498
+ let font = lock. fonts . font ( & font_id) ;
1499
+ font. has_glyphs ( alt)
1500
+ && font. has_glyphs ( ctrl)
1501
+ && font. has_glyphs ( shift)
1502
+ && font. has_glyphs ( mac_cmd)
1503
+ } )
1504
+ }
1505
+
1506
+ /// Format the given modifiers in a human-readable way (e.g. `Ctrl+Shift+X`).
1507
+ pub fn format_modifiers ( & self , modifiers : Modifiers ) -> String {
1508
+ let os = self . os ( ) ;
1509
+
1510
+ let is_mac = os. is_mac ( ) ;
1511
+
1512
+ if is_mac && self . can_show_modifier_symbols ( ) {
1513
+ ModifierNames :: SYMBOLS . format ( & modifiers, is_mac)
1514
+ } else {
1515
+ ModifierNames :: NAMES . format ( & modifiers, is_mac)
1516
+ }
1517
+ }
1518
+
1487
1519
/// Format the given shortcut in a human-readable way (e.g. `Ctrl+Shift+X`).
1488
1520
///
1489
1521
/// Can be used to get the text for [`crate::Button::shortcut_text`].
1490
1522
pub fn format_shortcut ( & self , shortcut : & KeyboardShortcut ) -> String {
1491
1523
let os = self . os ( ) ;
1492
1524
1493
- let is_mac = matches ! ( os, OperatingSystem :: Mac | OperatingSystem :: IOS ) ;
1494
-
1495
- let can_show_symbols = || {
1496
- let ModifierNames {
1497
- alt,
1498
- ctrl,
1499
- shift,
1500
- mac_cmd,
1501
- ..
1502
- } = ModifierNames :: SYMBOLS ;
1503
-
1504
- let font_id = TextStyle :: Body . resolve ( & self . style ( ) ) ;
1505
- self . fonts ( |f| {
1506
- let mut lock = f. lock ( ) ;
1507
- let font = lock. fonts . font ( & font_id) ;
1508
- font. has_glyphs ( alt)
1509
- && font. has_glyphs ( ctrl)
1510
- && font. has_glyphs ( shift)
1511
- && font. has_glyphs ( mac_cmd)
1512
- } )
1513
- } ;
1525
+ let is_mac = os. is_mac ( ) ;
1514
1526
1515
- if is_mac && can_show_symbols ( ) {
1527
+ if is_mac && self . can_show_modifier_symbols ( ) {
1516
1528
shortcut. format ( & ModifierNames :: SYMBOLS , is_mac)
1517
1529
} else {
1518
1530
shortcut. format ( & ModifierNames :: NAMES , is_mac)
0 commit comments