From f64c7509b39b5cb50c2ecf71be4077b131e3b6f8 Mon Sep 17 00:00:00 2001 From: Gerriet Backer Date: Wed, 7 Mar 2018 17:15:43 +0100 Subject: [PATCH 1/6] Allow setting button visibility For one or for all buttons via setButton() --- Lumina/Lumina/UI/LuminaButton.swift | 2 +- Lumina/Lumina/UI/LuminaViewController.swift | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Lumina/Lumina/UI/LuminaButton.swift b/Lumina/Lumina/UI/LuminaButton.swift index 29374e3..7076088 100644 --- a/Lumina/Lumina/UI/LuminaButton.swift +++ b/Lumina/Lumina/UI/LuminaButton.swift @@ -8,7 +8,7 @@ import UIKit -enum SystemButtonType { +public enum SystemButtonType { enum FlashState { //swiftlint:disable identifier_name case on diff --git a/Lumina/Lumina/UI/LuminaViewController.swift b/Lumina/Lumina/UI/LuminaViewController.swift index 7446e15..16f7817 100644 --- a/Lumina/Lumina/UI/LuminaViewController.swift +++ b/Lumina/Lumina/UI/LuminaViewController.swift @@ -202,6 +202,30 @@ public final class LuminaViewController: UIViewController { self.camera?.frameRate = frameRate } } + + /// Set visibility for *one* button + public func setButton(button: SystemButtonType, visible: Bool) { + switch button { + case .cancel: + cancelButton.isHidden = !visible + case .torch: + torchButton.isHidden = !visible + case .shutter: + shutterButton.isHidden = !visible + case .cameraSwitch: + switchButton.isHidden = !visible + case .photoCapture: + break + } + } + + /// Set visibility for *all* buttons + public func setButton(visible: Bool) { + setButton(button: .cancel, visible: visible) + setButton(button: .torch, visible: visible) + setButton(button: .shutter, visible: visible) + setButton(button: .cameraSwitch, visible: visible) + } /// A collection of model types that will be used when streaming images for object recognition /// From 6364680a94120fe43e8079eb4d5fa6888ee5099f Mon Sep 17 00:00:00 2001 From: Gerriet Backer Date: Mon, 12 Mar 2018 11:43:59 +0100 Subject: [PATCH 2/6] Buttons made public to allow visiblity setting Class LuminaButton is now public as well as instances in LuminaViewController. --- Lumina/Lumina/UI/LuminaButton.swift | 6 ++-- Lumina/Lumina/UI/LuminaViewController.swift | 34 ++++++--------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/Lumina/Lumina/UI/LuminaButton.swift b/Lumina/Lumina/UI/LuminaButton.swift index 7076088..9ee5c8a 100644 --- a/Lumina/Lumina/UI/LuminaButton.swift +++ b/Lumina/Lumina/UI/LuminaButton.swift @@ -23,7 +23,7 @@ public enum SystemButtonType { case shutter } -final class LuminaButton: UIButton { +public final class LuminaButton: UIButton { private var squareSystemButtonWidth = 40 private var squareSystemButtonHeight = 40 private var cancelButtonWidth = 70 @@ -53,7 +53,7 @@ final class LuminaButton: UIButton { } } - required init() { + public required init() { super.init(frame: CGRect.zero) self.backgroundColor = UIColor.clear if let titleLabel = self.titleLabel { @@ -149,7 +149,7 @@ final class LuminaButton: UIButton { } } - required init?(coder aDecoder: NSCoder) { + public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } } diff --git a/Lumina/Lumina/UI/LuminaViewController.swift b/Lumina/Lumina/UI/LuminaViewController.swift index 16f7817..5f0c762 100644 --- a/Lumina/Lumina/UI/LuminaViewController.swift +++ b/Lumina/Lumina/UI/LuminaViewController.swift @@ -60,7 +60,7 @@ public final class LuminaViewController: UIViewController { } private var _cancelButton: LuminaButton? - var cancelButton: LuminaButton { + public var cancelButton: LuminaButton { if let currentButton = _cancelButton { return currentButton } @@ -71,7 +71,7 @@ public final class LuminaViewController: UIViewController { } private var _shutterButton: LuminaButton? - var shutterButton: LuminaButton { + public var shutterButton: LuminaButton { if let currentButton = _shutterButton { return currentButton } @@ -83,7 +83,7 @@ public final class LuminaViewController: UIViewController { } private var _switchButton: LuminaButton? - var switchButton: LuminaButton { + public var switchButton: LuminaButton { if let currentButton = _switchButton { return currentButton } @@ -94,7 +94,7 @@ public final class LuminaViewController: UIViewController { } private var _torchButton: LuminaButton? - var torchButton: LuminaButton { + public var torchButton: LuminaButton { if let currentButton = _torchButton { return currentButton } @@ -202,29 +202,13 @@ public final class LuminaViewController: UIViewController { self.camera?.frameRate = frameRate } } - - /// Set visibility for *one* button - public func setButton(button: SystemButtonType, visible: Bool) { - switch button { - case .cancel: - cancelButton.isHidden = !visible - case .torch: - torchButton.isHidden = !visible - case .shutter: - shutterButton.isHidden = !visible - case .cameraSwitch: - switchButton.isHidden = !visible - case .photoCapture: - break - } - } - + /// Set visibility for *all* buttons public func setButton(visible: Bool) { - setButton(button: .cancel, visible: visible) - setButton(button: .torch, visible: visible) - setButton(button: .shutter, visible: visible) - setButton(button: .cameraSwitch, visible: visible) + cancelButton.isHidden = !visible + torchButton.isHidden = !visible + shutterButton.isHidden = !visible + switchButton.isHidden = !visible } /// A collection of model types that will be used when streaming images for object recognition From b200f95415701ccc286621d1b92501b9c777c9a9 Mon Sep 17 00:00:00 2001 From: Gerriet Backer Date: Mon, 12 Mar 2018 11:45:13 +0100 Subject: [PATCH 3/6] Convenience function setButton removed For setting the visibility of all buttons --- Lumina/Lumina/UI/LuminaViewController.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Lumina/Lumina/UI/LuminaViewController.swift b/Lumina/Lumina/UI/LuminaViewController.swift index 5f0c762..29dd359 100644 --- a/Lumina/Lumina/UI/LuminaViewController.swift +++ b/Lumina/Lumina/UI/LuminaViewController.swift @@ -202,14 +202,6 @@ public final class LuminaViewController: UIViewController { self.camera?.frameRate = frameRate } } - - /// Set visibility for *all* buttons - public func setButton(visible: Bool) { - cancelButton.isHidden = !visible - torchButton.isHidden = !visible - shutterButton.isHidden = !visible - switchButton.isHidden = !visible - } /// A collection of model types that will be used when streaming images for object recognition /// From 3d6449265e57362eec76d7ce225f72f240df1144 Mon Sep 17 00:00:00 2001 From: Gerriet Backer Date: Mon, 26 Mar 2018 15:09:03 +0200 Subject: [PATCH 4/6] Button visibility controlled via dedicated functions for each button Reverted previous approaches (buttons are no longer public) --- Lumina/Lumina/UI/LuminaButton.swift | 8 +++---- Lumina/Lumina/UI/LuminaViewController.swift | 25 +++++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Lumina/Lumina/UI/LuminaButton.swift b/Lumina/Lumina/UI/LuminaButton.swift index 9ee5c8a..29374e3 100644 --- a/Lumina/Lumina/UI/LuminaButton.swift +++ b/Lumina/Lumina/UI/LuminaButton.swift @@ -8,7 +8,7 @@ import UIKit -public enum SystemButtonType { +enum SystemButtonType { enum FlashState { //swiftlint:disable identifier_name case on @@ -23,7 +23,7 @@ public enum SystemButtonType { case shutter } -public final class LuminaButton: UIButton { +final class LuminaButton: UIButton { private var squareSystemButtonWidth = 40 private var squareSystemButtonHeight = 40 private var cancelButtonWidth = 70 @@ -53,7 +53,7 @@ public final class LuminaButton: UIButton { } } - public required init() { + required init() { super.init(frame: CGRect.zero) self.backgroundColor = UIColor.clear if let titleLabel = self.titleLabel { @@ -149,7 +149,7 @@ public final class LuminaButton: UIButton { } } - public required init?(coder aDecoder: NSCoder) { + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } } diff --git a/Lumina/Lumina/UI/LuminaViewController.swift b/Lumina/Lumina/UI/LuminaViewController.swift index 29dd359..e893fba 100644 --- a/Lumina/Lumina/UI/LuminaViewController.swift +++ b/Lumina/Lumina/UI/LuminaViewController.swift @@ -60,7 +60,7 @@ public final class LuminaViewController: UIViewController { } private var _cancelButton: LuminaButton? - public var cancelButton: LuminaButton { + var cancelButton: LuminaButton { if let currentButton = _cancelButton { return currentButton } @@ -71,7 +71,7 @@ public final class LuminaViewController: UIViewController { } private var _shutterButton: LuminaButton? - public var shutterButton: LuminaButton { + var shutterButton: LuminaButton { if let currentButton = _shutterButton { return currentButton } @@ -83,7 +83,7 @@ public final class LuminaViewController: UIViewController { } private var _switchButton: LuminaButton? - public var switchButton: LuminaButton { + var switchButton: LuminaButton { if let currentButton = _switchButton { return currentButton } @@ -94,7 +94,7 @@ public final class LuminaViewController: UIViewController { } private var _torchButton: LuminaButton? - public var torchButton: LuminaButton { + var torchButton: LuminaButton { if let currentButton = _torchButton { return currentButton } @@ -203,6 +203,23 @@ public final class LuminaViewController: UIViewController { } } + /// Setting visibility of the buttons (default: all buttons are visible) + public func setCancelButton(visible: Bool) { + cancelButton.isHidden = !visible + } + + public func setShutterButton(visible: Bool) { + shutterButton.isHidden = !visible + } + + public func setSwitchButton(visible: Bool) { + switchButton.isHidden = !visible + } + + public func setTorchButton(visible: Bool) { + torchButton.isHidden = !visible + } + /// A collection of model types that will be used when streaming images for object recognition /// /// - Note: Only works on iOS 11 and up From 64d8093f6050e6df641b0c8501adb66cbd6ae5b1 Mon Sep 17 00:00:00 2001 From: Gerriet Backer Date: Mon, 26 Mar 2018 15:16:44 +0200 Subject: [PATCH 5/6] Fixed whitespace --- Lumina/Lumina/UI/LuminaViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lumina/Lumina/UI/LuminaViewController.swift b/Lumina/Lumina/UI/LuminaViewController.swift index e893fba..6716867 100644 --- a/Lumina/Lumina/UI/LuminaViewController.swift +++ b/Lumina/Lumina/UI/LuminaViewController.swift @@ -207,7 +207,7 @@ public final class LuminaViewController: UIViewController { public func setCancelButton(visible: Bool) { cancelButton.isHidden = !visible } - + public func setShutterButton(visible: Bool) { shutterButton.isHidden = !visible } @@ -215,11 +215,11 @@ public final class LuminaViewController: UIViewController { public func setSwitchButton(visible: Bool) { switchButton.isHidden = !visible } - + public func setTorchButton(visible: Bool) { torchButton.isHidden = !visible } - + /// A collection of model types that will be used when streaming images for object recognition /// /// - Note: Only works on iOS 11 and up From a982f7ec6feb527177d0e5d562759a4c97f165ff Mon Sep 17 00:00:00 2001 From: Gerriet Backer Date: Thu, 29 Mar 2018 18:11:31 +0200 Subject: [PATCH 6/6] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit added „Changing the user interface“ --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 22ab045..5975721 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,19 @@ func streamed(videoFrame: UIImage, with predictions: [LuminaRecognitionResult]?, Note that this returns a class type representation associated with the detected results. The example above also makes use of the built-in text prompt mechanism for Lumina. +### Changing the user interface + +To adapt the user interface to your needs, you can set the visibility of the buttons by calling these methods on `LuminaViewController`: + +```swift +camera.setCancelButton(visible: Bool) +camera.setShutterButton(visible: Bool) +camera.setSwitchButton(visible: Bool) +camera.setTorchButton(visible: Bool) +``` + +Per default, all of the buttons are visible. + ## Maintainers - David Okun [![Twitter Follow](https://img.shields.io/twitter/follow/dokun24.svg?style=social&label=Follow)](https://twitter.com/dokun24) [![GitHub followers](https://img.shields.io/github/followers/dokun1.svg?style=social&label=Follow)](https://github.com/dokun1)