Tabbed text in label - xamarin.forms

I'm trying to create an Android app that contains the World 8 Ball Pool Rules (https://www.epa.org.uk/Downloads/Rules_World_Rules_2019.pdf), to make it easier for me to have a mobile version of the rules, and develop my skills with xamarin.forms
Some of the rules have sub rules
e.g.
When playing from the Baulk:
The centre point of the Cue Ball.........
The Cue Ball can be moved......
The Cue Ball may be played.....
I'm trying to add the list, or at least indent the text in a label to format the string to look like the above.
Is there a special sequence of characters to create the tab (like
is for new line)?

If I were doing this, I would probably use separate Labels and use a margin to indent them. It is far neater than the horrible syntax you would need to do it in a single Label. Examples:
<StackLayout>
<Label Text="When playing from the Baulk:"
BackgroundColor="Red" />
<Label Text="1. The centre point of the Cue Ball........."
BackgroundColor="Red"
Margin="10, 0, 0, 0"/>
<Label Text="2. The Cue Ball can be moved......"
BackgroundColor="Red"
Margin="10, 0, 0, 0"/>
<Label Text="3. The Cue Ball may be played....."
BackgroundColor="Red"
Margin="10, 0, 0, 0"/>
<Label Text="When playing from the Baulk:
1. The centre point of the Cue Ball.........
2. The Cue Ball can be moved......
3. The Cue Ball may be played....."
BackgroundColor="Blue" />
</StackLayout>
gives:

Related

How to calibrate analog joystick to screen

I am having a problem with my analog joystick. I have set it up to move the mouse position accordingly to the joystick values. On a technicality, it does work, as it does control the mouse. However, the calibration is off and when I test it, the mouse stays off-centered on the screen at rest and can only move around from that "center" position. I have scoured the internet trying to find a solution, but alas I must ask.
Snippet:
int xMapped = map(xread, 0, 1023, 0, 1920);
int yMapped = map(yread, 0, 1023, 0, 1080);
I have done testing to the joystick and can confirm the min and max values are correct.
(I feel like I may have weirdly worded the situation, so here is a ms paint visual :D)
Expectation
Circle-Mouse
Rounded Rectangle-Range
Rectangle-Screen
What Happens

Xamarin Forms - AbsoluteLayout - How does works positions

