Jump to content

Recommended Posts

Posted

I have a tunibutton on a panel. this button is anchor on right and left.

When i decrease my panel size my  button size width is decrease.

If the caption is too long for the button, i would like  the caption to be written on 2 lines or that the font size decrease automaticly. 

Is it possible to do that ?

Posted

I've solved this by modifying css of the button manually in code. However, it would be very nice feature to achieve this by simply setting property like 'AutoWrap' to true.

Posted

Hi,

 

I think here you need to consider the length of the caption, the width of the button, and depending on this to change some properties of css: "line-height", "white-space"

Posted

Sorry , I'm not used to working with css and js

 

So i try this :

Custom Css : 

.wrap-button .x-button-label {
  word-wrap: break-word;
}

and on my button :

function beforeInit(sender, config)
{
  config.cls="wrap-button";
}

But it don't work.

:unsure:

Am i on the good way ?

Posted

Hi,

 

One possible solution I think, can you try to use this approach for now ?!

 

UniButton1 -> ClientEvents -> ExtEvents -> function resize:

function resize(sender, width, height, oldWidth, oldHeight, eOpts)
{
    var me = sender.btnInnerEl;
    var tm = new Ext.util.TextMetrics();
    var lineHeight = parseInt(me.getStyle("line-height"));
    
    if (tm.getSize(sender.text).width >= width + 25) {
        me.setStyle("line-height", lineHeight / 2 + "px");
        me.setStyle("white-space", "normal");
    } else {
        me.setStyle("white-space", "nowrap");
    };       
}

Best regards.

  • Upvote 1
Posted

Here is a modified version of Delphi Developer's solution which scales the number of lines dynamically...obviously there is only so much space to fit eventually.

function resize(sender, width, height, oldWidth, oldHeight, eOpts)
{
    var me = sender.btnInnerEl;
    var tm = new Ext.util.TextMetrics();
    var lineHeight = parseInt(me.getStyle("line-height"));
    var textWidth = tm.getSize(sender.text).width;   
    
    if (textWidth >= width + 25) {         
        me.setStyle("line-height", lineHeight / Math.ceil(textWidth/width) + "px");
        me.setStyle("white-space", "normal");
    } else {
        me.setStyle("white-space", "nowrap");
    };       
}

post-4617-0-85275000-1491554514_thumb.png

post-4617-0-97286200-1491554518_thumb.png

  • Upvote 2
Posted

Ok,

excuse me delphi developer. it work in the sample.

Thanks GerhardV

it not work in my main project.

In my main project the button is in a uniframe and the frame is assigned to the left panel. I'll investigate and i don't find, i'll come bak with a new sample.

Thanks for all

Posted

function resize(sender, width, height, oldWidth, oldHeight, eOpts)
{
    var me = sender.btnInnerEl;
    var tm = new Ext.util.TextMetrics();
    var lineHeight = parseInt(me.getStyle("line-height"));
  
    if (tm.getSize(sender.text).width >= width + 25)
    {        
      Ext.defer(function() {
          me.setStyle("line-height", lineHeight / 2 + "px");
          me.setStyle("white-space", "normal");
      }, 50);
    }
    else
    {
      me.setStyle("white-space", "nowrap");
    };       
}
  • 1 year later...
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...