Get rid of ugly CustomEditor spacing - c#

I've been making my own event management system because I don't want to pay money for Playmaker:
I'm getting this really terrible spacing between labels and their components (for example, in the picture above, between Nickname and it's text field)
The script can be found here (keep in mind, its a work in progress. I haven't had time to clean it all up):
http://pastebin.com/w2cLWBvh

It looks like that layout system you've been using aims to give both the nickname label and text input field nearly the same amount of space within their combined area.
Without knowing an awful lot about what layout options Unity's GUI system has, you can probably do with setting the length of the label and textbox arbitrarily.
Here's how you can get the size of a label given a specific string:
GUI.skin.GetStyle("Label").CalcSize(new GUIContent(widestIdString));
So say you have a new BeginArea containing your label and textbox combo. You'd set the label length to this newly calculated width, and the textbox width to the difference of the Area's width and the label's width, plus an arbitrary distance to seperate them, such as 23f;

Related

Dynamic sized multi line TextBox field in a PDF

I have created a document in an open office with a multi-line form field:
The issue I am having is when the dynamic content exceeds the initial size of the multi-line text box:
Sure I can re-size the Text Box in the original template but the dynamic content may be from 1 to 50 lines and I want the text after the Text Box to be close to the last line of dynamic content.
Can someone suggest a way to solve this?
I have once coded a solution to set the width and height of a textbox programmatically based on the characters supplied. I think this was a school assignment a long time ago.
This can be done with both VBA in a code behind or probably with a macro even. Or with VB.net.
I don't have the code I used way back when, but basically determine the maximum width you are able to provide in character width, the preferred width. Determine the pixel requirement per character for that width. This becomes the textbox width.
Divide your total string character count by your preferred width character count. Round up, calculate the pixel height per character. And use this value times the rounded result for the textbox height. Dirty but it should work.
Any chance you can change to a label and set AutoSize to True? You can fix the width and let the height auto adjust. This should be done before converting to a pdf. In fact all of the sizing should be resovled before pdf conversion.
Another Down voter without a comment, should not be allowed.

Check if Control.Text is to long to be shown

I'm trying to do some automatic tests if the strings of a translated Application still fits the existing UI. The translation process just takes an existing resource assembly translates the contained resources and creates a new resources assembly for the new language. Easy but that way there is no garantee that the translations still fits into the UI (the UI is not involved in the translation process) and might get truncated all over the place. So for an automatic check i would need an idea on how to find truncated Text on the UI.
I tried so far:
Measuring the client size of a control, measuring the text length and
compare them. Doesn't work since there seem to be no way to find out
the ~real~ client size of a control that is used for putting text on
it (For a Button its not just Size minus Padding for example)
Setting AutoSize to true and checking if the control grows. That
would only work for non-wordwrapping controls and there seem to be
no sharp limit here. A control might grow to fit the Text on its
surface when setting autosize but the Text was fitting before
also. The margins might have been pretty narrow but the Text where
fitting.
Are there more idea that might work? Or are there some tweeks that might make the above mentioned ways work? Would be great if there where a simple Win API method i could call that would just give me the actual shown text of a control not the text a programmer/programm whishes to be shown on a control.
Get the amount of the characters from the non translated version and differentiate them against the length of the translated version then multiply the current controls width by the difference. It could look something like this.
float scalingAmount = 0.1 //This is just an example value, you'd probably want to adjust this yourself
float difference = oldLabel.Text.Length - label.Text.Length;
label.Width = oldLabel.Width * (difference/scalingAmmount)

How do you calculate pixel size of string?

I have a string. I know the font family and the font size it is going to be displayed in. I need to know how many pixels the text will take up in the ui. So that I can determine whether to show another element. How would I do that?
I found a couple of things, but none of them were available in my Windows universal project. For example:
Graphics.MeasureString
TextRenderer.MeasureText
Edit:
This is not a web project.
I want to calculate the size it will take in the ui before it is in the ui.
I think you need to create a textblock in code and assign the desired text to it. Then you can get the actual height and width from it. See the below code
TextBlock txt=new TextBlock();
//set additional properties of textblock here . Such as font size,font family, width etc.
txt.Text = "your text here";
var height = txt.ActualHeight;
var width = txt.ActualWidth;
You can do further operations based on this height and width
I am not saying this is the optimized solution .But this will work for you
Try checking the values of the Width and Height properties of the control you use to display your text (eg. your TextBox), after setting your string as text/content, to decide whether to show another element.

Limit text to width of TextBox

I'm using a TextBox to create an editable title on something that looks like a post-it note. I changed to a TextBox from a RichEditBox to see if that could solve my problem, which it didn't, so I'm willing to change back if that helps.
My problem is that I don't want the user to be able to enter more characters than fit in the set width of the TextBox, because I want the whole title to be visible. Setting a fixed limit to the amount of characters that can be entered doesn't really work since for example 10 large M's would fill the width of my TextBox, but other characters will only fill half of it. So I would like to compare the width of the text to the width of the TextBox, so I can restrict input beyond that point.
Edit: I'm using the Segoe UI font, and I don't really consider changing the font to one with characters of equal width as a solution.
Set the TextBox Font to a Courier Font, then all characters are equal width and calculating max becomes trivial.
I am suck in programming world. i m try help you..

Display unsorted data in SL3 line chart

I'm having trouble with my Silverlight Chart. My model is unsorted, that is, the sorting is done on the server side. It needs to support year transitions, but as you can see from the screenshot the charting control automatically sorts the model and fills in the gaps. The line sort be ever increasing and not taking a dip on new year.
How can I make the chart display the data in the order specified in the grid control to the left?
Btw, using SL3
alt text http://img705.imageshack.us/img705/7602/unsortedsilverlightchar.png
The line chart is not designed to do the task you seem to be asking. After all the purpose of a line chart is to help the user trace a trend or even visually interpolate an interim value. However if the interval between horizontal points is not linear and always traveling in the same direction such lines meaningless.
I would therefore suggest that the Line chart is not appropriate or that you have some other hidden data which should be used for the Y-axis which would make the lines meaningful.
Alternatives might be to use a Scatter graph or a Column series where the y-axis value has been converted to a string and thus cause the series to use a Category based axis instead of range based one.

Categories

Resources