Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework DecimalTextField Struct and Toolbar #337

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions FreeAPS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
3871F38725ED661C0013ECB5 /* Suggestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3871F38625ED661C0013ECB5 /* Suggestion.swift */; };
3871F39C25ED892B0013ECB5 /* TempTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3871F39B25ED892B0013ECB5 /* TempTarget.swift */; };
3871F39F25ED895A0013ECB5 /* Decimal+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3871F39E25ED895A0013ECB5 /* Decimal+Extensions.swift */; };
3883581C25EE79BB00E024B2 /* DecimalTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3883581B25EE79BB00E024B2 /* DecimalTextField.swift */; };
3883581C25EE79BB00E024B2 /* TextFieldWithToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3883581B25EE79BB00E024B2 /* TextFieldWithToolBar.swift */; };
3883583425EEB38000E024B2 /* PumpSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3883583325EEB38000E024B2 /* PumpSettings.swift */; };
388358C825EEF6D200E024B2 /* BasalProfileEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388358C725EEF6D200E024B2 /* BasalProfileEntry.swift */; };
38887CCE25F5725200944304 /* IOBEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38887CCD25F5725200944304 /* IOBEntry.swift */; };
Expand Down Expand Up @@ -641,7 +641,7 @@
3871F38625ED661C0013ECB5 /* Suggestion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Suggestion.swift; sourceTree = "<group>"; };
3871F39B25ED892B0013ECB5 /* TempTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempTarget.swift; sourceTree = "<group>"; };
3871F39E25ED895A0013ECB5 /* Decimal+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Decimal+Extensions.swift"; sourceTree = "<group>"; };
3883581B25EE79BB00E024B2 /* DecimalTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecimalTextField.swift; sourceTree = "<group>"; };
3883581B25EE79BB00E024B2 /* TextFieldWithToolBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldWithToolBar.swift; sourceTree = "<group>"; };
3883583325EEB38000E024B2 /* PumpSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpSettings.swift; sourceTree = "<group>"; };
388358C725EEF6D200E024B2 /* BasalProfileEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasalProfileEntry.swift; sourceTree = "<group>"; };
38887CCD25F5725200944304 /* IOBEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IOBEntry.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1516,7 +1516,7 @@
isa = PBXGroup;
children = (
3811DE5925C9D4D500A708ED /* ViewModifiers.swift */,
3883581B25EE79BB00E024B2 /* DecimalTextField.swift */,
3883581B25EE79BB00E024B2 /* TextFieldWithToolBar.swift */,
383420D825FFEB3F002D46C1 /* Popup.swift */,
389ECDFD2601061500D86C4F /* View+Snapshot.swift */,
38EA05FF262091870064E39B /* BolusProgressViewStyle.swift */,
Expand Down Expand Up @@ -2719,7 +2719,7 @@
38A504A425DD9C4000C5B9E8 /* UserDefaultsExtensions.swift in Sources */,
38FE826A25CC82DB001FF17A /* NetworkService.swift in Sources */,
FE66D16B291F74F8005D6F77 /* Bundle+Extensions.swift in Sources */,
3883581C25EE79BB00E024B2 /* DecimalTextField.swift in Sources */,
3883581C25EE79BB00E024B2 /* TextFieldWithToolBar.swift in Sources */,
6B1A8D2E2B156EEF00E76752 /* LiveActivityBridge.swift in Sources */,
38DAB28A260D349500F74C1A /* FetchGlucoseManager.swift in Sources */,
38F37828261260DC009DB701 /* Color+Extensions.swift in Sources */,
Expand Down
49 changes: 22 additions & 27 deletions FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,34 @@ extension AddCarbs {
HStack {
Text("Carbs").fontWeight(.semibold)
Spacer()
DecimalTextField(
"0",
value: $state.carbs,
formatter: formatter,
autofocus: true,
cleanInput: true
TextFieldWithToolBar(
text: $state.carbs,
placeholder: "0",
shouldBecomeFirstResponder: true,
numberFormatter: formatter
)
Text(state.carbs > state.maxCarbs ? "⚠️" : "g").foregroundColor(.secondary)
}.padding(.vertical)

if state.useFPUconversion {
proteinAndFat()
}
HStack {
Text("Note").foregroundColor(.secondary)
TextField("", text: $state.note).multilineTextAlignment(.trailing)
if isFocused {
Button { isFocused = false } label: { Image(systemName: "keyboard.chevron.compact.down") }
.controlSize(.mini)
VStack {
HStack {
Text("Note").foregroundColor(.secondary)
TextFieldWithToolBarString(text: $state.note, placeholder: "", maxLength: 25)
if isFocused {
Button { isFocused = false } label: { Image(systemName: "keyboard.chevron.compact.down") }
.controlSize(.mini)
}
}.focused($isFocused)

HStack {
Spacer()
Text("\(state.note.count) / 25")
.foregroundStyle(.secondary)
}
}.focused($isFocused)
}
HStack {
Button {
state.useFPUconversion.toggle()
Expand Down Expand Up @@ -268,25 +275,13 @@ extension AddCarbs {
HStack {
Text("Fat").foregroundColor(.orange) // .fontWeight(.thin)
Spacer()
DecimalTextField(
"0",
value: $state.fat,
formatter: formatter,
autofocus: false,
cleanInput: true
)
TextFieldWithToolBar(text: $state.fat, placeholder: "0", numberFormatter: formatter)
Text(state.fat > state.maxFat ? "⚠️" : "g").foregroundColor(.secondary)
}
HStack {
Text("Protein").foregroundColor(.red) // .fontWeight(.thin)
Spacer()
DecimalTextField(
"0",
value: $state.protein,
formatter: formatter,
autofocus: false,
cleanInput: true
)
TextFieldWithToolBar(text: $state.protein, placeholder: "0", numberFormatter: formatter)
Text(state.protein > state.maxProtein ? "⚠️" : "g").foregroundColor(.secondary)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ extension AddTempTarget {
HStack {
Text("Target")
Spacer()
DecimalTextField("0", value: $state.low, formatter: formatter, cleanInput: true)
TextFieldWithToolBar(text: $state.low, placeholder: "0", numberFormatter: formatter)
Text(state.units.rawValue).foregroundColor(.secondary)
}
HStack {
Text("Duration")
Spacer()
DecimalTextField("0", value: $state.duration, formatter: formatter, cleanInput: true)
TextFieldWithToolBar(text: $state.duration, placeholder: "0", numberFormatter: formatter)
Text("minutes").foregroundColor(.secondary)
}
}
Expand All @@ -203,7 +203,7 @@ extension AddTempTarget {
HStack {
Text("Duration")
Spacer()
DecimalTextField("0", value: $state.duration, formatter: formatter, cleanInput: true)
TextFieldWithToolBar(text: $state.duration, placeholder: "0", numberFormatter: formatter)
Text("minutes").foregroundColor(.secondary)
}
}
Expand Down
11 changes: 5 additions & 6 deletions FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ extension Bolus {
HStack {
Text("Amount")
Spacer()
DecimalTextField(
"0",
value: $state.amount,
formatter: formatter,
autofocus: true,
cleanInput: true
TextFieldWithToolBar(
text: $state.amount,
placeholder: "0",
shouldBecomeFirstResponder: true,
numberFormatter: formatter
)
Text(state.amount > state.maxBolus ? "⚠️" : "U").foregroundColor(.secondary)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ extension Calibrations {
HStack {
Text("Meter glucose")
Spacer()
DecimalTextField(
"0",
value: $state.newCalibration,
formatter: formatter,
autofocus: false,
cleanInput: true
)
TextFieldWithToolBar(text: $state.newCalibration, placeholder: "0", numberFormatter: formatter)
Text(state.units.rawValue).foregroundColor(.secondary)
}
Button {
Expand Down
22 changes: 10 additions & 12 deletions FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ extension DataTable {
Section {
HStack {
Text("New Glucose")
DecimalTextField(
" ... ",
value: $state.manualGlucose,
formatter: glucoseFormatter,
autofocus: true,
cleanInput: true
TextFieldWithToolBar(
text: $state.manualGlucose,
placeholder: " ... ",
shouldBecomeFirstResponder: true,
numberFormatter: glucoseFormatter
)
Text(state.units.rawValue).foregroundStyle(.secondary)
}
Expand Down Expand Up @@ -253,12 +252,11 @@ extension DataTable {
HStack {
Text("Amount")
Spacer()
DecimalTextField(
"0",
value: $state.externalInsulinAmount,
formatter: insulinFormatter,
autofocus: true,
cleanInput: true
TextFieldWithToolBar(
text: $state.externalInsulinAmount,
placeholder: "0",
shouldBecomeFirstResponder: true,
numberFormatter: insulinFormatter
)
Text("U").foregroundColor(.secondary)
}
Expand Down
18 changes: 11 additions & 7 deletions FreeAPS/Sources/Modules/FPUConfig/View/FPUConfigRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,42 @@ extension FPUConfig {
Section(header: Text("Limit Per Entry")) {
HStack {
Text("Max Carbs")
DecimalTextField("g", value: $state.maxCarbs, formatter: formatter)
TextFieldWithToolBar(text: $state.maxCarbs, placeholder: "g", numberFormatter: formatter)
}
HStack {
Text("Max Fat")
DecimalTextField("g", value: $state.maxFat, formatter: formatter)
TextFieldWithToolBar(text: $state.maxFat, placeholder: "g", numberFormatter: formatter)
}
HStack {
Text("Max Protein")
DecimalTextField("g", value: $state.maxProtein, formatter: formatter)
TextFieldWithToolBar(text: $state.maxProtein, placeholder: "g", numberFormatter: formatter)
}
}

Section(header: Text("Fat and Protein Conversion Settings")) {
HStack {
Text("Delay In Minutes")
Spacer()
DecimalTextField("60", value: $state.delay, formatter: intFormater)
TextFieldWithToolBar(text: $state.delay, placeholder: "60", numberFormatter: intFormater)
}
HStack {
Text("Maximum Duration In Hours")
Spacer()
DecimalTextField("8", value: $state.timeCap, formatter: intFormater)
TextFieldWithToolBar(text: $state.timeCap, placeholder: "8", numberFormatter: intFormater)
}
HStack {
Text("Interval In Minutes")
Spacer()
DecimalTextField("30", value: $state.minuteInterval, formatter: intFormater)
TextFieldWithToolBar(text: $state.minuteInterval, placeholder: "30", numberFormatter: intFormater)
}
HStack {
Text("Override With A Factor Of ")
Spacer()
DecimalTextField("0.5", value: $state.individualAdjustmentFactor, formatter: conversionFormatter)
TextFieldWithToolBar(
text: $state.individualAdjustmentFactor,
placeholder: "0.5",
numberFormatter: conversionFormatter
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ extension ManualTempBasal {
HStack {
Text("Amount")
Spacer()
DecimalTextField("0", value: $state.rate, formatter: formatter, autofocus: true, cleanInput: true)
TextFieldWithToolBar(
text: $state.rate,
placeholder: "0",
shouldBecomeFirstResponder: true,
numberFormatter: formatter
)
Text("U/hr").foregroundColor(.secondary)
}
Picker(selection: $state.durationIndex, label: Text("Duration")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct NightscoutConnectView: View {
Toggle("Use local glucose server", isOn: $state.useLocalSource)
HStack {
Text("Port")
DecimalTextField("", value: $state.localPort, formatter: portFormater)
TextFieldWithToolBar(text: $state.localPort, placeholder: "", numberFormatter: portFormater)
}
} header: { Text("Local glucose source") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ extension NotificationsConfig {
HStack {
Text("Low")
Spacer()
DecimalTextField("0", value: $state.lowGlucose, formatter: glucoseFormatter)
TextFieldWithToolBar(text: $state.lowGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
Text(state.units.rawValue).foregroundColor(.secondary)
}

HStack {
Text("High")
Spacer()
DecimalTextField("0", value: $state.highGlucose, formatter: glucoseFormatter)
TextFieldWithToolBar(text: $state.highGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
Text(state.units.rawValue).foregroundColor(.secondary)
}
}
Expand All @@ -105,7 +105,11 @@ extension NotificationsConfig {
HStack {
Text("Carbs Required Threshold")
Spacer()
DecimalTextField("0", value: $state.carbsRequiredThreshold, formatter: carbsFormatter)
TextFieldWithToolBar(
text: $state.carbsRequiredThreshold,
placeholder: "0",
numberFormatter: carbsFormatter
)
Text("g").foregroundColor(.secondary)
}
}
Expand Down
Loading