Right justify a list of values - autohotkey

I am an irregular AHK user and typically work at the edge of my knowledge.
I usually need to keep the help files to hand.
I am using Version 1.0.48.05 and have a problem.
In a nutshell - I want to print a list of numeric values using the Gui interface so that the values line up under each other justified to the right.
I can not find an easy or robust way of doing that. What am I missing.
The values can vary from 0 to 9999. They are always integers.
====================
This is a snippet of code before I try to right-justify :
tabpos := 200
Gui, Add, Text, x%tabpos% y300, %value1%
Gui, Add, Text, x%tabpos% y320, %value2%
Gui, Add, Text, x%tabpos% y340, %value3%
Gui, Add, Text, x%tabpos% y360, %value4%
That prints my values at the "tabpos" position but all left-justified.
My first attempt to right-justify was to use a function which padded with a number of spaces determined by the length of the "value" . For exammple :
Gui, Add, Text, x%tabpos% y300, % pad(6, value1)
pad(width, val)
{
ans := SubStr(" ", 1, width-StrLen(val)).val
return ans
}
But that did not work well as the width of a digit was not the same as (or a multiple of) the width of a space.
Where I introduced a multiple into the function, that worked differently for different type sizes and typefaces.
My second attempt was to adjust the "tabpos" by a number of pixels depending on the length of the "value". For example :
newpos := tabpos - 9*StrLen(value1) ; Where a digit is 9 pixels wide
Gui, Add, Text, x%newpos% y300, %value1%
But that only works well where a digit is exactly 9 pixels wide. I would like a more general, robust method.
I have tried using the AHK SetFormat instruction, but have failed to get any effect. Perhaps I am using it incorrectly. In any event, it appears that SetFormat works by padding with spaces and so it would have the same effect as my first attempt (above) with the same problems.
==================
Any suggestions will be very welcome.
I would like the method to work whatever the typeface, type size, whether bold or normal, and whatever the DPI of the monitor.

How about...
Gui, Add, Text, x100 y100 w100 Right, 123
Gui, Add, Text, x100 y120 w100 Right, 123456
Gui, Add, Text, x100 y140 w100 Right, 123456789

Related

How can I hide a label if another label is taking up X number of lines?

Say I have two labels, one on top of the other. Label 1 is set to have a maximum number of lines of 2 (numberOfLines=2). So sometimes, depending on the text, Label 1 can take up TWO lines. The thing though is that a maximum of 2 lines should be shown between both labels, where Label 1's second line takes precedence over Label 2. (Also, Label 2 is always 1 line.)
So either of these 2 scenarios are possible:
Label 1 text
Label 2 text
OR
Label 1 text (line 1)
Label 1 text (line 2)
The only way I thought to attack this was to simply hide Label 2 if Label 1 is taking up 2 lines. But the problem is, how can I determine how many lines Label 1 is taking up?
I've found a few other answers about this (1, 2), but none seem to work for me. Is there perhaps a better way to go about this?
In my opinion, you should just use one label, and construct the text seperately by the code and pass the final text into the label. In order to have a new line, you can use "\n". If you want to have a different fonts/color etc, you can always use AttributedString. This will be much cleaner, easier to change, and more flexible to maintain in the future.
Did you working with Constraint? or Did you have knowledge about NSLayoutConstraints?
you can easily do that with managing proper constraint and it doesn't matter how many line will text have you can show both label with text.
make sure label.numberofline = 0. // It will take line as text.

How to align text when the middle is bold?

I have a script that needs to have an emboldened word. If I use:
Gui, Add, Text,, % "Dispassionated Concentration: "
Gui, font, bold
Gui, Add, Text,x+0, % FormatMinutes(dc)
Gui, font
Gui, Add, Text,, % "Non Focused:" FormatMinutes(NonFocused)
. "`nIdle Time:" FormatMinutes(IdleTime)
. "`nTotal Time:" FormatMinutes(TotalTime)
then the result is like this:
If the line is:
Gui, Add, Text,Y+0, % "Non Focused:" FormatMinutes(NonFocused)
If it's x-0 Y+0:
How to align the text?
Use
Gui, Add, Text,xs Y+0, % "Non Focused:" FormatMinutes(NonFocused)
See Gui - Syntax & Usage: Positioning and Sizing of Controls. Admittedly I just try and error without actually understand what they do.

Adjusting graphical LaTeX text size in Matlab

I am trying this example:
http://www.mathworks.com/help/symbolic/latex.html
Let's say I wanted to resize those labels. How? I can't figure out any LaTeX code, and 'fontsize' does not do the trick.
This hits a sore spot when it comes to Matlab's support for (or use of) Latex. The normal font-size commands from Latex aren't available. (In Latex normally you'd just say \Large{Text ... $x$} or even \normalsize ....)
To do this in a Matlab plot you can add fontsize spec at the end
title(['For $x$ and ...'], 'Interpreter', 'latex', 'fontsize', 14)
For more discussion and how to change font type as well see this post. Note that there are not so many fonts readily available in Matlab. To preserve sanity I'd keep this kind of tweaking to the minimum.
There is another method that will work anywhere in Matlab where you can use Latex -- in any text, in the middle of a string, etc: You can drop to Latex's lower level font specification.
title(['\fontsize{15}{0}\selectfont For $x$ and ...'], 'Interpreter', 'latex')
The first command \fontsize{}{} specifies the font, the second one \selectfont actually changes it for the rest of the text. When you want to switch to a different font, even mid-string, you again issue \fontsize{12}{0}\selectfont and you have that font size after that point. The only thing you need to change is the size (I used 15 and 12 as examples), the rest is boilerplate (for this purpose).
See what these things mean and more discussion in this post. For far more detail on fonts in Matlab see this article. For how to change fonts across the whole document see this post.
There are yet other ways but it gets progressively trickier and this should be enough. Probably the best advice is to set it once for the whole document. That also makes sense typesetting-wise.
Note. The font command of the second example must be given outside of math mode. Latex has two major modes, text and math. To make it go to 'math mode', where it processes everything as it were math symbols, you put a $, or $$. (There are yet many other ways, but in Matlab's strings this is all you'll ever use.) When you want it to go back to typesetting text normally, you end math mode with another $, or $$. All math is in between $...$, everything else is normal text.
This is some text, now typeset some math: $y = x^2$ ... back to text.
The font commands do not work in math mode but need be given outside the $...$. They will apply to any following math as well. In a plot command we'd say
ylabel(['\fontsize{16}{0}\selectfont $\dot{x}$'], 'interpreter','latex');
Here is the line that worked:
ylabel('$x_e, x_c$', 'interpreter','latex', 'fontsize', 32);
Obviously, between the dollar signs can be whatever appropriate LaTeX expression desired.

How to set Autohotkey Gui control type slider as float?

By default, the Gui control type "Slider" is ment to be used with integers:
Gui, Add, Slider, range0-10, 0
But what if I want to use it with floating point numbers? I did some research on the internet and found something known as Tickinterval, which should set the value of how much the Slider increases or decreases every tick. So I've tried:
Gui, Add, Slider, range0-10 Tickinterval0.1, 0
But this had no effect at all. This is why I think the Slider only works with integers. Even though there's no mention of it on the official docs: Autohotkey GUI Control Types#Slider
Is there any way to make the Slider work with floating point numbers?
Searching around some more I've found a solution (or workaround) to the problem:
Gui, Add, Slider, vSlider gSlide range0-10 tickinterval1-100 AltSubmit, 0
Slide:
Gui,Submit,NoHide
int := slider/10
fra := Mod(int, 10)
fra := SubStr(fra, InStr(fra,".")+1, 1 )
val := Floor(int) "." fra
tooltip % val
SetTimer, RemoveToolTip, 500
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
I've edited the solution I found to show the correct tooltip when sliding the bar as well. All that's left to do is set the value of val to the correct variable and it works like a charm.

matlab: having a good control of MyBox, box with text

my problem is I want to have a box for additional bigger comments to the graph.
How can I create this box, so that it will be always on the right bottom side outside of my graph, and it will be automatically adjusting its size to the amount of text inside? Also, if I will have longer text, I need it to be split into more lines, not just one line extremely long.
I use it like that, however I have a poor control over what is happening, this just creates a certain size in a certain place, text is cut.. please help :)
x = rand(110)*100;
y = x;
plot(x,y)
MyBox = uicontrol('style','text')
set(MyBox,'String','optional longer information to be put into diagram')
set(MyBox,'Position',[10,0,40,10])
I am afraid you can not do that automatically - Text boxes do not use callbacks. From the documentation:
Users cannot change static text interactively. Static text controls do not activate callback routines when clicked.
What you can do is call textwrap function, which will automatically wrap the text you pass to it and return new Text box position:
MyBox = uicontrol('style','text');
% set initial position - first three values are kept constant after wrap, the hight can be changed
set(MyBox,'Position',[10,10,30,10])
% adjust the height of your Text box and wrap the text
[outstring,newpos] = textwrap(MyBox,{'optional longer information to be put into diagram'});
% set new position and text
set(MyBox,'Position',newpos, 'String', outstring)
You will have to call textwrap and set(...) yourself whenever you change the string in the text box.