Repository: napari/napari

Issue:
Adding empty layers (shapes, labels) changes viewer size (caused in #
## 🐛 Bug

#4814 (according to git bisect) added a somewhat nasty UI bug wherein adding an empty shapes layer makes the window very wide.


https://user-images.githubusercontent.com/1609449/186669399-21a80104-9aee-4e78-bf5a-a65870243eb1.mov



haven't looked at the code to see why, but pinging @Czaki 


Discussion:
it looks like a problem with the length of help text on status bar:

https://github.com/napari/napari/pull/4814#discussion_r928128416

https://user-images.githubusercontent.com/3826210/186672848-06f5652d-07e6-47a4-ad59-a9f5e32014a4.mp4

There are two options. Limit list of shortcuts in help (but this is workaround) or update statusbar to do not resize on to long text but rather show animation with rolling text. 
> There are two options. Limit list of shortcuts in help (but this is workaround) or update statusbar to do not resize on to long text but rather show animation with rolling text.

or use an eliding label... we should always be using eliding labels for things that shouldn't constrain the width
also status part has similar effect (but smaller)

https://user-images.githubusercontent.com/3826210/186675001-a430472d-e020-4cfa-94ce-6a099c621cbc.mp4

Touched also in #4664



yep, I see the general pattern.  text sometimes makes the window too big.   Do you know why #4980 is the PR that brings all this to the forefront though?  

Basically, it should never be the case that text changes the window size.  Perhaps we've always had a latent issue here, but for some reason #4980 is the one that brought it all to the forefront.  Whatever the ultimate fix may be (which, I think, is probably to use more eliding labels for things that shouldn't be affecting the final size policy of the containing widget), we need to somehow lose the behavior added in #4980
Do you mean #4814? 

The reason is that this PR brings information about all shortcuts to the interface. Before this, there was information only about part of them, and outdated as hardcoded. 

In this comment, https://github.com/napari/napari/pull/4814#issuecomment-1193664460 @jni decide that decision if inform about all shortcuts, or only subset should be done later. 
And I do not like elited label as it removes some information and prefers to see animated, shifting text. 
lol, yes sorry... was looking at the title of this post to get that issue number again.  #4814 is the PR that made this a problem. 

> @jni decide that decision if inform about all shortcuts, or only subset should be done later.

did @jni realize at the time that it would make windows massively wide?  or was he just meaning that the _text_ could be reconsidered later.  I consider this UI bug a big one, and one that needs fixing asap.  While #4814 brings some nice info to the UI, it adds an UX bug that isn't worth it IMO.  needs to be fixed.  

> And I do not like elited label as it removes some information and prefers to see animated, shifting text.

that's fine, you can choose an alternate solution if you'd like.  we just can't have adding an empty shapes layer make the window massively wide.  I'll leave it to you to pick whatever approach you prefer to undo the window width probelm added by #4814

> or was he just meaning that the _text_ could be reconsidered later

only this. I will not mark PR as ready if I found that there is UX problem. 


> prefer to undo the window width problem

The siplest workatound will be limit `help_li` length to first few elements

https://github.com/napari/napari/blob/29cd6fee3ecd5fd0f7f86b65682abbcc8208966a/napari/components/viewer_model.py#L548

> The siplestworkatound will be limit help_li length to first few elements

That's fine if that's what you want to do, but may I ask why you prefer that to an eliding label that will do that automatically, if necessary based on available width, and add the ellipsis for you?
Maybe I wrong understand. We have just plug and play component that could be used on the status bar to elide text? I understand that it needs to be coded, but maybe it is ready and could be used by replacing the constructor call? 
> Maybe I wrong understand. We have just plug and play component that could be used on the status bar to elide text?

I believe `superqt.QElidingLabel` should do this for you

Resolving patch:
diff --git a/napari/_qt/widgets/qt_viewer_status_bar.py b/napari/_qt/widgets/qt_viewer_status_bar.py
--- a/napari/_qt/widgets/qt_viewer_status_bar.py
+++ b/napari/_qt/widgets/qt_viewer_status_bar.py
@@ -59,9 +59,11 @@ def __init__(self, parent: '_QtMainWindow') -> None:
 
         main_widget.setLayout(layout)
 
-        self.addWidget(main_widget)
-        self._help = QLabel('')
-        self.addPermanentWidget(self._help)
+        self.addWidget(main_widget, 1)
+        self._help = QElidingLabel('')
+        self._help.setAlignment(Qt.AlignmentFlag.AlignRight)
+        self._help.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
+        layout.addWidget(self._help, 1)
 
         self._activity_item = ActivityToggleItem()
         self._activity_item._activityBtn.clicked.connect(


Test patch: