Resizing a button with higher values of Height and Width is less smooth than with lower values in WPF - wpf

I have a button which Max and Min height X width are 1024X1360 and 72X95 pixels. I am resizing this button by handling DragDelta events of Thumbs present in button's Template. The problem is the updation of height and width at lower levels, i.e upto 210X280, gives out a smooth operation which is not the case with greater sizes. Anybody out here has faced the issue? Any suggestion to improve the user experience in this situation.

The easiest fix here is to make the contents of your button less complex. In general, the more stuff there is to draw inside of it (i.e. larger size) the longer it is going to take to draw it. This can become even more problematic when you consider that hardware will play an (unpredictable) role in the performance as well.
So a couple of easy options: Mix and match for best results.
1. Make your button less complex.
2. Limit its maximum size. (To something smaller)
3. Accept the choppiness.

Related

Scroll bar slider behavior

I am implementing a scrolled window control.
I need to draw simple scrollbar sliders for this purpose.
Usually, sliders shrink as the content grows, but I am unable to understand how.
What is the relation/ratio formula? I've made several google tries to find out, but I didn't.
Does it have a minimum size it can go or it is just really hard to shrink it that far due to exponential shrinking behavior? We are talking simple generic scrollbars. What would be the proper way to implement the proper slider dynamic sizing?
Obviously this question is so dumb that nobody would bother answering.
I used to make complex hacks but now the simplest logic just slipped away across my mind.
The horizontal scroll bar slider width is the portion of the content (child) width.
(width / content) * width
width * width / content

WPF dynamically scale TextBlock Text without filling a container

I have a set of pages that look like this:
I have the content in grids with * Heights and Widths so the grid correctly scales when the entire window resizes. I would like the text to resize with the grid. Basically I would like the user to resize from this:
To this:
(preserving white space)
One way to do this would be to wrap the TextBlock in a ViewBox with margins on the right and bottom (for Grid.Row="3") to account for white space. But because I have several pages with different lengths and line counts I would have to set the margin specifically for each page otherwise the text sizes would differ on each page. Is there a better way to do this??
I don't think there is a better way to do this. There are different ways. But, I think it isn't just a matter of opinion that they would not be better.
Ways I can think of.
Render your text offscreen, rendertargetbitmap that so you've got a picture. Change your textblocks on screen to images and stretch them.
Or
Work out the size your text wants to be. Then do some calculation comes up with a different fontsize which is "better". This is a lot easier to write a description of than do.
In my opinion.
A viewbox is easier to implement. Way less error prone than calculations. Will give at least as good results as rendering to a picture.
I just want to add one more solution to the ones suggested by Andy, which is more of a scientific approach and takes a bit of practice to master.
Suppose you have to find a function F, which maps one or more variables to a desired single value. In your case that would be a function F, which takes aspect ratio of the window as input and outputs an appropriate font size.
How can you find such a function?
Well... you don't need to do any math yourself!
First, you need some data to begin with:
1. Resize the window randomly
2. Calculate aspect ration (X)
3. Pick an appropriate font size that looks good enough (Y)
4. Repeat the measurement 7 to 10 times (sorry data scientists)
5. Enter the data in Excel - one column for X and another one for Y
6. Insert a scatter chart
7. Choose the best trendline for your data, but avoid the polynomial one
8. Display the trendline equation and use the expression in your code
Now I should mention the pros and cons of this regression technique.
Pros:
1. It can solve a wide range of tricky problems:
"I use this 3rd party control, but when the text is too long it overlaps the title bar. How to trim it so it doesn't go beyond the top border?. Deadline is coming!"
2. Even if it doesn't solve the problem perfectly, the results are often acceptable
3. It takes minutes to try out unlike spending a day refreshing your math skills
Cons:
1. The biggest problem is that to keep it simple, you often lower the number of
variables by assuming some of them to be constant. In this post I've assumed that
the font family won't change for example, neither the font weight.
2. If any of the assumptions does not hold the final result could be even worse
This technique is fragile, but powerful. Use it as your last weapon and never leave magic expression like
fontSize = (int)(0.76 + 1.2 * aspectRation) without documenting how it came to be.

Codename one SpanLabel text does not occupying full width

