Get a minimum value between view high and view width - sass

I'm fairly new to scss, I'm trying to make a variable that has the minimum value of 10 percent view height and 10 percent view width.
my approach is
$size = min(10vh, 10vw);
But I would get unit not comparable error.
How would I solve such issue? Thanks in advance

I think that this can't be done.
At transpile time SASS doesn't know what the height and the width of the viewport are gonna be (think about the change of orientation of a tablet). That information is only available on the client device.
This can't be done in CSS either (there is no max or min function), see Calc of max, or max of calc in CSS

Related

Need a little help on an equation for a GUI "Slider"

This is a small equation that's giving me a headache, I'm close to solving but- Ugh.
I'll try to be prompt.
I have this:
As you see it is a slider that goes from 0.1x to 3x Difficulty.
I have other sliders like this, for audio for example that just go from 0% to 100%.
That works fine.
However, with a minimum value greater than 0 my math breaks a bit and I'm stuck not being able to
perfectly slide the bar all the way to the bottom because it isn't 0 and it is 0.1 instead.
I want to make it to where even if the minimum value isn't 0, the bar goes all the way to empty.
Here is the relevant equations/calculations at play:
var percent = val/val_max
var adjustment = ((x2-x1)*val_min)-((((x2-x1)*val_min)*percent)*val_min)
var x2_final = (x1+((x2-x1)*percent))-adjustment
percent is the percentage of the current value relative to the max value (0.0 to 1.0)
adjustment is trying to find how much to additionally add/remove from x2_final based on the current value to keep the slider properly scaled when the minimum value isn't 0. (This is where the problem is)
x2_final is the final (in pixels) coordinate where the slider should stop based on the previous calculations.
Initially the slider would over fill when full (that was fixed by the current adjustments) but now the slider doesn't go all the way empty and leaves a "0.1" worth of slider.
I don't usually use forums or stackoverflow as I try to figure out things on my own but so I apologize if my explanation needs work.
Here is what the slider looks like when I set it as low as it will go:
Also, if I have more math related problems, are there any good tools I can use to help simulate my calculations like this so people can run it for them selves or something?
Thanks in advance!
Solved it!
So my equation was a bit wrong for the adjustment.
As now it looks like this:
var percent = val/val_max
var percent_min = val_min/val_max
var adjustment = ((x2-x1)*percent_min)-(((x2-x1)*percent_min)*percent)
var x2_final = (x1+((x2-x1)*percent))-adjustment
And now the slider properly fills to full as well as empties to the bottom,
regardless of what the minimum value is.
But I also noticed then the bar as I was sliding it wasn't following my mouse.
So to fix that I had to go later in my code where I update the current value of the slider as the user clicks and changes it...
var mouse_x_percent = round2((mouse_x-x1+adjustment)/(x2-x1+adjustment),2)
Just had to add the adjustment to both sides of that calculation (getting the mouse_x's percentage relative to the beginning and end of the slider itself which would then be used to calculate the new value by multiplying the mouse_x_percent with the max value).
(Round2() takes two numbers, the first being the number to round, and the second to what decimal place)
Always love solving a problem, I hope this helps someone else.

Unity: How to calculate scrollbar value needed to move the content with known value?

I have a dynamic way to increase content size depending on number of elements on it.
As the content increases, scrollbar size decreases and the value of scrollbar value needed to move the content by fixed number (100 to right for example) changes also (decreased).
Can I have a method that scroll the content by a fixed number without depending on scrollbar size and value (or an equation that can get the value needed each time)?
Edit:
I know how to scroll by changing Scrollbar.Value (from 0 to 1). But I need to scroll by a fixed number (ex: 100) not a ratio (0-1)
Scrollbar is just a control which is there for the user to scroll and behind the scene it manipulates ScrollRect.horizontalNormalizedPosition and ScrollRect.verticalNormalizedPosition.
You don't use scrollbar if you have to set the value manually using code. You directly deal with scrollrect's normalized position (which is ranged 0-1).
You can change this value proportionally by calculating the total size of ScrollRect and then finding the ratio of your desired scroll value. Something like this:
float totalWidth = // find total width of scroll rect transform.
float targetValue = 100;
float targetPercentage = targetValue/totalWidth;
scrollRect.horizontalNormalizedPosition = targetPercentage;
Now if your scrollrect is 500 and you want to scroll to 100.
your target percentage will be 100/500 (= 0.2f)
I hope you can figure out the rest.

Gradually move from one color to another

I have a program where I have a slider, and when i move it up or down (left or right) the color changes gradually. Sadly I am not able to achieve this. My colors change yes, but it is very sudden! I have the 7 colors of the rainbow on seperate .png files and when I scroll the respective one comes up. I was wondering if there was anything I could do to make the colors morph or blend into each other better to make the transaction appear muuch more smoothly.
Thank you
UPDATE
if(self.slider.value > 7 (
{
self.label.text=#"red";
//self.imgView.backgroundColor=[UIColor redColor];
// self.imgView.backgroundColor=[UIColor colorWithPatternImage:#"redPicture"];
self.view.backgroundColor=[UIColor colorWithRed:146 green:50 blue:146 alpha:1];
}
This is going to be a generalized answer because I'm not going to write your code for you (not least because I have never written a letter of xcode in my life), but this should put you on the right track.
You want a continuous spectrum of color, so that should tell you right off the bat that using a series of if statements is the wrong way to go. Instead, you should calculate the color you want by doing some math with the slider value directly.
You haven't told me what your slider range is and whether it's discrete, so for the purposes of this answer let's call the lowest value min and the highest value max, just to keep things general. So your total range is max - min. Let's express the value of your slider as a percentage along this range; we can calculate this as (self.slider.value - min) / (max - min). (For instance, for a slider that goes from 0 to 50, a slider value of 37 gives you (37-0)/(50-0) = 0.74.)
So now you should have a decimal value between 0 and 1, which you can map along the Hue-Saturation-Value color scale. I don't know if xcode has a HSV method directly (this answer has some code which might be helpful), but if not it's pretty easy to convert HSV to RGB.

jQuery Max Length Plugin

Is there any plugin for jQuery that would take an argument for the max length of a field and then size the width of the same field in respect to it?
Calculating the width depending on the field size is not possible, since different letters have different sizes (compare i and w). A possibility would be to take the size and multiply with the width of a w, but then the field would become very/too big. It also depends on font settings and I am unsure about possibilities to get font dimensions from JavaScript.
Taking this in mind: I do not think there are any (good) working plugins for jQuery out there... But maybe someone else is able to prove me wrong?

Change the maximum width OR maximum height of a form in .net

I've been meaning to ask this question for a while.
It appears that if I want to set a maximum width of a form then I have to set a maximum height as well.
Is this right?
If so, which of the multitude of variables do I use, in this situation, to set the maximum form height to the height of the window?
Screen.PrimaryScreen.Bounds?, Screen.GetWorkingArea(New Point(0, 0))?
Eta: From further investigation, I think PrimaryScreen.Bounds and GetWorkingArea are the same.
Also, having thought a little more, should I put Int32.MaxValue into the height property instead of the max height of the window?
Yes, you do have to set the max width and height together using a Size instance. If you do not want to limit one of the dimensions, you might want to consider using System.Windows.Forms.SystemInformation.MaxWindowTrackSize to get the max for the "unlimited" dimension.

Resources