complication widget scaling for 40mm watch (#524)

This commit is contained in:
Paul Plant 2024-04-01 13:08:27 +02:00 committed by GitHub
parent 1f274188b0
commit 72abe3f315
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 7 deletions

View File

@ -11,17 +11,18 @@ import SwiftUI
extension XDripWatchComplication.EntryView {
@ViewBuilder
var accessoryRectangularView: some View {
ZStack {
VStack(spacing: 0) {
HStack(alignment: .center) {
HStack(alignment: .center, spacing: 4) {
Text("\(entry.widgetState.bgValueStringInUserChosenUnit)\(entry.widgetState.trendArrow()) ")
.font(.system(size: 24)).bold()
.font(.system(size: entry.widgetState.isSmallScreen() ? 20 : 24)).bold()
.foregroundStyle(entry.widgetState.bgTextColor())
Text(entry.widgetState.deltaChangeStringInUserChosenUnit())
.font(.system(size: 24)).fontWeight(.semibold)
.font(.system(size: entry.widgetState.isSmallScreen() ? 20 : 24)).fontWeight(.semibold)
.foregroundStyle(entry.widgetState.deltaChangeTextColor())
.lineLimit(1)
}
@ -29,21 +30,21 @@ extension XDripWatchComplication.EntryView {
Spacer()
Text("\(entry.widgetState.bgReadingDate?.formatted(date: .omitted, time: .shortened) ?? "--:--")")
.font(.system(size: 16))
.font(.system(size: entry.widgetState.isSmallScreen() ? 14 : 16))
.foregroundStyle(Color(white: 0.7))
.minimumScaleFactor(0.2)
}
.padding(0)
GlucoseChartView(glucoseChartType: .watchAccessoryRectangular, bgReadingValues: entry.widgetState.bgReadingValues, bgReadingDates: entry.widgetState.bgReadingDates, isMgDl: entry.widgetState.isMgDl, urgentLowLimitInMgDl: entry.widgetState.urgentLowLimitInMgDl, lowLimitInMgDl: entry.widgetState.lowLimitInMgDl, highLimitInMgDl: entry.widgetState.highLimitInMgDl, urgentHighLimitInMgDl: entry.widgetState.urgentHighLimitInMgDl, liveActivitySize: nil, hoursToShowScalingHours: nil, glucoseCircleDiameterScalingHours: nil, overrideChartHeight: entry.widgetState.disableComplications ? ConstantsGlucoseChartSwiftUI.viewHeightWatchAccessoryRectangular - 15 : nil, overrideChartWidth: nil)
GlucoseChartView(glucoseChartType: .watchAccessoryRectangular, bgReadingValues: entry.widgetState.bgReadingValues, bgReadingDates: entry.widgetState.bgReadingDates, isMgDl: entry.widgetState.isMgDl, urgentLowLimitInMgDl: entry.widgetState.urgentLowLimitInMgDl, lowLimitInMgDl: entry.widgetState.lowLimitInMgDl, highLimitInMgDl: entry.widgetState.highLimitInMgDl, urgentHighLimitInMgDl: entry.widgetState.urgentHighLimitInMgDl, liveActivitySize: nil, hoursToShowScalingHours: nil, glucoseCircleDiameterScalingHours: nil, overrideChartHeight: entry.widgetState.overrideChartHeight(), overrideChartWidth: entry.widgetState.overrideChartWidth())
if entry.widgetState.disableComplications {
HStack(alignment: .center, spacing: 4) {
Image(systemName: "exclamationmark.triangle")
.font(.system(size: 14))
.font(.system(size: entry.widgetState.isSmallScreen() ? 12 : 14))
Text("Keep-alive disabled")
.font(.system(size: 14))
.font(.system(size: entry.widgetState.isSmallScreen() ? 12 : 14))
.multilineTextAlignment(.leading)
}
.foregroundStyle(.teal)

View File

@ -151,6 +151,22 @@ extension XDripWatchComplication.Entry {
return (minValue, maxValue, gaugeColor, gaugeGradient)
}
func isSmallScreen() -> Bool {
return (WKInterfaceDevice.current().screenBounds.size.width < ConstantsAppleWatch.pixelWidthLimitForSmallScreen) ? true : false
}
func overrideChartHeight() -> Double {
var height = isSmallScreen() ? ConstantsGlucoseChartSwiftUI.viewHeightWatchAccessoryRectangularSmall : ConstantsGlucoseChartSwiftUI.viewHeightWatchAccessoryRectangular
height += disableComplications ? -15 : 0
return height
}
func overrideChartWidth() -> Double {
return isSmallScreen() ? ConstantsGlucoseChartSwiftUI.viewWidthWatchAccessoryRectangularSmall : ConstantsGlucoseChartSwiftUI.viewWidthWatchAccessoryRectangular
}
}
}
@ -158,6 +174,6 @@ extension XDripWatchComplication.Entry {
extension XDripWatchComplication.Entry {
static var placeholder: Self {
.init(date: .now, widgetState: WidgetState(bgReadingValues: [100], bgReadingDates: [Date()], isMgDl: true, slopeOrdinal: 3, deltaChangeInMgDl: 0, urgentLowLimitInMgDl: 60, lowLimitInMgDl: 80, highLimitInMgDl: 140, urgentHighLimitInMgDl: 180))
.init(date: .now, widgetState: WidgetState(bgReadingValues: [100], bgReadingDates: [Date()], isMgDl: true, slopeOrdinal: 3, deltaChangeInMgDl: 0, urgentLowLimitInMgDl: 60, lowLimitInMgDl: 80, highLimitInMgDl: 140, urgentHighLimitInMgDl: 180, disableComplications: true))
}
}

View File

@ -12,6 +12,7 @@
470824D2297484B500C52317 /* SwiftCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 470824D1297484B500C52317 /* SwiftCharts */; };
470824D3297484B500C52317 /* SwiftCharts in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 470824D1297484B500C52317 /* SwiftCharts */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
470CE1FC246802EB00D5CB74 /* BluetoothPeripheralsView.strings in Resources */ = {isa = PBXBuildFile; fileRef = 470CE1FE246802EB00D5CB74 /* BluetoothPeripheralsView.strings */; };
4713B0142BBAB12D009F2838 /* ConstantsAppleWatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DE41B82B87B2680041DA19 /* ConstantsAppleWatch.swift */; };
47150A4027F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47150A3F27F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift */; };
4716A4EF2B406C3D00419052 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4716A4EE2B406C3D00419052 /* WidgetKit.framework */; };
4716A4F12B406C3D00419052 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4716A4F02B406C3D00419052 /* SwiftUI.framework */; };
@ -3996,6 +3997,7 @@
47E91BBA2B9A43F20063181B /* FollowerBackgroundKeepAliveType.swift in Sources */,
478A92582B8FA1F20084C394 /* Date.swift in Sources */,
478A92552B8FA1D80084C394 /* ConstantsBGGraphBuilder.swift in Sources */,
4713B0142BBAB12D009F2838 /* ConstantsAppleWatch.swift in Sources */,
478A925F2B8FB5290084C394 /* XDripWatchComplication+Entry.swift in Sources */,
478A925A2B8FA27D0084C394 /* TextsCommon.swift in Sources */,
4746068C2B96380200AC9214 /* ConstantsLibreLinkUp.swift in Sources */,

View File

@ -78,6 +78,10 @@ enum ConstantsGlucoseChartSwiftUI {
static let viewWidthWatchAccessoryRectangular: CGFloat = 180
static let viewHeightWatchAccessoryRectangular: CGFloat = 55
// watch complication sizes for smaller watches
static let viewWidthWatchAccessoryRectangularSmall: CGFloat = 160
static let viewHeightWatchAccessoryRectangularSmall: CGFloat = 45
static let lowHighLineColorWatchAccessoryRectangular = Color(white: 0.7)
static let urgentLowHighLineColorWatchAccessoryRectangular = Color(white: 0.5)
static let xAxisGridLineColorWatchAccessoryRectangular = Color(white: 0.4)