Skip to content

Commit 2c65805

Browse files
committed
remember window sizing
1 parent cc32992 commit 2c65805

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

imageviewer5.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
"@executable_path/../Frameworks",
320320
);
321321
MACOSX_DEPLOYMENT_TARGET = 10.15;
322-
MARKETING_VERSION = 1.2;
322+
MARKETING_VERSION = 1.3;
323323
PRODUCT_BUNDLE_IDENTIFIER = djs.imageviewer5;
324324
PRODUCT_NAME = "$(TARGET_NAME)";
325325
SWIFT_VERSION = 5.0;
@@ -342,7 +342,7 @@
342342
"@executable_path/../Frameworks",
343343
);
344344
MACOSX_DEPLOYMENT_TARGET = 10.15;
345-
MARKETING_VERSION = 1.2;
345+
MARKETING_VERSION = 1.3;
346346
PRODUCT_BUNDLE_IDENTIFIER = djs.imageviewer5;
347347
PRODUCT_NAME = "$(TARGET_NAME)";
348348
SWIFT_VERSION = 5.0;

imageviewer5/AppDelegate.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ func spawn_window() {
110110

111111
// Create the window and set the content view.
112112
window = NSWindow(
113-
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
113+
contentRect: NSRect(),
114114
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
115115
backing: .buffered, defer: false)
116+
117+
//contentView.frame(minWidth: CGFloat(current_image_width), minHeight:CGFloat(current_image_height))
116118
window.title = WindowTitle
117119
window.center()
118120
window.setFrameAutosaveName("Main Window")
@@ -170,6 +172,16 @@ func get_URL_String() -> String { /* file://path/to/picture.jpg */
170172
return current_url
171173
}
172174

175+
func get_IMG_Size(axis: String) -> Int {
176+
if axis == "Width" {
177+
return current_image_width
178+
}
179+
if axis == "Height" {
180+
return current_image_height
181+
}
182+
return 0
183+
}
184+
173185
func get_full_filepath() -> String { /* /path/to/picture.jpg */
174186
let fp = String ( ((NSURL(string: get_URL_String())?.path)!))
175187
return fp

imageviewer5/ContentView.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import AppKit
33
import Combine
44
import Foundation
55

6-
var screen_width = NSScreen.main?.frame.width
7-
var screen_height = NSScreen.main?.frame.height
8-
6+
var screen_width = NSScreen.main?.frame.width // Current display max width
7+
var screen_height = NSScreen.main?.frame.height // and height
98

109
struct ContentView: View {
1110
@State var url_string = get_URL_String()
12-
//@State var window_width = (screen_width)! / 2 // get macs screen resolution
13-
//@State var window_height = (screen_height)! / 2
11+
@State var imgW = CGFloat(get_IMG_Size(axis: "Width"))
12+
@State var imgH = CGFloat(get_IMG_Size(axis: "Height"))
13+
1414

1515
let pub = NotificationCenter.default.publisher(for: NSNotification.Name(NCName))
1616

@@ -26,13 +26,17 @@ struct ContentView: View {
2626
}.onReceive(pub) {_ in
2727
// This gets run when notification is sent
2828
self.url_string = get_URL_String()
29+
self.imgW = CGFloat(get_IMG_Size(axis: "Width"))
30+
self.imgH = CGFloat(get_IMG_Size(axis: "Height"))
31+
2932
}
33+
.frame(minWidth: 400, idealWidth: imgW, maxWidth: NSScreen.main?.frame.height, minHeight: 300, idealHeight: imgH, maxHeight: NSScreen.main?.frame.height)
3034
}
3135
}
32-
36+
/*
3337
struct ContentView_Previews: PreviewProvider {
3438
static var previews: some View {
3539
ContentView()
3640
}
37-
}
41+
}*/
3842

imageviewer5/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<key>CFBundleShortVersionString</key>
3737
<string>$(MARKETING_VERSION)</string>
3838
<key>CFBundleVersion</key>
39-
<string>37</string>
39+
<string>104</string>
4040
<key>LSApplicationCategoryType</key>
4141
<string>public.app-category.photography</string>
4242
<key>LSMinimumSystemVersion</key>

0 commit comments

Comments
 (0)