Skip to content

Commit

Permalink
More work on the multi-segment tester app.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMarshallNY committed Aug 11, 2024
1 parent be9fbf3 commit a1c9d48
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 3 deletions.
193 changes: 193 additions & 0 deletions Tests/LGV_7_Segment_Group_Tester/LGV_7SGT_ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,88 @@ import UIKit
import LGV_7_Segment
import RVS_Generic_Swift_Toolbox

/* ###################################################################################################################################### */
// MARK: - Custom View for Displaying the Digit Set -
/* ###################################################################################################################################### */
/**
*/
class LGV_7SGT_DisplayView: UIView {

}

/* ###################################################################################################################################### */
// MARK: - Displays Multiple Segments, And Controls -
/* ###################################################################################################################################### */
/**
*/
class LGV_7SGT_ViewController: UIViewController {
/* ################################################################################################################################## */
// MARK: Enumeration for the Display Type Segmented Switch
/* ################################################################################################################################## */
/**
These are assignments for the integer indexes of the segmented control.
*/
enum DisplayTypes: Int {
/* ############################################################## */
/**
Only display the control outline.
*/
case outline

/* ############################################################## */
/**
Only display the mask
*/
case maskOnly

/* ############################################################## */
/**
Only display on segments
*/
case onOnly

/* ############################################################## */
/**
Only display off segments
*/
case offOnly

/* ############################################################## */
/**
Display everything except the mask.
*/
case all
}

/* ################################################################## */
/**
The label that displays the current value
*/
@IBOutlet weak var valueDisplayLabel: UILabel?

/* ################################################################## */
/**
A slider that affects the value shown on the display.
*/
@IBOutlet weak var valueSlider: UISlider?

/* ################################################################## */
/**
The digit display view
*/
@IBOutlet weak var displayView: LGV_7SGT_DisplayView?

/* ################################################################## */
/**
A segmented switch that affects the number of digits to display.
*/
@IBOutlet weak var digitCountSegmentedSwitch: UISegmentedControl?

/* ################################################################## */
/**
A segmented switch that affects what is displayed.
*/
@IBOutlet weak var displaySegmentedSwitch: UISegmentedControl?
}