I'm working with Xamarin.Forms with AbsoluteLayout, however, I'm not sure to understand how to works the positionning of elements.
I'm working with Proportional Values so if I'm placing an element at AbsoluteLayout.LayoutBounds="1, 0.05, 0.15, 0.1" where each values is Proportional (so the flags are "all" AbsoluteLayout.LayoutFlags="All")
It will be placed at the top/right of the screen. It will not take a place a bit outside however. So what does it means? Each element are repositionned into the screen if they go outside?
But now, another question comes, when you place an element, on what is based the X/Y position? Does is the center or another point?
On this example, I tried with 0.15 but the rendering was a bit weird, so I put 0 and then the rendering match with what I want.
You could say "Test it and you'll see.", however, It's a waste of time for the designer and me, to position every elements, because we're not sure to understand how does it works. So we juste make try with debuging..
We are also searching to know if a software exist to generate positions about the design made by the designer. We mean the position X/Y of the element in percent.
Thank in advance !
With AbsoluteLayoutFlag.All, the Rectangle bounds parameters have the following meaning:
x means the percentage of the remaining space (i.e parent width - control width) which should be on the left of the control
y means the percentage of the remaining space (i.e parent height - control height) which should be on the top of the control
width is the width of the control in percentage of the parent width
height is the height of the control in percentage of the parent height
Width and height are what people usually expect. However, x and y are not as people are more used to "left" and "top". So you can write a converter to convert left percentage into x and top percentage into y:
x = left / (1 - width)
y = top / (1 - height)
<AbsoluteLayout BackgroundColor="Yellow">
<BoxView
Color="Red"
AbsoluteLayout.LayoutBounds="1.0, 1.0, 0.5, 0.5"
AbsoluteLayout.LayoutFlags="All" />
<BoxView
Color="Green"
WidthRequest="50"
HeightRequest="50"
AbsoluteLayout.LayoutBounds="0.1, 0.1, AutoSize, AutoSize"
AbsoluteLayout.LayoutFlags="PositionProportional" />
<BoxView
Color="Blue"
AbsoluteLayout.LayoutBounds="0.25, 0.25, 0.5, 0.5"
AbsoluteLayout.LayoutFlags="All" />
</AbsoluteLayout>
When I researched AbsoluteLayout I created this sample and
Test it and you'll see
What I've decided from my investigation:
X and Y are coordinates of top left corner of View. It's relative position. As you can see for red rectangle 1.0, 1.0 is center position, so, as I understand, 100% width of screen is 2.0(same for height). All views inside AbsoluteLayout positioned dependently on values of parent AbsoluteLayout.
Edited:
X and Y are center coordinate of View, not left top corner. And 100% of Width is 1.0.
I did some testing and found that,With AbsoluteLayoutFlag.All, essentially the X value given as a Percentage basically represents where the anchor is on a rectangle. As in if X = 10% then the anchor is 10% from the left of the Rectangle:
example
At X = 0.1 with a given width of 20%. 90% of the length will go to the right and 10% will go to the left.
At X = 0.5 with a given width of 20%. 10% will go to left and 10% to the right.
Formula for X bounds
Variables in Rectangle (Ax, Ay, Wx, Wy):
W - required width
Ax - X value. (anchor position)
X1 - X position value of top left corner relative to left side (X = 0)
X2 - x position value of top right corner relative to left side (X = 0)
The Formula has 5 possible scenarios for an Anchor value
Ax = 0:
X1 = 0 & X2 = Wx
Ax = 1:
X2 = 1 & X1 = (1 - Wx)
Ax = 0.5
X1 = Ax - (0.5)(Wx)
X2 = Ax + (0.5)(Wx)
0 < Ax < 0.5
X1 = Ax - (Ax)(Wx)
X2 = Ax + (1 - Ax)(Wx)
0.5 < Ax < 1
X1 = Ax - (Ax)(Wx)
X2 = Ax + (1-Ax)(Wx)
X && Y are the center of the element
As a late answer, I've put a nuget package with a fork of AbsoluteLayout but working as I'd expect.
Install nuget package SmartMachines.AbsoluteLayout, add namespace xmlns:sm="clr-namespace:SmartMachines;assembly=AbsoluteLayout" and you will have exactly same AbsoluteLayout as native Xamarin, but with expected Proportional alignment behavior.
Hope that will save other people several hours on googling and debugging.
With AbsoluteLayout.LayoutFlags="All", the LayoutBounds (x, y, width, height) should be interpreted as follows:
width and height simply represent the respective dimensions of the child as a proportion of the AbsoluteLayout's overall size. For example, a width of 0.1 would create a child 10% of the width of the layout, 0.9 would cover 90% and 1.0 will fill the parent from left to right.
x and y represent the position within the parent, relative to the extremes of movement possible with the child still wholly visible within the layout. So: an x value of 0.0 places the left edge of the child against the left edge of the layout container and a value of 1.0 aligns the child's right edge with the container's right edge. Values between 0 and 1 represent positions between those extremes, moving the child proportionately through the range of movement available to it when the child is kept completely within the layout.
A nice way to think about the x / y positioning is to compare it with a window scroll bar or a value slider control because the whole scroll bar is visible at all times and it can be thought of as sliding between a value of 0 (document at top) and 1 (document at bottom).
Needless to say, centring a child is done by setting x or y to 0.5, regardless of width or height values.

glOrtho results are not what I expected

I am a little perplexed as to the trouble I am having with glOrtho(). My code works in the following case:
// Scenario 1
...
glOrtho(0, _width, 0, _height, 0, 1);
...
glRasterPos2i(0, 0);
...
However, I am unhappy with this coordinate system, I would like it to use:
// Scenario 2
...
glOrtho(0, _width, -_height, 0, 0, 1);
...
glRasterPos2i(0, -_height);
...
Unfortunately, only changing the two lines above in my code leaves me with a blank screen. I assumed I did not understand how glOrtho() and glRasterPos2i() work, as I am fairly new to OpenGl, so I tried the following:
// Scenario 3
...
glOrtho(0, _width, -_height, 1, 0, 1);
...
glRasterPos2i(0, -_height);
...
And, to my surprise, it worked! Why is this? The above code is not sufficient for my purposes, so I will stick with scenario 1 unless I can solve my problem. Does anyone have any insight as to why Scenario 1 and 3 work, but Scenario 2 does not? According to my web searches, Scenario 2 should work, so I must misunderstand something.
If it helps, I am using glDrawPixels() to draw an image, where _height and _width are the height and width of the image.
I am using Windows 7 and Qt 4.7.4.
If you need any more info, let me know.
edit: Typo in the original, it should read glOrtho(0, _width, -_height, 0, 0, 1) instead of glOrtho(0, _width, _height, 0, 0, 1).
You raster position is on the corner of the window. My guess is that round-off error is causing the position to be clipped in some cases but not others.
I think that the answer is glWindowPos(), which was added in version 1.4. Like the name says, it sets the raster position directly in window coordinates, unaffected by the modelview and projection matrices. Importantly, the raster position will always be valid, even if the position is on or outside of the window bounds. The disadvantage is that you'll have to do the coordinate mapping yourself before calling glWindowPos().

