From a5344abeb0211849f8df889be1f161f73fd550de Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sun, 7 Feb 2021 13:00:48 -0800 Subject: [PATCH] Hides elements on monster detail if they don't have values to show. Adds TODO to hide dividers when applicable. --- MonsterCards/Views/MonsterDetail.swift | 45 ++++++++++++++++++-------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/MonsterCards/Views/MonsterDetail.swift b/MonsterCards/Views/MonsterDetail.swift index 0063edd..438d148 100644 --- a/MonsterCards/Views/MonsterDetail.swift +++ b/MonsterCards/Views/MonsterDetail.swift @@ -68,24 +68,43 @@ struct MonsterDetail: View { var body: some View { ScrollView { VStack (alignment: .leading) { - // meta: "(large humanoid (elf) lawful evil" - Text(monster.meta) - .font(.subheadline) - .foregroundColor(.secondary) - + let monsterMeta = monster.meta + let monsterArmorClassDescription = monster.armorClassDescription + let monsterHitPoints = monster.hitPoints + let monsterSpeed = monster.speed + + if (!monsterMeta.isEmpty) { + // meta: "(large humanoid (elf) lawful evil" + Text(monsterMeta) + .font(.subheadline) + .foregroundColor(.secondary) + } + + // TODO: Find a way to hide unnecessarry dividiers. + // if sections 0, 1, 2, and 3 are present there should be a divider between each of them + // if section 1 is not present there should be one and only one divider between sections 0 and 2 as well as the one between 2 and 3 + // if sections 1 and 2 are not present there should be a single divider between sections 0 and 3 SectionDivider() - // AC - LabeledField("Armor Class") { - Text(monster.armorClassDescription)// armor class + if (!monsterArmorClassDescription.isEmpty) { + // AC + LabeledField("Armor Class") { + Text(monsterArmorClassDescription)// armor class + } } - // HP - LabeledField("Hit Points") { - Text(monster.hitPoints) // hit points + + if (!monsterHitPoints.isEmpty) { + // HP + LabeledField("Hit Points") { + Text(monsterHitPoints) // hit points + } } + // Speed - LabeledField("Speed") { - Text(monster.speed) // speed + if (!monsterSpeed.isEmpty) { + LabeledField("Speed") { + Text(monsterSpeed) // speed + } } SectionDivider()