/* ###################################################################################################################################### */
Expand All @@ -39,5 +115,122 @@ extension LGV_7SGT_ViewController {
*/
override func viewDidLoad() {
super.viewDidLoad()

guard let digitCountSegmentedSwitch = digitCountSegmentedSwitch else { return }

for index in 0..<digitCountSegmentedSwitch.numberOfSegments {
digitCountSegmentedSwitch.setTitle(String(format: "SLUG-COUNT-%d", index).localizedVariant, forSegmentAt: index)
}

let max = (displaySegmentedSwitch?.numberOfSegments ?? 0)

for index in 0..<max {
displaySegmentedSwitch?.setTitle(String(format: "SLUG-SWITCH-%d", index).localizedVariant, forSegmentAt: index)
}

guard let slider = valueSlider else { return }

digitCountSegmentedSwitchChanged(digitCountSegmentedSwitch)
valueSliderChanged(slider)
}

/* ################################################################## */
/**
Called when the value slider changes.

- parameter inSlider: The slider that changed.
*/
@IBAction func valueSliderChanged(_ inSlider: UISlider) {
let intValue = Int(round(inSlider.value))
inSlider.value = Float(intValue)
valueDisplayLabel?.text = String(intValue)
}

/* ################################################################## */
/**
Called when the segmented switch for the number of digits changes.

- parameter inSwitch: The switch that changed.
*/
@IBAction func digitCountSegmentedSwitchChanged(_ inSwitch: UISegmentedControl) {
valueSlider?.isEnabled = 0 < inSwitch.selectedSegmentIndex
valueDisplayLabel?.isHidden = 0 == inSwitch.selectedSegmentIndex

valueSlider?.value = Float(0)

switch inSwitch.selectedSegmentIndex {
case 1:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false
valueSlider?.minimumValue = Float(0)
valueSlider?.maximumValue = Float(15)

case 2:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false
valueSlider?.minimumValue = Float(-15)
valueSlider?.maximumValue = Float(15)

case 3:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false
valueSlider?.minimumValue = Float(-31)
valueSlider?.maximumValue = Float(31)

case 4:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false
valueSlider?.minimumValue = Float(-255)
valueSlider?.maximumValue = Float(255)

case 5:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false
valueSlider?.minimumValue = Float(-4095)
valueSlider?.maximumValue = Float(4095)

default:
valueSlider?.isEnabled = false
valueDisplayLabel?.isHidden = true
valueSlider?.minimumValue = Float(0)
valueSlider?.maximumValue = Float(0)
}

valueSlider?.sendActions(for: .valueChanged)
}

/* ################################################################## */
/**
Called when the segmented switch for the display changes.

- parameter inSwitch: The switch that changed.
*/
@IBAction func displaySegmentedSwitchChanged(_ inSwitch: UISegmentedControl) {
switch inSwitch.selectedSegmentIndex {
case DisplayTypes.outline.rawValue:
valueSlider?.isEnabled = false
valueDisplayLabel?.isHidden = true

case DisplayTypes.maskOnly.rawValue:
valueSlider?.isEnabled = false
valueDisplayLabel?.isHidden = true

case DisplayTypes.onOnly.rawValue:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false

case DisplayTypes.offOnly.rawValue:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false

case DisplayTypes.all.rawValue:
valueSlider?.isEnabled = true
valueDisplayLabel?.isHidden = false

default:
break
}

displayView?.setNeedsLayout()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand All @@ -11,17 +12,92 @@
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="LGV_7SGT_ViewController" customModule="LGV_7_Sement_Group_Tester" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="LGV_7SGT_ViewController" customModule="LGV_7_Segment_Group_Tester" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EyI-f8-J7b">
<rect key="frame" x="175.66666666666666" y="59" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="vvQ-sh-x43">
<rect key="frame" x="14" y="88" width="365" height="31"/>
<connections>
<action selector="valueSliderChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="pJ8-Wb-DGt"/>
</connections>
</slider>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XBx-Sz-IxC" customClass="LGV_7SGT_DisplayView" customModule="LGV_7_Segment_Group_Tester" customModuleProvider="target">
<rect key="frame" x="16" y="126" width="361" height="128"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="361" placeholder="YES" id="HkC-Kn-ccp"/>
<constraint firstAttribute="height" constant="128" placeholder="YES" id="hGr-aA-DHn"/>
</constraints>
</view>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="hok-nV-Fc6">
<rect key="frame" x="16" y="262" width="361" height="32"/>
<segments>
<segment title="SLUG-COUNT-0"/>
<segment title="SLUG-COUNT-1"/>
<segment title="SLUG-COUNT-2"/>
<segment title="SLUG-COUNT-3"/>
<segment title="SLUG-COUNT-4"/>
<segment title="SLUG-COUNT-5"/>
</segments>
<connections>
<action selector="digitCountSegmentedSwitchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="LSB-w0-8BX"/>
</connections>
</segmentedControl>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="4" translatesAutoresizingMaskIntoConstraints="NO" id="fjn-Ny-Wyb">
<rect key="frame" x="37" y="301" width="319" height="32"/>
<segments>
<segment title="Outline"/>
<segment title="Mask"/>
<segment title="On"/>
<segment title="Off"/>
<segment title="All"/>
</segments>
<connections>
<action selector="displaySegmentedSwitchChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="9qJ-1V-uvN"/>
</connections>
</segmentedControl>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="fjn-Ny-Wyb" secondAttribute="trailing" constant="16" id="0PM-pq-LLh"/>
<constraint firstItem="XBx-Sz-IxC" firstAttribute="top" secondItem="vvQ-sh-x43" secondAttribute="bottom" constant="8" symbolic="YES" id="1np-CH-73u"/>
<constraint firstItem="EyI-f8-J7b" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="5Cb-t0-lHY"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="hok-nV-Fc6" secondAttribute="trailing" constant="16" id="8LQ-tU-qqK"/>
<constraint firstItem="fjn-Ny-Wyb" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="KYH-Il-Buz"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="XBx-Sz-IxC" secondAttribute="trailing" constant="16" id="Le4-nW-MfJ"/>
<constraint firstItem="fjn-Ny-Wyb" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="T2R-wQ-A3l"/>
<constraint firstItem="XBx-Sz-IxC" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="VNf-Ah-0dw"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="fjn-Ny-Wyb" secondAttribute="bottom" id="ZtT-TR-gxP"/>
<constraint firstItem="EyI-f8-J7b" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="dSy-6p-ZIf"/>
<constraint firstItem="hok-nV-Fc6" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="ekw-Fe-rWc"/>
<constraint firstItem="hok-nV-Fc6" firstAttribute="top" secondItem="XBx-Sz-IxC" secondAttribute="bottom" constant="8" symbolic="YES" id="g0O-91-B0Y"/>
<constraint firstItem="fjn-Ny-Wyb" firstAttribute="top" secondItem="hok-nV-Fc6" secondAttribute="bottom" constant="8" id="h9E-Lc-JeL"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="vvQ-sh-x43" secondAttribute="trailing" constant="16" id="jQn-CV-tyo"/>
<constraint firstItem="XBx-Sz-IxC" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="l5U-cc-Aaj"/>
<constraint firstItem="vvQ-sh-x43" firstAttribute="top" secondItem="EyI-f8-J7b" secondAttribute="bottom" constant="8" symbolic="YES" id="lEE-4v-2Qn"/>
<constraint firstItem="vvQ-sh-x43" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="rbV-oF-XvH"/>
</constraints>
</view>
<connections>
<outlet property="digitCountSegmentedSwitch" destination="hok-nV-Fc6" id="Vt4-uM-HVf"/>
<outlet property="displaySegmentedSwitch" destination="fjn-Ny-Wyb" id="Qep-Z2-zel"/>
<outlet property="displayView" destination="XBx-Sz-IxC" id="hRx-F4-S0e"/>
<outlet property="valueDisplayLabel" destination="EyI-f8-J7b" id="WZb-1u-phN"/>
<outlet property="valueSlider" destination="vvQ-sh-x43" id="Z2d-jS-dAL"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="132" y="-34"/>
<point key="canvasLocation" x="130.53435114503816" y="-34.507042253521128"/>
</scene>
</scenes>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</slider>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="W4T-dd-WjV" customClass="LGV_7ST_DisplaySegment" customModule="LGV_7_Segment_Tester" customModuleProvider="target">
<rect key="frame" x="62.666666666666657" y="160" width="249.99999999999997" height="492"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" secondItem="W4T-dd-WjV" secondAttribute="height" multiplier="250:492" id="NU5-ti-Ypm"/>
<constraint firstAttribute="width" priority="999" constant="250" id="Wb6-hf-5wg"/>
Expand Down
7 changes: 7 additions & 0 deletions Tests/Test_Common/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@
"SLUG-SWITCH-2" = "On";
"SLUG-SWITCH-3" = "Off";
"SLUG-SWITCH-4" = "All";

"SLUG-COUNT-0" = "0 Digits";
"SLUG-COUNT-1" = "1 Digit";
"SLUG-COUNT-2" = "2 Digits";
"SLUG-COUNT-3" = "3 Digits";
"SLUG-COUNT-4" = "4 Digits";
"SLUG-COUNT-5" = "5 Digits";

0 comments on commit a1c9d48

Please sign in to comment.