Window (Changing mode doesn't fire event like resize) - events

Like the topic said I'm having problem with window resizing event. Basically I want to my content fit window size. However not everything works like it should. Changing window mode for instance maximizing or resizing is handled by client event listener. The problem is that when I'm resizing everything works ok, but maximizing/restoring only changes window size and the content doesnt fit at all. What is the solution for this type of behaviour?
ps. Changing browser's window size fire the content to update.

Normally you don't need to use resize listener to do layouting in Vaadin Window, usually full size layouts (width and height are 100%) and expand rations are the concepts you need.
If you really need to use window resize listeners, you need to use a WindowModeChangeListener. That's fired when window mode is changes. There is a method called addWindowModeChangeListener in Window.

Related

How can I make window zooming respect auto layout constraints?

To keep things simple, let's say I have a window containing a single view, which has auto layout constraints binding all 4 sides to the window container view with offset 0. And assume that this view also has a constraint setting its aspect ratio to a constant value. If I resize the window manually, then then window nicely maintains the desired aspect ratio. But if I click the little green zoom widget, then the window fills up the whole screen, regardless of the aspect ratio, with part of the view being above the top of the screen. Is there some way I can make zooming resize the window as big as it can be, without violating auto layout constraints?
I couldn't very well detect this problem in the delegate method windowWillResize:toSize:, because that doesn't tell me which screen it's thinking about putting the window on. I could try to fix the window size in the windowDidResize: delegate method, at which time I do know what screen it's on, but I'm not sure exactly how to do that without reinventing Auto Layout's wheel.
Apparently someone thinks I wasn't explicit enough, so I'll try again. Steps to reproduce:
In Xcode, create a new macOS App project using XIB interface.
Open MainMenu.xib and select the window.
Reshape the window to be approximately square.
Using the Attribute Inspector, set the Full Screen behavior for the window to Auxiliary Window.
Drag an Image View from the library and drop it in the window.
In the Attributes Inspector, set the image view to show the NSComputer image and scale axes independently.
Expand the image view to fill up the window content area.
With the image view selected, click the button to add new layout constraints.
Add 5 constraints, binding the 4 sides to the container, and setting the aspect ratio. (see screen shot)
Build and Run.
Observe that if you resize the window by dragging an edge or corner, the aspect ratio remains fixed.
Click the green zoom widget in the title bar of the window, and observe that the window expands without regard for the aspect ratio constraint, cutting off part of the image.
I just set up a test project exactly as you specified, and when I invoke the window zoom widget, the window expands and retains its aspect ratio i.e. it works as expected. The only thing I can think of that might be causing your issue: maybe your content hugging and content compression resistance priorities are at odds with your constraints? Mind you, I just left them at the default values and it worked fine. Unfortunately Mac/AppKit development (esp. when using IB) is rife with these kind of odd bugs and weird behaviour, probably because Apple has not given it any love in years, so bugs creep in/fester and they are clearly so DONE with developing UI the 'old fashioned way'. (Using SwiftUI to make a Mac app is just as frustrating, in different ways, so I'll stick with what I know). FYI, I used Xcode 13.4.1 to create this test project. Good luck!

Detect moving the windows from one display to another

I have a window with an opengl view where content ist rendered. The problem I have in macOS is, that when I move the window from one monitor to the other, its content gets messed up. A redraw fixes the issue. Thus I need to redraw the GL Area when it gets moved from one monitor to the other. Is there any way to detect the transition of the window from one monitor to the other?
You can register for notifications that fire when the view's window changes screens: NSWindowDidChangeScreenNotification

Resizing UWP Window on User Drag

I am trying to change the size of the UI Elements within a UWP Window on the change of the size of the window itself, such as clicking the edge of the window and dragging right. However, on increase of size, there seems to be Bounds set on the creation of the Window for the maximum size of the content, is there anyway to bypass this Bounds?
Try setting the UI Element's HorizontalAlignment and/or VerticalAlignment to "Stretch". Alternatively, if you want to scale it too, you may put the whole thing in a ViewBox. There are really quite a few options to achieve what you want.

Managing a full screen view with support for popup dialogs (Cocoa/OSX)

I am working on a Cocoa app that consists of 5 views of varying shapes and sizes, some of these views are NSOpenGLViews. I need to have functionality for any of these views to be able to take over the whole window and go into some sort of full screen mode. I originally tried doing this with the method enterFullScreenMode:withOptions: but I ran into trouble when I would try and bring up a dialog window (this would result in a crash). So it seems that I need to scale back my approach a little because I cannot live without these popup dialogs.
My new strategy is to stretch the view that is going into full screen mode so that it takes over the whole view of the screen and then enter into kiosk mode. I was wondering if anyone had tried this type of approach to make a full screen view and if they could offer any advice about best practices for this type of implementation.
My main concern is that I need to preserve the state of the window when I leave full screen mode so I am wondering what would be the best way to hide the other views. Could I just make the other views invisible and then stretch my full screen view to take over the window or would it be better to put the full screen view into a new window and then stretch this new window? My first inclination is that it would be best to keep the full screen view in its original window because it seems this would interfere with event handling less.

Programmatically closing an NSWindow when it loses focus

I am making an image picker that will display an n by n grid of selectable button when the picker is popped up. This grid of buttons will be contained within an NSWindow but I would like for the window to be close automatically if the user clicks off the screen. Is there a flag that can be set so that when the window looses focus it will be closed automatically?
There are two notifications that you may be interested in: NSWindowDidResignKeyNotification and NSWindowDidResignMainNotification. You can simply register for the one you're interested in in awakeFromNib (or windowDidLoad if you have a custom controller) and then close or hide the window as appropriate when you receive the notifications.
I won't delve too much into whether or not this is a good idea from UI standpoint. But, it might be a better idea to have either an overlay view or a panel for the functionality you describe.
You might check out NSPanel. It's an NSWindow subclass that will hide itself when the app is in the background, and that behavior sounds very similar to what you are looking for.

Resources