mirror of
https://github.com/textmate/textmate.git
synced 2026-01-19 19:58:11 -05:00
Add OakSetAccessibilityLabel function
This function makes it easy to set accessibility "labels" for UI elements. It is flexible - takes care of NSView vs. NSControl case, labels can be specified directly as a string or as a user interface element.
This commit is contained in:
committed by
Allan Odgaard
parent
617e9df202
commit
b80d60db57
@@ -16,3 +16,4 @@ PUBLIC NSImageView* OakCreateDividerImageView ();
|
||||
PUBLIC NSBox* OakCreateViewWithColor (NSColor* color = nil, NSColor* secondaryColor = nil);
|
||||
PUBLIC NSBox* OakCreateVerticalLine (NSColor* primaryColor, NSColor* secondaryColor = nil);
|
||||
PUBLIC NSBox* OakCreateHorizontalLine (NSColor* primaryColor, NSColor* secondaryColor = nil);
|
||||
PUBLIC BOOL OakSetAccessibilityLabel (NSObject* element, NSObject* label);
|
||||
|
||||
@@ -211,3 +211,23 @@ NSImageView* OakCreateDividerImageView ()
|
||||
[res setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationVertical];
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOL OakSetAccessibilityLabel (NSObject* element, NSObject* label)
|
||||
{
|
||||
if([element isKindOfClass:[NSControl class]])
|
||||
element = [(NSControl*)element cell] ?: element; // e.g. NSTableView is an NSControl with a nil cell
|
||||
else if(!([element isKindOfClass:[NSView class]] || [element isKindOfClass:[NSCell class]]))
|
||||
return NO;
|
||||
|
||||
NSString* attribute = NSAccessibilityDescriptionAttribute;
|
||||
if([label isKindOfClass:[NSView class]] || [label isKindOfClass:[NSCell class]])
|
||||
{
|
||||
attribute = NSAccessibilityTitleUIElementAttribute;
|
||||
if([label isKindOfClass:[NSControl class]])
|
||||
label = [(NSControl*)label cell] ?: label;
|
||||
}
|
||||
else if(![label isKindOfClass:[NSString class]])
|
||||
return NO;
|
||||
|
||||
return [element accessibilitySetOverrideValue:label forAttribute:attribute];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user