How should I smooth the transition between these two states in flex/flashbuilder

I have an item in which has two states, best described as open and closed, and they look like this:
and
And what I'd like to do is is smooth the transition between one state and the other, effectively by interpolating between the two points in a smooth manner (sine) to move the footer/button-block and then fade in the pie chart.
However this is apparently beyond me and after wrestling with my inability to do so for an hour+ I'm posting it here :D
So my transition block looks as follows
<s:transitions>
<s:Transition id="TrayTrans" fromState="*" toState="*">
<s:Sequence>
<s:Move duration="400" target="{footer}" interpolator="{Sine}"/>
<s:Fade duration="300" targets="{body}"/>
</s:Sequence>
</s:Transition>
<s:Transition>
<s:Rotate duration="3000" />
</s:Transition>
</s:transitions>
where {body} refers to the pie chart and {footer} refers to the footer/button-block.
However this doesn't work so I don't really know what to do...
Additional information which may be beneficial:
The body block is always of fixed height (perhaps of use for the Xby variables in some effects?).
It needs to work in both directions.
Oh and the Sine block is defined above in declarations just as <s:Sine id="Sine">.
Additionally! How would I go about setting the pie chart to rotate continually using these transition blocks? (this would occur without the labels on) Or is that the wrong way to go about it as it's not a transition as such?
The effect I'm after is one where the pie chart rotates slowly without labels prior to a selection of a button below, but on selection the rotation stops and labels appear...
Thanks a lot in advance!
And apologies on greyscale, but I can't really decide on a colour scheme. Any suggestions welcome.
If you dont mind doing some actionscript coding, this becomes pretty easy with an as3 function.
You would need to do the following:
public function doTransition():void
{
var move:Move= new Move();
move.target=footer;
move.yFrom = 0;//current position
move.yTo = 400;//or whatever is the final position of the footer
move.duration=500;//duration in milliseconds
var resize:Resize=new Resize();
resize.target=body;
resize.heightFrom=0;//or whatever is initial height
resize.heightTo=400;//or whatver is the final height
resize.duration=500;
var fadeIn:Fade =new Fade();
fadeIn.target = pieChart;//the id of the piechart
fadeIn.alphaFrom =0;
fadeIn.alphaTo = 1;
fadeIn.duration =500;
move.play();
resize.play();
fadeIn.play();
}
This done, you would need code to rotate the pie chart.
For that you can use timers and rotation transformations.
To make your tweening easier, I'd recommend using TweenLite to get the job done. You'll end up writing less actionscript.

Flex 4, rotation transition, use shortest route?

I have this object in Flex 4
<s:Group
id="shanks"
width="243"
height="243"
x="243"
y="243"
rotation.Classic="0"
rotation.Centro="72"
rotation.Lace="144"
rotation.Lido="216"
rotation.Euro="288"
clipAndEnableScrolling="false">
<mx:Image source="{circleUnder}" x="-243" y="-243"/>
</s:Group>
It is a circle divided into 5 equal parts each 72 degrees. So each state you can see is increases the rotation by 72 degrees.
I have a transition for the rotation when the state changes like so:
<s:transitions>
<s:Transition>
<mx:AnimateProperty target="{shanks}" property="rotation"/>
</s:Transition>
</s:transitions>
Being that this is a circle you can actually rotate CW or CCW to get to the right degree for the state. Usually the rotation-transition uses whichever is lower. For example to get from Classic to Centro (0 to 72) it goes CW. But this is not always the case. To go from Lace to Lido (144 to 216) it goes CCW. This is not desired sense it would make a much better transition to go CW because it requires less spinning of the circle to get to the desired degree.
What I want is for the circle to spin in the direction which requires the least amount of rotation to reach its destination degree.
I hope this makes sense. Is there a way to set the transition to do that?
I don't think you should use mx:AnimateProperty. Try the new spark Rotation class in your transition. You will also probably want to set autoTransformCenter to true which tells the overall transform effect that the operation will happen about the center of the object.

Resources