aboutsummaryrefslogtreecommitdiff
path: root/Sources/SwiftLVGL/Widgets
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/SwiftLVGL/Widgets')
-rw-r--r--Sources/SwiftLVGL/Widgets/LVGLButton.swift40
-rw-r--r--Sources/SwiftLVGL/Widgets/LVGLLabel.swift30
-rw-r--r--Sources/SwiftLVGL/Widgets/LVGLSlider.swift41
-rw-r--r--Sources/SwiftLVGL/Widgets/LVGLSpinner.swift36
-rw-r--r--Sources/SwiftLVGL/Widgets/LVGLSwitch.swift41
5 files changed, 96 insertions, 92 deletions
diff --git a/Sources/SwiftLVGL/Widgets/LVGLButton.swift b/Sources/SwiftLVGL/Widgets/LVGLButton.swift
index 62b1659..694b764 100644
--- a/Sources/SwiftLVGL/Widgets/LVGLButton.swift
+++ b/Sources/SwiftLVGL/Widgets/LVGLButton.swift
@@ -12,27 +12,27 @@ public protocol LVGLButtonProtocol: LVGLObjectProtocol {
}
public struct LVGLButton: LVGLButtonProtocol {
- public let label: LVGLLabel
- public var pointer: UnsafeMutablePointer<lv_obj_t>?
-
- public init(
- _ text: String, alignment: LVAlignment = .center, textColor: Color = .blue,
- xSize: Int32 = 120, ySize: Int32 = 50, xOffset: Int32 = 0, yOffset: Int32 = 0,
- eventType: LVEventCode = .all,
- callback: @escaping (UnsafeMutablePointer<lv_event_t>?) -> Void = { _ in }
- ) {
- guard let button = lv_button_create(lv_screen_active()) else {
- fatalError("Failed to create button")
- }
- self.pointer = button
- self.label = LVGLLabel(
- text, alignment: alignment, xOffset: xOffset, yOffset: yOffset
- )
- self.label.setParent(parentPointer: pointer!)
- align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
- setSize(width: xSize, height: ySize)
- setCallback(eventType: eventType, callback)
+ public let label: LVGLLabel
+ public var pointer: UnsafeMutablePointer<lv_obj_t>?
+ public init(
+ _ text: String, alignment: LVAlignment = .center, textColor: Color = .blue,
+ xSize: Int32 = 120, ySize: Int32 = 50, xOffset: Int32 = 0, yOffset: Int32 = 0,
+ eventType: LVEventCode = .all,
+ callback: @escaping (UnsafeMutablePointer<lv_event_t>?) -> Void = { _ in }
+ ) {
+ guard let button = lv_button_create(lv_screen_active()) else {
+ fatalError("Failed to create button")
}
+ self.pointer = button
+ self.label = LVGLLabel(
+ text, alignment: alignment, xOffset: xOffset, yOffset: yOffset
+ )
+ self.label.setParent(parentPointer: pointer!)
+ align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
+ setSize(width: xSize, height: ySize)
+ setCallback(eventType: eventType, callback)
+
+ }
}
diff --git a/Sources/SwiftLVGL/Widgets/LVGLLabel.swift b/Sources/SwiftLVGL/Widgets/LVGLLabel.swift
index 792144d..070da16 100644
--- a/Sources/SwiftLVGL/Widgets/LVGLLabel.swift
+++ b/Sources/SwiftLVGL/Widgets/LVGLLabel.swift
@@ -1,6 +1,6 @@
//
// LVGLLabel.swift
-//
+//
//
// Created by Navan Chauhan on 8/9/24.
//
@@ -8,24 +8,26 @@
import CLVGL
public protocol LVGLLabelProtocol: LVGLObjectProtocol {
- func setText(_ text: String)
+ func setText(_ text: String)
}
public struct LVGLLabel: LVGLLabelProtocol {
- public var pointer: UnsafeMutablePointer<lv_obj_t>?
+ public var pointer: UnsafeMutablePointer<lv_obj_t>?
- public init(_ text: String, alignment: LVAlignment = .center, xOffset: Int32 = 0, yOffset: Int32 = 0) {
- guard let label = lv_label_create(lv_screen_active()) else {
- fatalError("Failed to create label")
- }
- self.pointer = label
- setText(text)
- align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
+ public init(
+ _ text: String, alignment: LVAlignment = .center, xOffset: Int32 = 0, yOffset: Int32 = 0
+ ) {
+ guard let label = lv_label_create(lv_screen_active()) else {
+ fatalError("Failed to create label")
}
+ self.pointer = label
+ setText(text)
+ align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
+ }
- public func setText(_ text: String) {
- text.withCString { cString in
- lv_label_set_text(pointer, cString)
- }
+ public func setText(_ text: String) {
+ text.withCString { cString in
+ lv_label_set_text(pointer, cString)
}
+ }
}
diff --git a/Sources/SwiftLVGL/Widgets/LVGLSlider.swift b/Sources/SwiftLVGL/Widgets/LVGLSlider.swift
index 3a7abcc..c397b4e 100644
--- a/Sources/SwiftLVGL/Widgets/LVGLSlider.swift
+++ b/Sources/SwiftLVGL/Widgets/LVGLSlider.swift
@@ -1,6 +1,6 @@
//
// LVGLSlider.swift
-//
+//
//
// Created by Navan Chauhan on 8/9/24.
//
@@ -8,31 +8,30 @@
import CLVGL
public protocol LVGLSliderProtocol: LVGLObjectProtocol {
- func setValue(value: Int32, enableAnimation: Bool)
+ func setValue(value: Int32, enableAnimation: Bool)
}
public struct LVGLSlider: LVGLSliderProtocol {
- public let label: LVGLLabel
- public var pointer: UnsafeMutablePointer<lv_obj_t>?
-
- public init(
- _ text: String = "0%", alignment: LVAlignment = .center, xOffset: Int32 = 0,
- yOffset: Int32 = 0
- ) {
- guard let slider = lv_slider_create(lv_screen_active()) else {
- fatalError("Failed to create slider")
- }
- self.pointer = slider
- self.label = LVGLLabel(text, alignment: alignment)
-
- align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
-
- self.label.setParent(parentPointer: slider)
+ public let label: LVGLLabel
+ public var pointer: UnsafeMutablePointer<lv_obj_t>?
+
+ public init(
+ _ text: String = "0%", alignment: LVAlignment = .center, xOffset: Int32 = 0,
+ yOffset: Int32 = 0
+ ) {
+ guard let slider = lv_slider_create(lv_screen_active()) else {
+ fatalError("Failed to create slider")
}
+ self.pointer = slider
+ self.label = LVGLLabel(text, alignment: alignment)
- public func setValue(value: Int32 = 0, enableAnimation: Bool = true) {
+ align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
- }
+ self.label.setParent(parentPointer: slider)
+ }
-}
+ public func setValue(value: Int32 = 0, enableAnimation: Bool = true) {
+ }
+
+}
diff --git a/Sources/SwiftLVGL/Widgets/LVGLSpinner.swift b/Sources/SwiftLVGL/Widgets/LVGLSpinner.swift
index 9a97bb2..2650b07 100644
--- a/Sources/SwiftLVGL/Widgets/LVGLSpinner.swift
+++ b/Sources/SwiftLVGL/Widgets/LVGLSpinner.swift
@@ -1,6 +1,6 @@
//
// LVGLSpinner.swift
-//
+//
//
// Created by Navan Chauhan on 8/9/24.
//
@@ -8,27 +8,27 @@
import CLVGL
public protocol LVGLSpinnerProtocol: LVGLObjectProtocol {
- func setAnimation(animationTime: UInt32, arcAngle: UInt32)
+ func setAnimation(animationTime: UInt32, arcAngle: UInt32)
}
public struct LVGLSpinner: LVGLSpinnerProtocol {
- public var pointer: UnsafeMutablePointer<lv_obj_t>?
+ public var pointer: UnsafeMutablePointer<lv_obj_t>?
- public init(
- animationTime: UInt32 = 100,
- arcAngle: UInt32 = 200, alignment: LVAlignment = .center, xSize: UInt32 = 100,
- ySize: UInt32 = 100
- ) {
- guard let spinner = lv_spinner_create(lv_screen_active()) else {
- fatalError("Failed to create spinner")
- }
- self.pointer = spinner
- align(alignment: alignment)
- setSize(width: 100, height: 100)
- lv_spinner_set_anim_params(spinner, 1000, 200)
+ public init(
+ animationTime: UInt32 = 100,
+ arcAngle: UInt32 = 200, alignment: LVAlignment = .center, xSize: UInt32 = 100,
+ ySize: UInt32 = 100
+ ) {
+ guard let spinner = lv_spinner_create(lv_screen_active()) else {
+ fatalError("Failed to create spinner")
}
+ self.pointer = spinner
+ align(alignment: alignment)
+ setSize(width: 100, height: 100)
+ lv_spinner_set_anim_params(spinner, 1000, 200)
+ }
- public func setAnimation(animationTime: UInt32 = 1000, arcAngle: UInt32 = 200) {
- lv_spinner_set_anim_params(pointer, animationTime, arcAngle)
- }
+ public func setAnimation(animationTime: UInt32 = 1000, arcAngle: UInt32 = 200) {
+ lv_spinner_set_anim_params(pointer, animationTime, arcAngle)
+ }
}
diff --git a/Sources/SwiftLVGL/Widgets/LVGLSwitch.swift b/Sources/SwiftLVGL/Widgets/LVGLSwitch.swift
index a3580d1..c2c4263 100644
--- a/Sources/SwiftLVGL/Widgets/LVGLSwitch.swift
+++ b/Sources/SwiftLVGL/Widgets/LVGLSwitch.swift
@@ -1,6 +1,6 @@
//
// LVGLSwitch.swift
-//
+//
//
// Created by Navan Chauhan on 8/9/24.
//
@@ -8,18 +8,21 @@
import CLVGL
public protocol LVGLSwitchProtocol: LVGLObjectProtocol {
- var checked: Bool { get set}
- func isChecked() -> Bool
- mutating func setChecked(_ to: Bool)
+ var checked: Bool { get set }
+ func isChecked() -> Bool
+ mutating func setChecked(_ to: Bool)
}
public struct LVGLSwitch: LVGLSwitchProtocol {
- public var checked: Bool
- public var pointer: UnsafeMutablePointer<lv_obj_t>?
+ public var checked: Bool
+ public var pointer: UnsafeMutablePointer<lv_obj_t>?
- public init(_ checked: Bool = false, alignment: LVAlignment = .center, xOffset: Int32 = 0, yOffset: Int32 = 0) {
+ public init(
+ _ checked: Bool = false, alignment: LVAlignment = .center, xOffset: Int32 = 0,
+ yOffset: Int32 = 0
+ ) {
guard let mySwitch = lv_switch_create(lv_screen_active()) else {
- fatalError("Failed to create switch")
+ fatalError("Failed to create switch")
}
self.pointer = mySwitch
self.checked = checked
@@ -27,18 +30,18 @@ public struct LVGLSwitch: LVGLSwitchProtocol {
align(alignment: alignment, xOffset: xOffset, yOffset: yOffset)
setChecked(checked)
- }
+ }
- public func isChecked() -> Bool {
- return checked
- }
+ public func isChecked() -> Bool {
+ return checked
+ }
- mutating public func setChecked(_ to: Bool) {
- if (to) {
- lv_obj_add_state(pointer, 1)
- } else {
- lv_obj_remove_state(pointer, 1)
- }
- self.checked = to
+ mutating public func setChecked(_ to: Bool) {
+ if to {
+ lv_obj_add_state(pointer, 1)
+ } else {
+ lv_obj_remove_state(pointer, 1)
}
+ self.checked = to
+ }
}