Skip to content

Commit

Permalink
- resizable left column
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed Mar 10, 2020
1 parent cdc035c commit 2decf15
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 28 deletions.
23 changes: 20 additions & 3 deletions Telegram-Mac/ApplicationContext.swift
Expand Up @@ -558,16 +558,33 @@ final class AuthorizedApplicationContext: NSObject, SplitViewDelegate {
leftController.openChat(index, force: force)
}



func splitResizeCursor(at point: NSPoint) -> NSCursor? {
if FastSettings.isMinimisize {
return NSCursor.resizeRight
} else {
if window.frame.width - point.x <= 380 {
return NSCursor.resizeLeft
}
return NSCursor.resizeLeftRight
}
}

func splitViewShouldResize(at point: NSPoint) {
if !FastSettings.isMinimisize {
let max_w = window.frame.width - 380
let result = min(max(point.x, 300), max_w)
FastSettings.updateLeftColumnWidth(result)
splitView.updateStartSize(size: NSMakeSize(result, result), controller: leftController)
}

}



func splitViewDidNeedSwapToLayout(state: SplitViewState) {
let previousState = splitView.state
splitView.removeAllControllers();
let w:CGFloat = 300;
let w:CGFloat = FastSettings.leftColumnWidth;
FastSettings.isMinimisize = false
splitView.mustMinimisize = false
switch state {
Expand Down
4 changes: 3 additions & 1 deletion Telegram-Mac/ChatMessageItem.swift
Expand Up @@ -548,13 +548,15 @@ class ChatMessageItem: ChatRowItem {
return super.isFixedRightPosition
}

if textLayout.lines.count > 1, let line = textLayout.lines.last, line.frame.width < contentSize.width - (rightSize.width + insetBetweenContentAndDate) {
if textLayout.lines.count > 1, let line = textLayout.lines.last, max(realContentSize.width, maxTitleWidth) < line.frame.width + (rightSize.width + insetBetweenContentAndDate) {
return true
}

return super.isForceRightLine
}

override var additionalLineForDateInBubbleState: CGFloat? {

if containsBigEmoji {
return rightSize.height + 3
}
Expand Down
7 changes: 3 additions & 4 deletions Telegram-Mac/ChatRowItem.swift
Expand Up @@ -1355,7 +1355,6 @@ class ChatRowItem: TableRowItem {
override func makeSize(_ width: CGFloat, oldWidth:CGFloat) -> Bool {

let result = super.makeSize(width, oldWidth: oldWidth)

isForceRightLine = false

if let channelViewsAttributed = channelViewsAttributed {
Expand All @@ -1371,8 +1370,8 @@ class ChatRowItem: TableRowItem {

func layout() -> Bool {
if additionalLineForDateInBubbleState == nil && !isFixedRightPosition {
if _contentSize.width + rightSize.width + insetBetweenContentAndDate > widthForContent, replyMarkupModel == nil {
widthForContent = _contentSize.width - 5
if _contentSize.width + rightSize.width + insetBetweenContentAndDate > widthForContent {
// widthForContent = _contentSize.width - 5
self.isForceRightLine = true
//_contentSize = self.makeContentSize(widthForContent)
return true
Expand Down Expand Up @@ -1576,7 +1575,7 @@ class ChatRowItem: TableRowItem {
//hasBubble ? ((authorText?.layoutSize.width ?? 0) + (isScam ? theme.icons.chatScam.backingSize.width + 3 : 0) + (adminBadge?.layoutSize.width ?? 0)) : 0

let forwardWidth = hasBubble ? (forwardNameLayout?.layoutSize.width ?? 0) + (isForwardScam ? theme.icons.chatScam.backingSize.width + 3 : 0) : 0
let replyWidth = hasBubble ? (replyModel?.size.width ?? 0) : 0
let replyWidth: CGFloat = hasBubble ? (replyModel?.size.width ?? 0) : 0

var rect = NSMakeRect(defLeftInset, 2, contentSize.width, height - 4)

Expand Down
11 changes: 10 additions & 1 deletion Telegram-Mac/FastSettings.swift
Expand Up @@ -141,8 +141,8 @@ class FastSettings {
private static let kArchiveAutohidden = "kArchiveAutohidden"
private static let kAutohideArchiveFeature = "kAutohideArchiveFeature"

private static let kLeftColumnWidth = "kLeftColumnWidth"


static var sendingType:SendingType {
let type = UserDefaults.standard.value(forKey: kSendingType) as? String
if let type = type {
Expand Down Expand Up @@ -368,6 +368,15 @@ class FastSettings {
UserDefaults.standard.set(true, forKey: "dice_\(messageId.id)_\(messageId.namespace)")
UserDefaults.standard.synchronize()
}

static func updateLeftColumnWidth(_ width: CGFloat) {
UserDefaults.standard.set(width, forKey: kLeftColumnWidth)
UserDefaults.standard.synchronize()
}
static var leftColumnWidth: CGFloat {
return UserDefaults.standard.value(forKey: kLeftColumnWidth) as? CGFloat ?? 300
}

/*
+(void)requestPermissionWithKey:(NSString *)permissionKey peer_id:(int)peer_id handler:(void (^)(bool success))handler {
Expand Down
2 changes: 1 addition & 1 deletion Telegram-Mac/Info.plist
Expand Up @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>192419</string>
<string>192486</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.social-networking</string>
<key>LSFileQuarantineEnabled</key>
Expand Down
2 changes: 1 addition & 1 deletion TelegramShare/Info.plist
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleShortVersionString</key>
<string>5.9.3</string>
<key>CFBundleVersion</key>
<string>192419</string>
<string>192486</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSExtension</key>
Expand Down
70 changes: 53 additions & 17 deletions submodules/TGUIKit/TGUIKit/TGSplitView.swift
Expand Up @@ -30,15 +30,21 @@ fileprivate class SplitMinimisizeView : Control {
checkCursor()
}


func checkCursor() {
if let splitView = splitView {
if let minimisize = splitView.delegate?.splitViewIsCanMinimisize(), minimisize {
if mouseInside() {
if splitView.state == .minimisize {
NSCursor.resizeRight.set()
if mouseInside() || (NSEvent.pressedMouseButtons & (1 << 0)) != 0 {
if let cursor = splitView.delegate?.splitResizeCursor(at: self.frame.origin.offsetBy(dx: 5, dy: 0)) {
cursor.set()
} else {
NSCursor.resizeLeft.set()
if splitView.state == .minimisize {
NSCursor.resizeRight.set()
} else {
NSCursor.resizeLeft.set()
}
}

} else {
NSCursor.arrow.set()
}
Expand Down Expand Up @@ -67,19 +73,17 @@ fileprivate class SplitMinimisizeView : Control {

if let splitView = splitView {
if let minimisize = splitView.delegate?.splitViewIsCanMinimisize(), minimisize {
if splitView.state == .minimisize {
NSCursor.resizeRight.set()
} else {
NSCursor.resizeLeft.set()
}
checkCursor()

let current = splitView.convert(event.locationInWindow, from: nil)


if startPoint.x - current.x >= 100, splitView.state != .minimisize {
splitView.delegate?.splitViewShouldResize(at: current)

if current.x <= 100, splitView.state != .minimisize {
splitView.needMinimisize()
startPoint = current
} else if current.x - startPoint.x >= 100, splitView.state == .minimisize {
} else if current.x >= 100, splitView.state == .minimisize {
splitView.needFullsize()
startPoint = current
} else {
Expand All @@ -90,13 +94,36 @@ fileprivate class SplitMinimisizeView : Control {
}
}

private func notifyTableEndResize(in view: NSView) {
for view in view.subviews {
if let view = view as? TGFlipableTableView {
view.viewDidEndLiveResize()
} else {
notifyTableEndResize(in: view)
}
}
}
private func notifyTableStartResize(in view: NSView) {
for view in view.subviews {
if let view = view as? TGFlipableTableView {
view.viewWillStartLiveResize()
} else {
notifyTableStartResize(in: view)
}
}
}

fileprivate override func mouseUp(with event: NSEvent) {
startPoint = NSZeroPoint
if let splitView = splitView {
notifyTableEndResize(in: splitView)
}
}

fileprivate override func mouseDown(with event: NSEvent) {
if let splitView = splitView {
startPoint = splitView.convert(event.locationInWindow, from: nil)
notifyTableStartResize(in: splitView)
}
}

Expand Down Expand Up @@ -137,6 +164,19 @@ public protocol SplitViewDelegate : class {
func splitViewDidNeedFullsize(controller:ViewController) -> Void
func splitViewIsCanMinimisize() -> Bool
func splitViewDrawBorder() -> Bool

func splitViewShouldResize(at point: NSPoint) -> Void

func splitResizeCursor(at point: NSPoint) -> NSCursor?
}

public extension SplitViewDelegate {
func splitViewShouldResize(at point: NSPoint) -> Void {

}
func splitResizeCursor(at point: NSPoint) -> NSCursor? {
return nil
}
}


Expand Down Expand Up @@ -176,7 +216,7 @@ public class SplitView : View {

private var _proportions:[Int:SplitProportion] = [Int:SplitProportion]()
private var _startSize:[Int:NSSize] = [Int:NSSize]()
private var _controllers:[ViewController] = [ViewController]()
fileprivate var _controllers:[ViewController] = [ViewController]()
private var _issingle:Bool?
private var _layoutProportions:[SplitViewState:SplitProportion] = [SplitViewState:SplitProportion]()

Expand Down Expand Up @@ -270,11 +310,8 @@ public class SplitView : View {

public func updateStartSize(size:NSSize, controller:ViewController) -> Void {
_startSize[controller.internalId] = size;

_proportions[controller.internalId] = SplitProportion(min:size.width, max:size.height);

update();

needsLayout = true
}

public func update(_ forceNotice:Bool = false) -> Void {
Expand Down Expand Up @@ -381,7 +418,6 @@ public class SplitView : View {
}

size = NSMakeSize(x + min > frame.width ? (frame.width - x) : min, frame.height);

let rect:NSRect = NSMakeRect(x, 0, size.width, size.height);

if(!NSEqualRects(rect, obj.view.frame)) {
Expand Down

0 comments on commit 2decf15

Please sign in to comment.