From 86aa53089ba7e5d1e24c247dde8e1bde06a67126 Mon Sep 17 00:00:00 2001 From: Burrit0z Date: Wed, 3 Jun 2020 14:42:33 -0400 Subject: [PATCH] CENTER % LABEL --- KAIBatteryCell.mm | 14 +++++++------- KAIBatteryPlatter.mm | 7 +++++++ KAIStackView.h | 1 + Kai.xm | 25 ++++++++++++++----------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/KAIBatteryCell.mm b/KAIBatteryCell.mm index 01661dc..c7ddd47 100755 --- a/KAIBatteryCell.mm +++ b/KAIBatteryCell.mm @@ -126,23 +126,23 @@ [self.glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES; self.battery.translatesAutoresizingMaskIntoConstraints = NO; - [self.battery.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 49)].active = YES; + [self.battery.rightAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:- 20.5].active = YES; [self.battery.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES; [self.battery.widthAnchor constraintEqualToConstant:20].active = YES; [self.battery.heightAnchor constraintEqualToConstant:10].active = YES; - [self.percentLabel.rightAnchor constraintEqualToAnchor:self.battery.leftAnchor constant:-4.5].active = YES; + if(!hideDeviceLabel) { + [self.percentLabel.rightAnchor constraintEqualToAnchor:self.battery.leftAnchor constant:-4.5].active = YES; + } else if(hideDeviceLabel) { + [self.percentLabel.centerXAnchor constraintEqualToAnchor:blurPlatter.centerXAnchor].active = YES; + } if(hidePercent) { [self.label.rightAnchor constraintEqualToAnchor:self.battery.leftAnchor constant:-4.5].active = YES; } [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)].active = YES; - if(kaiAlign==0) { - [self.widthAnchor constraintEqualToConstant:(self.frame.size.width)].active = YES; - } else { - [self.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES; - } + [self.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES; } diff --git a/KAIBatteryPlatter.mm b/KAIBatteryPlatter.mm index d1fbd96..62e570d 100755 --- a/KAIBatteryPlatter.mm +++ b/KAIBatteryPlatter.mm @@ -159,11 +159,18 @@ long long lastPercentage; self.heightConstraint.active = YES; self.stack.heightConstraint.active = YES; [self setContentSize:self.stack.frame.size]; + if(kaiAlign==0) { + [self.stack.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES; + } else { + self.widthConstraint = [self.widthAnchor constraintEqualToConstant:(self.number * (self.frame.size.width + bannerWidthFactor))]; + self.widthConstraint.active = YES; + } } else { int height = (self.number * (bannerHeight + spacing)); if(kaiAlign!=0) { height = bannerHeight + spacing; + self.widthConstraint.constant = (self.number * (self.frame.size.width + bannerWidthFactor)); } if([self.superview.subviews count]>1) { diff --git a/KAIStackView.h b/KAIStackView.h index 9232e6f..fdabf55 100644 --- a/KAIStackView.h +++ b/KAIStackView.h @@ -6,6 +6,7 @@ @property (nonatomic, assign) NSInteger number; @property (nonatomic, assign) NSInteger oldCountOfDevices; @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; +@property (nonatomic, strong) NSLayoutConstraint *widthConstraint; @property (nonatomic, strong) KAIStackView *stack; @property (nonatomic, assign) BOOL isUpdating; @property (nonatomic, assign) BOOL queued; diff --git a/Kai.xm b/Kai.xm index 6871152..8c995c6 100755 --- a/Kai.xm +++ b/Kai.xm @@ -11,19 +11,22 @@ CSAdjunctListView *list; -(void)_layoutStackView { //this code is used to determine if kai is at the bottom of the stack view - if([[self stackView].subviews objectAtIndex:([[self stackView].subviews count] -1)] != [KAIBatteryPlatter sharedInstance] && belowMusic) { - //if it is not, but the option to have kai below music is on, i simply remove from it's current pos. - //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]; - } + @try { + if([[self stackView].subviews objectAtIndex:([[self stackView].subviews count] -1)] != [KAIBatteryPlatter sharedInstance] && belowMusic) { + //if it is not, but the option to have kai below music is on, i simply remove from it's current pos. + //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) {} if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { - [(NCNotificationListView *)(KAISelf.superview) fixComplicationsViewFrame]; - } + [(NCNotificationListView *)(KAISelf.superview) fixComplicationsViewFrame]; + } [[KAIBatteryPlatter sharedInstance] calculateHeight];