I'm using the SpanLabel Component, but on the screen the text content does not occupying the full width when text size is lower
Someone can help please?
This can happen if the width isn't deterministic. The SpanLabel won't be able to reflow and at best will cause only its own Container to resize. There are two solutions:
Deterministic hierarchy - this is generally best but not always possible
Use TextArea - sometimes this works around the issue by reducing the hierarchy depth.
Deterministic layout means that the size of the elements is determined in a clear way by the hierarchy. E.g. BoxLayout.Y is deterministic on the X axis as it gives the components on the X axis all available space. FlowLayout isn't deterministic as it gives components their preferred size.
Some layouts can go back and forth and vary in determinism based on their axis.
This is important because when we layout the components we go from top down. So we go through the Form to its children asking each for their preferred size. If at this point the SpanLabel doesn't know its size it can give the wrong value and we can't really fix that later as we don't reflow the UI. Reflow would create a potential infinite loop and a performance problem at best.
We try to workaround some of this behavior by making a revalidate() call within TextArea but that has its limits. If the hierarchy is too deep the preferred size is already set and won't adapt. SpanLabel is just a Container with a TextArea and a Label (for the icon). So by only using a TextArea you'd slightly simplify the hierarchy and it sometimes might be enough. E.g.
TextArea t = new TextArea(myText);
t.setEditable(false);
t.setFocusable(false);
t.setUIID("Label");

Distribute text top-to-bottom instead of left-to-right

I'm working on a view that's implementing a multi-column text layout using CoreText (using CTFramesetter).
CoreText usually fills each frame completely, so when I call CTFramesetterCreateFrame with three rects that make up my columns, I get a layout that's similar to the following image:
So the left column is filled completely, the middle column partially and the right column is empty. But instead, I'd like the text to distribute over the three columns so that they take up the least vertical space possible, like in this image:
How to achieve this with CoreText?
I don't mind going low-level here, even drawing each CTRun by hand is an option if necessary.
One idea I came up with would be to create a large frame with the width of a column and then figure out which CTLine to draw in which column. But this has a few limitations:
It would only work if all columns had the same width.
It does not work with clipping paths.
Unfortunately, I'll need to use clipping paths (as in kCTFrameClippingPathsAttributeName) so this idea is out. I could live the fixed column width limitation, though.
Another idea would be to reduce the height until the last frame overflows but that's a pretty brute-force way that surely wastes resources.
(BTW, due to compability requirements the use of TextKit classes like NSTextStorage isn't possible; the resulting view is intended to be used on Mac and iOS, but it needs to work on iOS < 7)
Since there doesn't seem to be a non-expensive way to solve this, here's how I've done it:
I did go with the "reduce the height until the last frame overflows" approach. To reduce the height, I simply have another clipping path (kCTFrameClippingPathsAttributeName) which is a rectangle that fills the bottom of the view to the required height.
The probably most expensive but simple way would have been to increase the rectangle height until finally the text doesn't fit inside the last frame any more.
Instead I've implemented a binary search for that. For my demo app, I usually find the correct height after 8-10 recursions which still is expensive but at least it's pixel-perfect and doesn't rely on any other information other than "did the last frame overflow".

Smaller PanoramaItems in a Windows Phone 7 app

Is it possible to decrease the default width of a Panorama control's PanoramaItems?
They can be made wider by specifying Orientation="Horizontal" and a width larger than 432. However, specifying a width less than 432 does not result in a smaller PanoramaItem. It's minimum width is 432 always.
I played around with the templates but couldn't figure out how to achieve this.
I'm afraid there isn't anything you can do about that. The Panorama has the width of its items baked in as 48 pixels less that its own width.
PanoramaItems are not designed to have a smaller width. If you wanted to do this you'd probably need to create your own version of the Panorama control.
Don't do this though!
Not only would it be a lot of effort to get right you'd break user expectations about how the panorama would work.
Would/could you allow multiple items to be displayed at once?
What would be the impact on navigation?
How would you communicate to users that your app works slightly differently to all the other ones on the phone?
How would you justify the mental cost to the user of the different behaviour?
What would the impact be on the item headers if they were smaller?
With the PanoramaItem width set to at least (almost) the width of the screen it allows the user to see and focus on a single item at a time.
Also, potentially having fewer items on screen at once can also help with performance too.

Resources