Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: toolbar 관련 사항 변경 #57

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Box42/Box/BoxBaseContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import Cocoa
import SnapKit

class BoxBaseContainerViewController: NSViewController {
var splitView: BoxBaseSplitView! = BoxBaseSplitView()
var contentGroup: BoxContentsViewGroup! = BoxContentsViewGroup()
var toolbarGroup: BoxToolbarViewGroup! = BoxToolbarViewGroup()
var functionGroupVC: BoxFunctionViewController! = BoxFunctionViewController()
var splitView: BoxBaseSplitView = BoxBaseSplitView()
var contentGroup: BoxContentsViewGroup = BoxContentsViewGroup()
var toolbarGroupVC: ToolbarViewController = ToolbarViewController()
var functionGroupVC: BoxFunctionViewController = BoxFunctionViewController()
let windowViewGroup: WindowButtonViewController = WindowButtonViewController()
var buttonGroup: BoxButtonViewGroup!
var leftContainer: MovableContainerView!

Expand Down Expand Up @@ -53,21 +54,28 @@ class BoxBaseContainerViewController: NSViewController {
private func leftContainerInit() {
leftContainer = MovableContainerView()
leftContainer.addSubview(buttonGroup)
leftContainer.addSubview(toolbarGroup)
leftContainer.addSubview(windowViewGroup.view)
leftContainer.addSubview(toolbarGroupVC.view)
leftContainer.addSubview(functionGroupVC.view)
leftContainerAutolayout()
leftContainer.frame.size.width = BoxSizeManager.shared.windowButtonGroupSize.width
}

private func leftContainerAutolayout() {
toolbarGroup.snp.makeConstraints { make in
windowViewGroup.view.snp.makeConstraints { make in
make.top.equalTo(leftContainer).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
make.left.equalTo(leftContainer)
}

toolbarGroupVC.view.snp.makeConstraints { make in
make.top.equalTo(windowViewGroup.view.snp.bottom).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
make.left.equalTo(leftContainer)
}

buttonGroup.snp.makeConstraints { make in
make.top.equalTo(toolbarGroup.snp.bottom).offset(Constants.UI.GroupAutolayout)
make.top.equalTo(toolbarGroupVC.view.snp.bottom).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
make.left.equalTo(leftContainer)
}
Expand Down
2 changes: 1 addition & 1 deletion Box42/Box/View/BoxButtonViewGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Cocoa
import SnapKit

class BoxButtonViewGroup: NSView {
var boxVM: WebViewModel! = WebViewModel()
var boxVM: WebViewModel = WebViewModel()
var pinSwitch : NSSwitch = NSSwitch()
var clickAction: ((NSButton) -> Void)?
var lastAddedButton: NSView?
Expand Down
10 changes: 5 additions & 5 deletions Box42/FunctionButton/View/BoxFunctionViewGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import AppKit
import SnapKit

class BoxFunctionViewGroup: NSView {
lazy var preferenceButton: PreferenceButtonView! = PreferenceButtonView(image: NSImage(imageLiteralResourceName: "plus"), completion: { self.preferenceAction?() })
lazy var pinButton: PinButtonView! = PinButtonView(image: NSImage(imageLiteralResourceName: "pin"), completion: { self.pinAction?() })
lazy var quitButton: QuitButtonView! = QuitButtonView(image: NSImage(imageLiteralResourceName: "figure.snowboarding"), completion: { self.quitAction?() })
lazy var boxButton: BoxFunctionButtonView! = BoxFunctionButtonView(image: NSImage(imageLiteralResourceName: "shippingbox"), completion: { self.boxAction?() })
lazy var divider: NSBox! = TopDivider(completion: { self.dividerAction?() })
lazy var preferenceButton: PreferenceButtonView = PreferenceButtonView(image: NSImage(imageLiteralResourceName: "plus"), completion: { self.preferenceAction?() })
lazy var pinButton: PinButtonView = PinButtonView(image: NSImage(imageLiteralResourceName: "pin"), completion: { self.pinAction?() })
lazy var quitButton: QuitButtonView = QuitButtonView(image: NSImage(imageLiteralResourceName: "figure.snowboarding"), completion: { self.quitAction?() })
lazy var boxButton: BoxFunctionButtonView = BoxFunctionButtonView(image: NSImage(imageLiteralResourceName: "shippingbox"), completion: { self.boxAction?() })
lazy var divider: NSBox = TopDivider(completion: { self.dividerAction?() })

var preferenceAction: (() -> Void)?
var pinAction: (() -> Void)?
Expand Down
3 changes: 1 addition & 2 deletions Box42/Main/BoxViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import AppKit
import WebKit

class BoxViewController: NSViewController {
var boxView: BoxBaseContainerViewController! = BoxBaseContainerViewController()
var boxView: BoxBaseContainerViewController = BoxBaseContainerViewController()
var gradientLayer: CAGradientLayer!
let preferencesVC = PreferencesViewController()
weak var menubarVCDelegate: MenubarViewControllerDelegate?


override func loadView() {
self.view = boxView.view
}
Expand Down
26 changes: 9 additions & 17 deletions Box42/Toolbar/ToolbarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@
import Cocoa

class ToolbarViewController: NSViewController {
var displayURL = DisplayURLInToolbar()
var goBackButton: GoBackInToolbar?
var goForwardButton: GoForwardInToolbar?
var reloadPageButton: ReloadPageViaToolbar?
var goHomePageViaButton: GoHomePageViaToolbar?
var sidebarLeading: SideBarLeading?

override func loadView() {
displayURL = DisplayURLInToolbar()
sidebarLeading = SideBarLeading(image: NSImage(imageLiteralResourceName: "sidebar.leading"), completion: sidebar)
goBackButton = GoBackInToolbar(image: NSImage(imageLiteralResourceName: "arrow.left"), completion: goBack)
goForwardButton = GoForwardInToolbar(image: NSImage(imageLiteralResourceName: "arrow.right"), completion: goFoward)
reloadPageButton = ReloadPageViaToolbar(image: NSImage(imageLiteralResourceName: "arrow.clockwise"), completion: reloadPage)
goHomePageViaButton = GoHomePageViaToolbar(image: NSImage(imageLiteralResourceName: "figure.skating"), completion: goToHome)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
let toolbarViewGroup = BoxToolbarViewGroup()

toolbarViewGroup.sidebar = sidebar
toolbarViewGroup.goBack = goBack
toolbarViewGroup.goFoward = goFoward
toolbarViewGroup.reloadPage = reloadPage
toolbarViewGroup.goToHome = goToHome

self.view = toolbarViewGroup
}

override func viewDidLoad() {
Expand Down
81 changes: 67 additions & 14 deletions Box42/Toolbar/View/BoxToolbarViewGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,76 @@ import AppKit
import SnapKit

class BoxToolbarViewGroup: NSView {
var toolbarVC: ToolbarViewController?
var displayURL = DisplayURLInToolbar()
lazy var sidebarLeading: SideBarLeading = SideBarLeading(image: NSImage(imageLiteralResourceName: "sidebar.leading"), completion: { self.goBack?() })
lazy var goBackButton: GoBackInToolbar = GoBackInToolbar(image: NSImage(imageLiteralResourceName: "arrow.left"), completion: { self.goFoward?()} )
lazy var goForwardButton: GoForwardInToolbar = GoForwardInToolbar(image: NSImage(imageLiteralResourceName: "arrow.right"), completion: { self.reloadPage?() })
lazy var reloadPageButton: ReloadPageViaToolbar = ReloadPageViaToolbar(image: NSImage(imageLiteralResourceName: "arrow.clockwise"), completion: { self.goToHome?() })
lazy var goHomePageViaButton: GoHomePageViaToolbar = GoHomePageViaToolbar(image: NSImage(imageLiteralResourceName: "figure.skating"), completion: { self.sidebar?() })

init() {
// toolbarVC = ToolbarViewController(nibName: nil, bundle: nil)

super.init(frame: NSRect(x: 0, y: 0, width: BoxSizeManager.shared.size.width - BoxSizeManager.shared.toolbarGroupSize.width, height: BoxSizeManager.shared.toolbarGroupSize.height))
var goBack: (() -> Void)?
var goFoward: (() -> Void)?
var reloadPage: (() -> Void)?
var goToHome: (() -> Void)?
var sidebar: (() -> Void)?

override init(frame: NSRect) {
super.init(frame: frame)
setupViews()
setupConstraints()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupViews()
setupConstraints()
}

private func setupViews() {
self.addSubview(displayURL)
self.addSubview(sidebarLeading)
self.addSubview(goBackButton)
self.addSubview(goForwardButton)
self.addSubview(reloadPageButton)
self.addSubview(goHomePageViaButton)
}

private func setupConstraints() {
displayURL.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.right.equalToSuperview()
}

self.wantsLayer = true
// self.addSubview(toolbarVC!.view)
sidebarLeading.snp.makeConstraints { make in
make.top.equalTo(displayURL).offset(10)
make.bottom.equalToSuperview()
make.left.equalToSuperview()
make.width.equalTo(goBackButton)
}

goBackButton.snp.makeConstraints { make in
make.top.bottom.equalTo(sidebarLeading)
make.left.equalTo(sidebarLeading.snp.right).offset(10)
make.width.equalTo(goForwardButton)
}

goForwardButton.snp.makeConstraints { make in
make.top.bottom.equalTo(sidebarLeading)
make.left.equalTo(goBackButton.snp.right).offset(10)
make.width.equalTo(reloadPageButton)
}

reloadPageButton.snp.makeConstraints { make in
make.top.bottom.equalTo(sidebarLeading)
make.left.equalTo(goForwardButton.snp.right).offset(10)
make.width.equalTo(goHomePageViaButton)
}

toolbarVC?.view.translatesAutoresizingMaskIntoConstraints = false
toolbarVC?.view.snp.makeConstraints { make in
make.edges.equalTo(self)
goHomePageViaButton.snp.makeConstraints { make in
make.top.bottom.equalTo(sidebarLeading)
make.left.equalTo(reloadPageButton.snp.right).offset(10)
make.right.equalToSuperview()
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")

}
}
2 changes: 1 addition & 1 deletion Box42/WebView/URL/URLModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct URLModels {

// Network logic api call 날려서 받아올 것.
let URLstring: [nameUrl] = [
("home", "http://42box.kr/"),
("home", "https://42box.kr/"),
("23Coaltheme", "https://42box.github.io/front-end/"),
// ("home", "http://127.0.0.1:3000/"),
("Box 42", "https://42box.github.io/front-end/#/box"),
Expand Down
6 changes: 2 additions & 4 deletions Box42/Window/BoxWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import Cocoa

class BoxWindowController: NSWindowController, NSToolbarDelegate, NSWindowDelegate {

override init(window: NSWindow?) {
let contentRect = BoxSizeManager.shared.boxViewSizeNSRect
let styleMask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable, .fullSizeContentView, .titled]

let styleMask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable, .fullSizeContentView]
let windowInstance = NSWindow(contentRect: contentRect, styleMask: styleMask, backing: .buffered, defer: false)

windowInstance.titlebarAppearsTransparent = true
Expand All @@ -30,7 +28,7 @@ class BoxWindowController: NSWindowController, NSToolbarDelegate, NSWindowDelega

windowInstance.delegate = self

setupToolbar()
// setupToolbar()
}

required init?(coder: NSCoder) {
Expand Down
31 changes: 31 additions & 0 deletions Box42/Window/View/WindowCloseButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// WindowCloseButton.swift
// Box42
//
// Created by Chanhee Kim on 8/23/23.
//

import AppKit

class WindowCloseButton: NSButton {

private var callback: (() -> Void)?

init(image: NSImage, completion: @escaping () -> Void) {
super.init(frame: .zero)

self.title = "X" // 기본적인 X 모양으로 표시. 이미지나 다른 디자인을 원하시면 변경하실 수 있습니다.
self.bezelStyle = .texturedRounded
self.target = self
self.action = #selector(closeAction)
self.callback = completion
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func closeAction() {
callback?()
}
}
31 changes: 31 additions & 0 deletions Box42/Window/View/WindowMaximizeButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// WindowMaximizeButton.swift
// Box42
//
// Created by Chanhee Kim on 8/23/23.
//

import AppKit

class WindowMaximizeButton: NSButton {

private var callback: (() -> Void)?

init(image: NSImage, completion: @escaping () -> Void) {
super.init(frame: .zero)

self.title = "□" // 기본적인 □ 모양으로 표시. 변경 가능.
self.bezelStyle = .texturedRounded
self.target = self
self.action = #selector(maximizeAction)
self.callback = completion
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func maximizeAction() {
callback?()
}
}
31 changes: 31 additions & 0 deletions Box42/Window/View/WindowMinimizeButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// WindowMinimizeButton.swift
// Box42
//
// Created by Chanhee Kim on 8/23/23.
//

import AppKit

class WindowMinimizeButton: NSButton {

private var callback: (() -> Void)?

init(image: NSImage, completion: @escaping () -> Void) {
super.init(frame: .zero)

self.title = "_" // 기본적인 _ 모양으로 표시. 변경 가능.
self.bezelStyle = .texturedRounded
self.target = self
self.action = #selector(minimizeAction)
self.callback = completion
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func minimizeAction() {
callback?()
}
}
56 changes: 56 additions & 0 deletions Box42/Window/View/WindowViewGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// WindowViewGroup.swift
// Box42
//
// Created by Chanhee Kim on 8/23/23.
//

import AppKit
import SnapKit

class WindowViewGroup: NSView {
lazy var windowClose: WindowCloseButton = WindowCloseButton(image: NSImage(imageLiteralResourceName: "sidebar.leading"), completion: { self.close?() })
lazy var windowMinimize: WindowMinimizeButton = WindowMinimizeButton(image: NSImage(imageLiteralResourceName: "arrow.left"), completion: { self.minimize?()} )
lazy var windowMaximize: WindowMaximizeButton = WindowMaximizeButton(image: NSImage(imageLiteralResourceName: "arrow.right"), completion: { self.maximize?() })

var close: (() -> Void)?
var minimize: (() -> Void)?
var maximize: (() -> Void)?

override init(frame: NSRect) {
super.init(frame: frame)
setupViews()
setupConstraints()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupViews()
setupConstraints()
}

private func setupViews() {
self.addSubview(windowClose)
self.addSubview(windowMinimize)
self.addSubview(windowMaximize)
}

private func setupConstraints() {

windowClose.snp.makeConstraints { make in
make.top.left.bottom.equalToSuperview()
make.width.equalTo(windowMinimize)
}

windowMinimize.snp.makeConstraints { make in
make.top.bottom.equalTo(windowClose)
make.left.equalTo(windowClose.snp.right).offset(10)
make.width.equalTo(windowMaximize)
}

windowMaximize.snp.makeConstraints { make in
make.top.right.bottom.equalToSuperview()
make.left.equalTo(windowMinimize.snp.right).offset(10)
}
}
}
Loading