-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add new Package PlantUMLEditor
- Loading branch information
1 parent
60d841c
commit 57c4543
Showing
8 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// swift-tools-version: 5.8 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "PlantUMLEditor", | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "PlantUMLEditor", | ||
targets: ["PlantUMLEditor"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "PlantUMLEditor", | ||
dependencies: []), | ||
.testTarget( | ||
name: "PlantUMLEditorTests", | ||
dependencies: ["PlantUMLEditor"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# PlantUMLEditor | ||
|
||
customization of project [CodeViewer](https://github.com/dwarvesf/CodeViewer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public struct PlantUMLEditor { | ||
public private(set) var text = "Hello, World!" | ||
|
||
public init() { | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
PlantUMLEditor/Tests/PlantUMLEditorTests/PlantUMLEditorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import XCTest | ||
@testable import PlantUMLEditor | ||
|
||
final class PlantUMLEditorTests: XCTestCase { | ||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct | ||
// results. | ||
XCTAssertEqual(PlantUMLEditor().text, "Hello, World!") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//: A UIKit based Playground for presenting user interface | ||
|
||
import UIKit | ||
import PlaygroundSupport | ||
|
||
import UIKit | ||
|
||
class LineNumberedTextView: UITextView { | ||
private let lineNumberLabel: UILabel = { | ||
let label = UILabel() | ||
label.backgroundColor = .lightGray | ||
label.textColor = .darkGray | ||
label.textAlignment = .center | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
return label | ||
}() | ||
|
||
override func layoutSubviews() { | ||
super.layoutSubviews() | ||
updateLineNumberLabel() | ||
} | ||
|
||
private func updateLineNumberLabel() { | ||
let layoutManager = self.layoutManager | ||
let textContainer = self.textContainer | ||
let textStorage = self.textStorage | ||
|
||
let visibleRect = self.bounds | ||
let visibleRange = layoutManager.characterRange(forGlyphRange: layoutManager.glyphRange(forBoundingRect: visibleRect, in: textContainer), actualGlyphRange: nil) | ||
|
||
let firstVisibleGlyphCharacterIndex = visibleRange.location | ||
let lastVisibleGlyphCharacterIndex = NSMaxRange(visibleRange) | ||
|
||
var lineNumberRect = CGRect.zero | ||
layoutManager.enumerateLineFragments(forGlyphRange: visibleRange) { (rect, usedRect, textContainer, glyphRange, stop) in | ||
let characterRange = layoutManager.characterRange(forGlyphRange: glyphRange, actualGlyphRange: nil) | ||
let lineText = (self.text as NSString).substring(with: characterRange) | ||
let lineNumber = 1 // layoutManager.lineNumber(for: glyphRange) | ||
|
||
let lineNumberGlyphRange = layoutManager.glyphRange( | ||
forCharacterRange: characterRange, | ||
actualCharacterRange: nil) | ||
let lineNumberRect = layoutManager.boundingRect(forGlyphRange: lineNumberGlyphRange, in: textContainer) | ||
let lineNumberLabelRect = CGRect(x: 0, y: lineNumberRect.origin.y, width: 30, height: lineNumberRect.size.height) | ||
|
||
if let lineNumberLabel = self.lineNumberLabel.copy() as? UILabel { | ||
lineNumberLabel.text = "\(lineNumber)" | ||
lineNumberLabel.frame = lineNumberLabelRect | ||
self.addSubview(lineNumberLabel) | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
class MyViewController : UIViewController { | ||
|
||
override func loadView() { | ||
|
||
let v = LineNumberedTextView() | ||
v.backgroundColor = .white | ||
v.text = "Hello\nWorld\nLine\nNumbers" | ||
view = v | ||
} | ||
|
||
override func viewDidLoad() { | ||
|
||
} | ||
} | ||
// Present the view controller in the Live View window | ||
PlaygroundPage.current.liveView = MyViewController() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |