123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- //
- // KMNBotaAnnotationHeaderView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/12/6.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNSectionHeaderView: NSView {
- private lazy var contentBox_: NSBox = {
- let view = NSBox()
- view.boxType = .custom
- view.titlePosition = .noTitle
- view.contentViewMargins = .zero
- view.borderWidth = 0
- return view
- }()
- private lazy var expandButton_: NSButton = {
- let view = NSButton()
- view.isBordered = false
- view.imagePosition = .imageOnly
- return view
- }()
- private lazy var titleLabel_: NSTextField = {
- let view = NSTextField(labelWithString: "")
- return view
- }()
- private lazy var numLabel_: NSTextField = {
- let view = NSTextField(labelWithString: "")
- return view
- }()
-
- private var leftConst_: NSLayoutConstraint?
- private var topConst_: NSLayoutConstraint?
- private var rightConst_: NSLayoutConstraint?
- private var bottomConst_: NSLayoutConstraint?
-
- var expandButton: NSButton {
- get {
- return expandButton_
- }
- }
- var titleLabel: NSTextField {
- get {
- return titleLabel_
- }
- }
- var numLabel: NSTextField {
- get {
- return numLabel_
- }
- }
-
- var contentInset: NSEdgeInsets = .init(top: 0, left: 0, bottom: 0, right: 0) {
- didSet {
- leftConst_?.constant = contentInset.left
- topConst_?.constant = contentInset.top
- rightConst_?.constant = -contentInset.right
- bottomConst_?.constant = -contentInset.bottom
- }
- }
-
- var itemClick: KMCommonClickBlock?
-
- convenience init() {
- self.init(frame: .init(x: 0, y: 0, width: 10, height: 10))
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- initSubviews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- initSubviews()
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- initSubviews()
- }
-
- func initSubviews() {
- addSubview(contentBox_)
- leftConst_ = contentBox_.km_add_leading_constraint_r()
- rightConst_ = contentBox_.km_add_trailing_constraint_r()
- topConst_ = contentBox_.km_add_top_constraint_r()
- bottomConst_ = contentBox_.km_add_bottom_constraint_r()
-
- let wh: CGFloat = 16
- let vspace: CGFloat = 8
- contentBox_.contentView?.addSubview(expandButton)
- expandButton.km_add_leading_constraint()
- expandButton.km_add_size_constraint(size: .init(width: wh, height: wh))
- expandButton.km_add_centerY_constraint()
-
- contentBox_.contentView?.addSubview(titleLabel)
- titleLabel.km_add_centerY_constraint()
- titleLabel.km_add_leading_constraint(equalTo: expandButton, attribute: .trailing, constant: 2 * vspace)
-
- contentBox_.contentView?.addSubview(numLabel_)
- numLabel_.km_add_centerY_constraint()
- numLabel_.km_add_trailing_constraint(constant: -vspace)
- }
- }
- class KMNBotaAnnotationHeaderView: NSView {
- private lazy var titleLabel_: NSTextField = {
- let view = NSTextField(labelWithString: "")
- view.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
- view.textColor = KMNColorTools.colorText_2()
- return view
- }()
-
- private lazy var searchButton_: ComponentButton = {
- let view = ComponentButton()
- let prop = ComponentButtonProperty()
- prop.type = .text_gray
- prop.size = .xxs
- prop.onlyIcon = true
- prop.icon = NSImage(named: "KMImageNameOutlineSearch")
- view.properties = prop
- return view
- }()
-
- private lazy var sortButton_: ComponentButton = {
- let view = ComponentButton()
- let prop = ComponentButtonProperty()
- prop.type = .text_gray
- prop.size = .xxs
- prop.onlyIcon = true
- prop.icon = NSImage(named: "KMImageNameBotaSearch")
- view.properties = prop
- return view
- }()
-
- private lazy var moreButton_: ComponentButton = {
- let view = ComponentButton()
- let prop = ComponentButtonProperty()
- prop.type = .text_gray
- prop.size = .xxs
- prop.onlyIcon = true
- prop.icon = NSImage(named: "KMImageNameOutlineMore")
- view.properties = prop
- return view
- }()
-
- private lazy var bottomLine_: NSView = {
- let view = NSView()
- view.wantsLayer = true
- return view
- }()
-
- var titleLabel: NSTextField {
- get {
- return titleLabel_
- }
- }
-
- var searchButton: ComponentButton {
- get {
- return searchButton_
- }
- }
- var sortButton: ComponentButton {
- get {
- return sortButton_
- }
- }
- var moreButton: ComponentButton {
- get {
- return moreButton_
- }
- }
- var bottomLine: NSView {
- get {
- return bottomLine_
- }
- }
-
- var itemClick: KMCommonClickBlock?
-
- convenience init() {
- self.init(frame: .init(x: 0, y: 0, width: 300, height: 40))
-
- initSubviews()
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- initSubviews()
- }
- func initSubviews() {
- let margin: CGFloat = 12
- addSubview(titleLabel_)
- titleLabel_.km_add_leading_constraint(constant: margin)
- titleLabel_.km_add_centerY_constraint()
-
- let vspace: CGFloat = 8
- let wh: CGFloat = 24
- addSubview(moreButton_)
- moreButton_.km_add_size_constraint(size: .init(width: wh, height: wh))
- moreButton_.km_add_trailing_constraint(constant: -margin)
- moreButton_.km_add_centerY_constraint()
- moreButton_.setTarget(self, action: #selector(moreAction))
-
- addSubview(sortButton_)
- sortButton_.km_add_size_constraint(size: .init(width: wh, height: wh))
- sortButton_.km_add_trailing_constraint(equalTo: moreButton_, attribute: .leading, constant: -vspace)
- sortButton_.km_add_centerY_constraint()
- sortButton_.setTarget(self, action: #selector(sortAction))
-
- addSubview(searchButton_)
- searchButton_.km_add_size_constraint(size: .init(width: wh, height: wh))
- searchButton_.km_add_trailing_constraint(equalTo: sortButton_, attribute: .leading, constant: -vspace)
- searchButton_.km_add_centerY_constraint()
- searchButton_.setTarget(self, action: #selector(searchAction))
-
- addSubview(bottomLine_)
- bottomLine_.km_add_leading_constraint()
- bottomLine_.km_add_trailing_constraint()
- bottomLine_.km_add_bottom_constraint()
- bottomLine_.km_add_height_constraint(constant: 1)
- }
-
- @objc func searchAction() {
- itemClick?(1)
- }
-
- @objc func sortAction() {
- itemClick?(2)
- }
-
- @objc func moreAction() {
- itemClick?(3)
- }
- }
|