App Designer uitextarea control gives position values not in pixels when window is maximised?

Here is the output. Can this be translated into pixels or any alternatives?
ans =
1.0e+03 *
1.2728 0.7737 0.6092 0.1143

 Accepted Answer

When I do this:
fig = uifigure;
txa = uitextarea(fig);
txa.position
I get the Output as 100 100 150 60 which are pixels.

7 Comments

That is true but there is some weirdness in MATLAB that it is often there may be other factors that effect it. So, I just tested the code below which does the job, both in normal and maximised. However, the UI for the app I am working is more and there are more controls in that MATLAB may have to consider when doing the "Auto" anchoring of controls, tho the other controls give pixel values which is wierd that it may be only the UITextarea.
The problem is unreproducible, check the zip also tested it in App Designer.
fig = uifigure;
txa = uitextarea(fig, 'position', [10 100 250 100]);
b = uibutton(fig)
b.ButtonPushedFcn = @(src, event)disp(fig.Children(2).Position)
The app is working perfectly fine with me, as you can see when I click Show Positions button, I can see the position of text area(in PIXELS) in Positions text field.
Also, it works when I maximise the window. Replace the Show Positions callback with
app.PositionsEditField.Value = num2str(fix(app.TextArea.Position));
Also, If you want the components position to be fixed even if window is maximised, you can set the AutoResizeChildren to off
for example
fig = uifigure;
fig.AutoResizeChildren = 'off';
txa = uitextarea(fig, 'position', [10 100 250 100]);
b = uibutton(fig)
b.ButtonPushedFcn = @(src, event)disp(fig.Children(2).Position)
Thanks for your time.
Here is what fix() produced for the numbers that were given by the Position property. Which is does not seem useful.
>> c = [1.2728 0.7737 0.6092 0.1143]
c =
1.2728 0.7737 0.6092 0.1143
>> fix(c)
ans =
1 0 0 0
I am looking to keep it so that it resizes the children, but it should not also change the unit I suppose for specific ones. I have tried applying the unit measurement property to pixels just before calling the Position property of uitextarea.
Apparently the: fix()
fix(app.TextArea.Position)
Did the "fix" so it is now shows pixel values correctly. This problem I supppose is related to the where number editField would show numbers in that representation due too long and this can be resolve by changing "ValueDisplayFormat" property to integer.
FYI:
I came to this conclusion after checking the internal value of the control, using mlapptools, which was intact, only at the higher level was being modified.
I think you are missing out something in c
In the comment above you have considered c as
c = [1.2728 0.7737 0.6092 0.1143]
you are missing to multiply *1.0e+03
which indicates
[1272.8 773.7 609.2 114.3]
which are pixels.
That is correct, they can be restored to correct unit.
Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!