• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script UI message window with scrollbar includes anoying blank space

New Here ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

Hey,

 

I've created a window which displays warning message return from API, however this message is followed by a lot of blank space which is really anoying. Is there any way to calculate 

content.maximumSize.height based on the size of the message that is being returned?
I was thinking about changing font to any monospace font and calculating it's height based on how many characters can fit into 1 line but it's sound like overcomplicating it, so I'm wondering if there is any easier way to accomplish it. 

Capture.PNG

 











 

Here is a code that generates window showed above.

	self.showMessage = function(title, header, details) {

		var w = new Window('dialog', title);
		w.add('statictext', undefined, header);
		if(details != undefined) {
			details = 'Details:\n' + details;

			var panel = w.add("panel" , undefined , "");
			panel.size = [650,400];

			var group = panel.add("group");
			group.orientation = "column";
			group.alignment = "left";

			var content = group.add("statictext" , undefined , 
			"What is Lorem Ipsum? "
			+ "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
			+ "Why do we use it?"
			+ " It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)."
			, { alignment: 'left', multiline: true });
			content.minimumSize.width = 600;
			
			var scrollBar = panel.add("scrollbar");
			scrollBar.stepdelta = 10;

			scrollBar.onChanging = function () {
				group.location.y = -1 * this.value;
			}

			w.onShow = function() {
				scrollBar.size = [16,panel.size.height];
				scrollBar.location = [panel.size.width-20, 0];
				scrollBar.maxvalue = group.size.height-panel.size.height+20;
			};
		}
		w.add('button', undefined, 'Close', {
			name: 'OK'
		});
		w.show();
		return w;
	};

 

TOPICS
How to , Scripting

Views

570

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

Hello,

Are you referring to all the space below the message?

 

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

Yeah, it adds this space below the message regardless how big the message is.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

Hi,

 

Try to adjust the panel size....

 

panel.size = [650,200]; or to whatever fits your needs.

 

Regards,

Mike

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

I do not think that will work since the message that is being displayed created dynamically, so sometimes it can be just 1 error sometimes 10 or even more. So settings panel size to fixed size won't work because it will cut off some text if the message would be too long.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

I've seen that I do not think that will work either becuase messages are coming back from the API so I do not know if a message will fit into one line or will have to be splitted into multiple lines. Because I do not know that I can not calculate size based on the number of messages that are being returned. I guess the only way to get this working in the way showed in your example would be to calculate hom many lines a message requires. I do not like an idea of calculating number of lines based of the letter width as it my cause some problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

Not sure if this is the answer you're looking for, but it's good to know in this situation. It's better to use .preferredSize property in place of .size property. Then you can prefer one dimension and let the other auto layout. To ignore a dimension, use -1 in the array passed to preferredSize property.

// Replace:
// panel.size = [650,400];
// with:
panel.preferredSize = [650, -1];

Then the panel is the width you ask for, and whatever height the content makes it. Try that and maybe it will help.

 

William Campbell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

It's not possible in ScriptUI to size a text container dynamically to its content. There's no 'autofit' method, and you can't measure the space that some text occupies (like you can in InDesign) and fit the container to the text.

P.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

@Peter Kahrel  Good to know. Which means my guess won't solve the problem. I gather from this that auto layout only considers control sizes, not considering any text within them.

 

William Campbell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

LATEST

That's right: autoLayout deals with controls relative to each other, not with controls relative to their content.

P.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines