[I am using IUP version 3.30, with GTK2 on X11]

Hello,

  IupFrame doesn't take the width of the title into account when it
calculates the width of the frame.
  Therefore, when the content of the Frame is not wide, the title is
cut short.


   Here is a very simple example :
--------------------------
#include <stddef.h>
#include <iup.h>

int main(void) {
  Ihandle *dlg, *frame, *button;
        
  IupOpen(NULL, NULL);
        
  button = IupButton("Button", NULL);
        
  frame = IupFrame(button);
  IupSetAttribute(frame, "TITLE", "A title wider than the button");
  
  dlg = IupDialog(frame);
  IupSetAttribute(dlg, "TITLE", "Test bug length of frame when title is set");
  IupSetAttribute(dlg, "SIZE", "200x80");

  IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
  IupMainLoop();
  IupClose();
        
  return 0;     
}
--------------------------

  I don't know if this mailing list allows it, but I attach 2
screenshots, one with the problem, and one after some patching.


  My patch is just meant as an example (and a quick&dirty fix for me),
not for direct inclusion. It is probably very brittle: I didn't account
for the "_IUPFRAME_HAS_TITLE" I can see in other parts, I assumed the
result of iupdrvFontGetStringWidth() was reliable (is it?), and I added
an hardcoded value to get some extra space).

  It is short, it simply calculates a minimal width for the frame based
on the width of the title string; and if the existing calculation is
smaller than that, it uses that minimal width instead.

  Here it is anyway:

--------------------------
--- iup.orig/src/iup_frame.c    2019-07-25 21:55:01.000000000 +0200
+++ iup/src/iup_frame.c 2022-12-18 20:23:34.404853218 +0100
@@ -30,6 +30,15 @@
   return height;
 }
 
+int iupFrameGetTitleWidth(Ihandle* ih)
+{
+  char *title = iupAttribGet(ih, "TITLE");
+  
+  if (!title) return 0;
+  
+  return iupdrvFontGetStringWidth(ih, title);
+}
+
 static void iFrameGetDecorSize(Ihandle* ih, int *width, int *height)
 {
   if (iupdrvFrameGetDecorSize(ih, width, height))
@@ -98,6 +107,7 @@
 static void iFrameComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int 
*children_expand)
 {
   int decorwidth, decorheight;
+  int min_width;
   Ihandle* child = ih->firstchild;
 
   iFrameGetDecorSize(ih, &decorwidth, &decorheight);
@@ -113,6 +123,10 @@
     *w += child->naturalwidth;
     *h += child->naturalheight;
   }
+  
+  min_width = decorwidth + iupFrameGetTitleWidth(ih) + 7; // 7 = some margin
+  
+  if (*w < min_width) *w = min_width;
 }
 
 static void iFrameSetChildrenCurrentSizeMethod(Ihandle* ih, int shrink)
--------------------------

Goodbye,
  Stéphane.

Attachment: screenshot_bug_frame_with_title.png
Description: Binary data

Attachment: screenshot_bug_frame_with_title_patched.png
Description: Binary data

_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to