Browse Source

align the view, right align is broken

pull/1/head
Burrit0z 4 years ago
parent
commit
9c4dd38746
4 changed files with 44 additions and 11 deletions
  1. +38
    -2
      KAIBatteryPlatter.mm
  2. +2
    -2
      KAIStackView.h
  3. +2
    -2
      KAIStackView.mm
  4. +2
    -5
      Kai.xm

+ 38
- 2
KAIBatteryPlatter.mm View File

@@ -8,6 +8,7 @@ NSTimer *queueTimer = nil;
self = [super initWithFrame:arg1];
instance = self;
if (self) {
self.stackHolder = [[UIView alloc] initWithFrame:arg1];
self.stack = [[KAIStackView alloc] init];
self.stack.axis = kaiAlign==0 ? 1 : 0;
self.stack.distribution = 0;
@@ -15,13 +16,33 @@ NSTimer *queueTimer = nil;
self.stack.alignment = 0;
self.oldCountOfDevices = -100;
self.queued = NO;
[self setMinimumZoomScale:1];
[self setMaximumZoomScale:1];
[self addSubview:self.stack];
[self addSubview:self.stackHolder];
[self.stackHolder addSubview:self.stack];
[self setContentSize:self.stack.frame.size];
[self setContentOffset:CGPointMake(0,0)];

//Keeping this link here to leak...
//https://cdn.discordapp.com/attachments/683698397634756646/718122118990266518/unknown.png

self.stackHolder.translatesAutoresizingMaskIntoConstraints = NO;

if(bannerAlign==2) { //center
self.subviewAligner = [self.stackHolder.centerXAnchor constraintEqualToAnchor:self.centerXAnchor];
} else if(bannerAlign==1) { //left
self.subviewAligner = [self.stackHolder.leftAnchor constraintEqualToAnchor:self.leftAnchor];
} else if(bannerAlign==3) { //right
self.subviewAligner = [self.stackHolder.rightAnchor constraintEqualToAnchor:self.rightAnchor];
}

[self.stackHolder.heightAnchor constraintEqualToAnchor:self.heightAnchor].active = YES;
[self.stackHolder.widthAnchor constraintEqualToAnchor:self.stack.widthAnchor].active = YES;
[self.stackHolder.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;

self.subviewAligner.active = YES;

[self updateBattery];
}
return self;
@@ -191,9 +212,12 @@ long long lastPercentage;

}];

self.stackHolder.frame = self.frame;

}

-(void)refreshForPrefs {

self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal;
[self setContentSize:self.stack.frame.size];
for( UIView *view in self.stack.subviews ) {
@@ -210,6 +234,18 @@ long long lastPercentage;
[device resetKaiCellForNewPrefs];
}

self.subviewAligner.active = NO;
[self.stackHolder removeConstraint:self.subviewAligner];
if(bannerAlign==2) { //center
self.subviewAligner = [self.stackHolder.centerXAnchor constraintEqualToAnchor:self.centerXAnchor];
} else if(bannerAlign==1) { //left
self.subviewAligner = [self.stackHolder.leftAnchor constraintEqualToAnchor:self.leftAnchor];
} else if(bannerAlign==3) { //right
self.subviewAligner = [self.stackHolder.rightAnchor constraintEqualToAnchor:self.rightAnchor];
}

self.subviewAligner.active = YES;

[self updateBattery];
}


+ 2
- 2
KAIStackView.h View File

@@ -1,14 +1,14 @@
@interface KAIStackView : UIStackView
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint;
@property (nonatomic, strong) NSLayoutConstraint *widthConstraint;
@property (nonatomic, strong) NSLayoutConstraint *aligner;
@end

@interface KAIBatteryPlatter : UIScrollView <UIScrollViewDelegate>
@property (nonatomic, strong) UIView *stackHolder;
@property (nonatomic, assign) NSInteger number;
@property (nonatomic, assign) NSInteger oldCountOfDevices;
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint;
@property (nonatomic, strong) NSLayoutConstraint *widthConstraint;
@property (nonatomic, strong) NSLayoutConstraint *subviewAligner;
@property (nonatomic, strong) KAIStackView *stack;
@property (nonatomic, assign) BOOL isUpdating;
@property (nonatomic, assign) BOOL queued;

+ 2
- 2
KAIStackView.mm View File

@@ -10,7 +10,7 @@

-(void)addSubview:(UIView *)view {
[super addSubview:view];
[(UIScrollView *)self.superview setContentSize:self.frame.size];
[(UIScrollView *)self.superview.superview setContentSize:self.frame.size];

if(textColor==0 && [view respondsToSelector:@selector(updateInfo)]) {
KAIBatteryCell *cell = (KAIBatteryCell *)view;
@@ -28,7 +28,7 @@

-(void)layoutSubviews {
[super layoutSubviews];
[(KAIBatteryPlatter *)(self.superview) calculateHeight];
[(KAIBatteryPlatter *)(self.superview.superview) calculateHeight];
}

@end

+ 2
- 5
Kai.xm View File

@@ -9,6 +9,7 @@ CSAdjunctListView *list;
%property (nonatomic, assign) BOOL hasKai;

-(void)_layoutStackView {
%orig;

//this code is used to determine if kai is at the bottom of the stack view
@try {
@@ -17,10 +18,7 @@ CSAdjunctListView *list;
//and insert into last slot.
[[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:([[self stackView].subviews count] -1)];
}/* else if([[self stackView].subviews objectAtIndex:0] != [KAIBatteryPlatter sharedInstance] && !belowMusic) {
[[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
}*/
}

} @catch (NSException *exc) {}

@@ -30,7 +28,6 @@ CSAdjunctListView *list;

[[KAIBatteryPlatter sharedInstance] calculateHeight];

%orig;
}

-(void)setStackView:(UIStackView *)arg1 {

Loading…
Cancel
Save