Skip to content

Commit

Permalink
build: add new Package PlantUMLEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Aug 20, 2023
1 parent 60d841c commit 57c4543
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PlantUMLApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
A01552A228CF47DF00F2B8A1 /* PlantUMLFramework */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLFramework; sourceTree = "<group>"; };
A01907EF2951CD5C0059CCBE /* privacy_policy.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = privacy_policy.md; sourceTree = "<group>"; };
A036CC402A0FC67C003FDB5E /* PlantUMLAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PlantUMLAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A036CF972A92BCFF007FDEB6 /* PlantUMLEditor */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLEditor; sourceTree = "<group>"; };
A038DB5B29D452880032E312 /* OpenAI.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = OpenAI.xcconfig; sourceTree = "<group>"; };
A038DB5F29D489BA0032E312 /* PlantUML+OpenAI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PlantUML+OpenAI.swift"; sourceTree = "<group>"; };
A047206E29549ACC007E061F /* SwiftUI+Share.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+Share.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -157,6 +158,7 @@
A0D3C63D28984A0E000838D7 = {
isa = PBXGroup;
children = (
A036CF972A92BCFF007FDEB6 /* PlantUMLEditor */,
A05F2E372A1FFC49007FDF36 /* CHANGELOG.md */,
A074F6982A16D40500061398 /* OpenAI.prod.xcconfig */,
A038DB5B29D452880032E312 /* OpenAI.xcconfig */,
Expand Down
9 changes: 9 additions & 0 deletions PlantUMLEditor/.gitignore
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
28 changes: 28 additions & 0 deletions PlantUMLEditor/Package.swift
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"]),
]
)
3 changes: 3 additions & 0 deletions PlantUMLEditor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PlantUMLEditor

customization of project [CodeViewer](https://github.com/dwarvesf/CodeViewer)
6 changes: 6 additions & 0 deletions PlantUMLEditor/Sources/PlantUMLEditor/PlantUMLEditor.swift
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 PlantUMLEditor/Tests/PlantUMLEditorTests/PlantUMLEditorTests.swift
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!")
}
}
71 changes: 71 additions & 0 deletions TextEditorView.playground/Contents.swift
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()
4 changes: 4 additions & 0 deletions TextEditorView.playground/contents.xcplayground
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>

0 comments on commit 57c4543

Please sign in to comment.