mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
Merge pull request #1185 from garrettmoon/addContentInsetToButtonNode
[ASButtonNode] Add support for contentInset and make it bit more threadsafe
This commit is contained in:
commit
8abda67d1a
@ -37,6 +37,13 @@
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) ASVerticalAlignment contentVerticalAlignment;
|
@property (nonatomic, assign) ASVerticalAlignment contentVerticalAlignment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @discussion insets the title and the image node
|
||||||
|
*
|
||||||
|
* @param contentEdgeInsets The insets used around the title and image node
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) UIEdgeInsets contentEdgeInsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the styled title associated with the specified state.
|
* Returns the styled title associated with the specified state.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#import "ASThread.h"
|
#import "ASThread.h"
|
||||||
#import "ASDisplayNode+Subclasses.h"
|
#import "ASDisplayNode+Subclasses.h"
|
||||||
#import "ASBackgroundLayoutSpec.h"
|
#import "ASBackgroundLayoutSpec.h"
|
||||||
|
#import "ASInsetLayoutSpec.h"
|
||||||
|
|
||||||
@interface ASButtonNode ()
|
@interface ASButtonNode ()
|
||||||
{
|
{
|
||||||
@ -38,6 +39,9 @@
|
|||||||
|
|
||||||
@synthesize contentSpacing = _contentSpacing;
|
@synthesize contentSpacing = _contentSpacing;
|
||||||
@synthesize laysOutHorizontally = _laysOutHorizontally;
|
@synthesize laysOutHorizontally = _laysOutHorizontally;
|
||||||
|
@synthesize contentVerticalAlignment = _contentVerticalAlignment;
|
||||||
|
@synthesize contentHorizontalAlignment = _contentHorizontalAlignment;
|
||||||
|
@synthesize contentEdgeInsets = _contentEdgeInsets;
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
@ -54,8 +58,11 @@
|
|||||||
[_imageNode setLayerBacked:YES];
|
[_imageNode setLayerBacked:YES];
|
||||||
[_backgroundImageNode setLayerBacked:YES];
|
[_backgroundImageNode setLayerBacked:YES];
|
||||||
|
|
||||||
|
[_titleNode setFlexShrink:YES];
|
||||||
|
|
||||||
_contentHorizontalAlignment = ASAlignmentMiddle;
|
_contentHorizontalAlignment = ASAlignmentMiddle;
|
||||||
_contentVerticalAlignment = ASAlignmentCenter;
|
_contentVerticalAlignment = ASAlignmentCenter;
|
||||||
|
_contentEdgeInsets = UIEdgeInsetsZero;
|
||||||
|
|
||||||
[self addSubnode:_backgroundImageNode];
|
[self addSubnode:_backgroundImageNode];
|
||||||
[self addSubnode:_titleNode];
|
[self addSubnode:_titleNode];
|
||||||
@ -196,6 +203,42 @@
|
|||||||
[self setNeedsLayout];
|
[self setNeedsLayout];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (ASVerticalAlignment)contentVerticalAlignment
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
return _contentVerticalAlignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setContentVerticalAlignment:(ASVerticalAlignment)contentVerticalAlignment
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
_contentVerticalAlignment = contentVerticalAlignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ASHorizontalAlignment)contentHorizontalAlignment
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
return _contentHorizontalAlignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setContentHorizontalAlignment:(ASHorizontalAlignment)contentHorizontalAlignment
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
_contentHorizontalAlignment = contentHorizontalAlignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIEdgeInsets)contentEdgeInsets
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
return _contentEdgeInsets;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
_contentEdgeInsets = contentEdgeInsets;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)color forState:(ASControlState)state
|
- (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)color forState:(ASControlState)state
|
||||||
{
|
{
|
||||||
NSDictionary *attributes = @{
|
NSDictionary *attributes = @{
|
||||||
@ -352,11 +395,18 @@
|
|||||||
|
|
||||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||||
{
|
{
|
||||||
|
UIEdgeInsets contentEdgeInsets;
|
||||||
|
ASLayoutSpec *spec;
|
||||||
ASStackLayoutSpec *stack = [[ASStackLayoutSpec alloc] init];
|
ASStackLayoutSpec *stack = [[ASStackLayoutSpec alloc] init];
|
||||||
stack.direction = self.laysOutHorizontally ? ASStackLayoutDirectionHorizontal : ASStackLayoutDirectionVertical;
|
{
|
||||||
stack.spacing = self.contentSpacing;
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
stack.horizontalAlignment = _contentHorizontalAlignment;
|
stack.direction = _laysOutHorizontally ? ASStackLayoutDirectionHorizontal : ASStackLayoutDirectionVertical;
|
||||||
stack.verticalAlignment = _contentVerticalAlignment;
|
stack.spacing = _contentSpacing;
|
||||||
|
stack.horizontalAlignment = _contentHorizontalAlignment;
|
||||||
|
stack.verticalAlignment = _contentVerticalAlignment;
|
||||||
|
|
||||||
|
contentEdgeInsets = _contentEdgeInsets;
|
||||||
|
}
|
||||||
|
|
||||||
NSMutableArray *children = [[NSMutableArray alloc] initWithCapacity:2];
|
NSMutableArray *children = [[NSMutableArray alloc] initWithCapacity:2];
|
||||||
if (self.imageNode.image) {
|
if (self.imageNode.image) {
|
||||||
@ -369,12 +419,18 @@
|
|||||||
|
|
||||||
stack.children = children;
|
stack.children = children;
|
||||||
|
|
||||||
if (self.backgroundImageNode.image) {
|
spec = stack;
|
||||||
return [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:stack
|
|
||||||
background:self.backgroundImageNode];
|
if (UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, contentEdgeInsets) == NO) {
|
||||||
} else {
|
spec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:contentEdgeInsets child:spec];
|
||||||
return stack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self.backgroundImageNode.image) {
|
||||||
|
spec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:spec
|
||||||
|
background:self.backgroundImageNode];
|
||||||
|
}
|
||||||
|
|
||||||
|
return spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)layout
|
- (void)layout
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user