arraysuser-interfacepropertiesframeworksqooxdoo

Extend window size according to window caption/label in qooxdoo


I have a window with a caption and two buttons. The window caption is longer than two buttons and I got three dots in the window caption. Is there some way to fix it I mean get rid of dots and see the full caption? Maybe try other ways for example use label in window body but I am afraid of the result will be the same.

var win = new qx.ui.window.Window("First Window");
win.setLayout(new qx.ui.layout.HBox());
win.setShowMinimize(false);

var yesBtn = new qx.ui.form.Button("Yes");
var noBtn = new qx.ui.form.Button("No");
win.add(yesBtn);
win.add(noBtn);

this.getRoot().add(win, {left:20, top:20});
win.open();

Solution

  • Here's an example showing the way to do it dynamically. You can copy/paste this into the playground at https://qooxdoo.org/qxl.playground/#%7B%22code%22%3A%22%22%7D

    function onAppear()
    {
      let styles;
      let resolvedFont;
      let content;
      let min;
      let captionWidget = this.getChildControl("title");
      let font = captionWidget.getFont();
    
      // Extra space needed to account for buttons, e.g., maximize, close.
      // This could be made dynamic using `getShowMaximize()`, etc.
      // Here, assigned a fixed value that works with maximize and close buttons
      let excess = 70;
    
      if (font)
      {
        resolvedFont = qx.theme.manager.Font.getInstance().resolve(font);
        styles = resolvedFont.getStyles();
      }
      else
      {
        styles = qx.bom.getDefaultStyles();
      }
    
      content = this.getCaption() || "A";
      min = qx.bom.Label.getTextSize(content, styles);
      this.setMinWidth(min.width + excess);
    }
    
    function addWindow(root, caption, top)
    {
      var win = new qx.ui.window.Window(caption);
    
      win.setLayout(new qx.ui.layout.HBox());
      win.setShowMinimize(false);
    
      var yesBtn = new qx.ui.form.Button("Yes");
      var noBtn = new qx.ui.form.Button("No");
      win.add(yesBtn);
      win.add(noBtn);
    
      root.add(win, {left:20, top:top});
      win.open();
    
      win.addListener("appear", onAppear);
    }
    
    addWindow(this.getRoot(), "First Window with a long caption", 20);
    addWindow(this.getRoot(), "Second Window", 120);