Lagrange [release]

SidebarWidget: Minimum and maximum widths considering both sidebars

abec43cd54a14c6d4a74239df97870a83cc474ed
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 0d931080..7cd51561 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -302,7 +302,7 @@ static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {
     const iWidget *w      = constAs_Widget(d);
     const iRect    bounds = bounds_Widget(w);
     const iPrefs * prefs  = prefs_App();
-    return iMini(bounds.size.x - gap_UI * d->pageMargin * 2,
+    return iMini(iMax(50 * gap_UI, bounds.size.x - gap_UI * d->pageMargin * 2),
                  fontSize_UI * prefs->lineWidth * prefs->zoomPercent / 100);
 }
 
@@ -2984,6 +2984,9 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
     const iWidget *w        = constAs_Widget(d);
     const iRect    bounds   = bounds_Widget(w);
     iVisBuf *      visBuf   = d->visBuf; /* will be updated now */
+    if (width_Rect(bounds) <= 0) {
+        return;
+    }
     draw_Widget(w);
     allocVisBuffer_DocumentWidget_(d);
     const iRect ctxWidgetBounds = init_Rect(
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index ca4404d5..0c17995e 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -564,8 +564,11 @@ static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) {
 }
 
 void setWidth_SidebarWidget(iSidebarWidget *d, int width) {
-    iWidget *w = as_Widget(d);
-    width = iClamp(width, 30 * gap_UI, rootSize_Window(get_Window()).x - 50 * gap_UI);
+    iWidget * w = as_Widget(d);
+    /* Even less space if the other sidebar is visible, too. */
+    const int otherWidth =
+        width_Widget(findWidget_App(d->side == left_SideBarSide ? "sidebar2" : "sidebar"));
+    width = iClamp(width, 30 * gap_UI, rootSize_Window(get_Window()).x - 50 * gap_UI - otherWidth);
     d->width = width;
     if (isVisible_Widget(w)) {
         w->rect.size.x = width;