Code Monkey home page Code Monkey logo

verticaltree's Introduction

Vertical Tree

Provides a vertical drawing of the tree structure and view information about the tree‘s nodes

安装

Podfile 添加

pod 'VerticalTree'
#或者只需要核心功能
pod 'VerticalTree/Core'
#只需要PrettyText
pod 'VerticalTree/PrettyText'

代码结构

——— VerticalTree
|——— Core 核心功能
| |——— VerticalTreeNodeProtocol
| |——— VerticalTreeNodeWrapper
|——— UI 绘制图形树(可折叠)
| |——— VerticalTreeCell
| |——— VerticalTreeIndexView
| |——— VerticalTreeListController
| |——— VerticalTreeListView
|——— PrettyText 终端文本树
| |——— VerticalTreePrettyPrint

主要协议

public protocol BaseTree {
    associatedtype T: BaseTree
    var parent: T? {get}
    var childs: [T] {get}
}

/// Node protocol
public protocol TreeNode: BaseTree {
    associatedtype U: TreeNode where Self.U == Self
    var parent: U? {get}
    var childs: [U] {get}

    /// note: deep start from 1
    var currentDeep: Int {get}

    /// note: minimum deep start from 1
    var treeDeep: Int {get}
    var index: Int {get}

    /// indexViewLegnth
    var length: TreeNodeLength {get}

    /// info description
    var info: Infomation {get}
    var isFold: Bool {set get}    
}

UIView 示范

UIView 的层级就是树状结构

  • 图形树绘制 (可折叠)
  • 文本树生成

用法

以UIView示范,让 UIView 遵守协议; 更多详见Demo(UIView,CALayer,UIViewController,自定义Node)

extension UIView: BaseTree {
    public var parent: UIView? {
        return superview
    }
    public var childs: [UIView] {
        return subviews
    }
}

然后 Wrapper 包装成 Node节点

// in ViewController
let rootNode = NodeWrapper(obj: view)
// 打印node结构
print(rootNode.currentTreePrettyPrintString())

使用 VerticalTree/PrettyText的UIView扩展更简单

extension BaseTree where Self: NSObject, Self == Self.T {
    // debug 可以查看更多信息
    @discardableResult public func prettyPrint(_ inDebug: Bool = false) -> String {
        return NodeWrapper(obj: self).currentTreePrettyPrintString().printIt()
    }
    public var getRoot: Self {
        let chain = sequence(first: self) { $0.parent }
        return chain.first { $0.parent == nil }!
    }
}
  • 打印当前View树结构

view.prettyPrint() 输入文本树如上:UIView示范

  • 打印当前Windows树结构

view.getRoot.prettyPrint()

  • 打印当前View树结构(查看更多debug信息)

view.prettyPrint(true)image

Author

XcodeYang, [email protected]

License

XYDebugView is available under the MIT license. See the LICENSE file for more info.

verticaltree's People

Contributors

zhipingyang avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.