SwiftUI animation affect inner objects - animation

I have question.. if I have several views that has buttons etc elements inside and also has animation on parent view.
How I can avoid that animation affect inner objects. In my case all buttons catch delay from parent view.
I try to use .сlipped, but I helps only for .shadow option, not for animations ;)
Example:
ViewA(editAction: {
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(0.8))
ViewB(editAction: {
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(0.95))
ViewC(editAction: {
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.1))
ViewD(verified: .constant(true), editAction: {
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.25))
ViewE(knowMoreAction: {
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.4))

Link animation to dependent value explicitly, like
ViewE(knowMoreAction: {
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.4), value: isShow)

Related

Squashed Sprite when turning horizontally

Unsquashed Sprite Squashed Sprite
My brother has issues with his sprite squashing whilst moving horizontally. The squashing is permanent after moving. I have found the line that causes the problem but cannot figure out what is causing this issue. When I remove this line the squashing stops however the sprite does not turn. He is following Shaun Spalding's Complete Platformer Tutorial and though I've watched it over I cannot find any issues with the actual code.
/// #description Insert description here
// You can write your code in this editor
// get player input
key_left=keyboard_check(vk_left);
key_right=keyboard_check(vk_right);
key_jump=keyboard_check_pressed(vk_up);
// calculate movement
var move=key_right-key_left;
hsp=move*walksp;
vsp=vsp+grv;
if(place_meeting(x,y+1,o_wall)) and (key_jump)
{
vsp=-7;
}
// horizontal collision
if (place_meeting(x+hsp,y,o_wall))
{
while(!place_meeting(x+sign(hsp),y,o_wall))
{
x=x+sign(hsp);
}
hsp=0;
}
x=x+hsp;
// vertical collision
if (place_meeting(x,y+vsp,o_wall))
{
while(!place_meeting(x,y+sign(vsp),o_wall))
{
y=y+sign(vsp);
}
vsp=0;
}
y=y+vsp;
// animation
if(!place_meeting(x,y+1,o_wall))
{
sprite_index=splayerA;
image_speed=0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed=1;
if (hsp==0)
{
sprite_index=s_player;
}
else
{
sprite_index=splayerR;
}
}
if (hsp != 0) image_xscale = sign(hsp); //this line is wrong and causes the squishing
A possible cause of this is that you've set the image_xscale to a different value before using the line:
if (hsp != 0) image_xscale = sign(hsp);
For example, you may have set this in the Create Event to enlarge the sprite:
image_xscale = 2;
But that value is reset after setting image_xscale again, as that line will only return -1 or 1 because of the Sign().
One quick solution is to apply the scale change to that line of code, like this:
if (hsp != 0) image_xscale = 2 * sign(hsp);
(Once again, presuming you've changed it's scale value somewhere else)
Though another solution is to enlarge the sprite itself in the sprite editor, so the scale doesn't have to be kept in mind everytime.

Kendo NumericTextBox with step and rounding

I want to setup kendoNumericTextBox to allow user input any integer number and set step to 1000. But when user enters any value and use spinner, it should update to next multiple of step.
For example:
enter 123, press spin up, value will be 1000
enter 1234, press spin up, value vill be 2000
Is it possible or only way is to handle spin event and modify value from there?
UPDATE:
Ok, guys, thnx for help.
I have this spin handler now and it seems to be working as expected.
function onSpin(e)
{
var currentvalue = kendo.parseInt(this.value());
if (currentvalue > 0)
{
this.value(Math.floor(currentvalue / this.step()) * this.step());
}
if (currentvalue < 0)
{
this.value(Math.ceil(currentvalue / this.step()) * this.step());
}
}
I have provided a dojo below with a potential solution for you:
https://dojo.telerik.com/UQohUjaP/2
I have created a function that will work on the spin and on change value so that it will step the value up/down on the value that you set e.g. 1000
the function is fairly simple and for brevity I have taken out the log statements here:
function onChange() {
var currentvalue = kendo.parseInt(this.value());
if (currentvalue > 0) {
currentvalue = Math.ceil(currentvalue / this.step()) * this.step();
} else if (currentvalue < 0) {
currentvalue = Math.floor(currentvalue / this.step()) * this.step();
} else {
currentvalue = 0;
}
this.value(currentvalue);
}
Unfortunately there doesn't seem to be a simple way of figuring out if the value has gone up or down so I am basically checking to see if the value is greater than 1 or less than 1 and then calculating the ceiling or the floor for the value and then stepping it in the right direction. in order to cater for zero we have a special condition which just sets the value to 0 assuming that is a valid value in your scenario
As you say, it's possible by listening to the spin event:
$("#numerictextbox").kendoNumericTextBox({
min: 0,
spin: function(e) {
var isUp = e.sender._key === 38,
isDown = e.sender._key === 40;
var m = Math.trunc(this.value()/1000),
value = isUp ? m + 1 : m;
this.value(value * 1000);
}
});
I doubt there's something out of the box, because your needs seem somewhat unusual.

Xamarin -- Set zoom in AVCapture not working

Hello I am trying to increase the zoom of the camera to its max level in my application.
However after setting the AvCapture to its max value it remains at its lowest zoom level on the screen. Below is my code.
void Initialize()
{
var videoDevices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
var cameraPosition = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;
var device = videoDevices.FirstOrDefault(d => d.Position == cameraPosition);
device.LockForConfiguration(out error);
if (error == null)
{
Console.WriteLine("Supports Preset");
var test = device.RampingVideoZoom;
var d = device.VideoZoomFactor;
device.VideoZoomFactor = device.ActiveFormat.VideoMaxZoomFactor;
}
device.UnlockForConfiguration();
while(device.RampingVideoZoom == true)
{
Console.WriteLine("Zooming camera"); //This line is never written
}
//See below for value this returns in Console
Console.WriteLine("Current Format");
Console.WriteLine(device.ActiveFormat);
}
Current Format
<AVCaptureDeviceFormat: 0x1c48049a0 'vide'/'420v' 1920x1080, { 3- 30 fps}, HRSI:4096x2304, fov:59.680, supports vis, max zoom:16.00 (upscales #1.94), AF System:2, ISO:22.0-704.0, SS:0.000005-0.333333>
This code does not affect the zoom of the camera AT ALL.
What am I doing wrong?
videoMaxZoomFactor Definition
A maximum factor of 1.0 indicates that the format is not capable of zooming.
There is no mistake in your code.
As the Documentation said ,if device.ActiveFormat.VideoMaxZoomFactor == 1 ,the zoom is not available.
You can debug the value of device.ActiveFormat.VideoMaxZoomFactor to see if it euqals to 1.

Qt Creator label value

I currently face the following problem:
I have 64 labels. Label_1 all the way up to Label_64.
I also have an int i.
"i" also goes from 1-64
I want that, when i == 1 Label_1 shall display an image. If i == 2, Label_2 shall display that image and so on.
Currently I'd do that with:
if(i == 1)
{
QPixmap pix("...");
ui->label_1->setPixmap(pix);
}
if(i == 2)
{
QPixmap pix("...");
ui->label_2->setPixmap(pix);
}
if(i == 3)
{
QPixmap pix("...");
ui->label_3->setPixmap(pix);
}
...
Is there some way to do that easier? Something like:
QPixmap pix("...");
ui->label_i->setPixmap(pix);
where the choosen label is directly defined by i?
You can store a list of QLabels.
QList<QLabel*> labels;
labels.at(i)->setPixmap(pix)
The disadvantage of this method is that you should manually assign ui->label_i to labels.at(i) for every i from 1 to 64 once:
labels.insert(0, NULL); // empty space to keep numbering the same.
labels.insert(1, ui->labels_1);
labels.insert(2, ui->labels_2);
...
labels.insert(64, ui->labels_64);
Depending on your specific case, you may use a more tricky solution. For example, if all the labels are stored in a QVBoxLayout at position 1 to 64, you can access label i as follows:
QVBoxLayout *layout = ...;
QLabel *label = qobject_cast<QWidget*> (layout->itemAt(i)->widget ());
if (label) // should be true if assumption is correct
label->setPixmap(pix);
You can also use method two to initialise the list of method 1.
See the Qt documentation for more information.

Why doesn't my OpenSCAD model render correctly in thingiverse?

I created a parametric OpenSCAD model, and tried importing it into thingiverse customizer. However, it is supposed to look like this:http://i.stack.imgur.com/BXFsQ.jpg, but it looks closer to this: http://i.stack.imgur.com/rOF5b.png
Does thingiverse simply not render anything correctly, or is there a problem with the model (code reproduced below)
//Do Nothing = 0
//Increment = 1
//Decrement = 2
//Increment + Zerocheck = 3
//Decrement + Zerocheck = 4
//Text position:
//Top left: 0
//Left side inwards: 1
//Left side outwards: 2
/* [Instructions] */
//Instructions for the Left Counter
Left_counter = 0; // [0:Do Nothing,1:Increment,2:Decrement,3:Increment and Check Zero,4:Decrement and Check Zero]
//Instructions for the Middle Counter
Middle_counter = 0; // [0:Do Nothing,1:Increment,2:Decrement,3:Increment and Check Zero,4:Decrement and Check Zero]
//Instructions for the Right Counter
Right_counter = 0; // [0:Do Nothing,1:Increment,2:Decrement,3:Increment and Check Zero,4:Decrement and Check Zero]
//Hole that currently has no purpose
No_Purpose_Hole = 0; // [0:Don't create hole,1:Create hole]
/* [Text] */
//Text to show
Text="";
//Can be used for card number, description, etc.
Text_position=0;// [0:Top left corner (1-3 chars),1:Left side facing inwards (1-12 chars),2:Left side facing outwards (1-12 chars)]
/* [Hidden] */
$fn=30;
include <write/Write.scad>;
punchcard();
module punchcard(){
scale([25.4,25.4,25.4])
difference(){
card(Text);
union(){
if (Left_counter == 1)
hole(3);
if (Left_counter == 2)
hole(1);
if (Left_counter == 3){
hole(3);
hole(5);}
if (Left_counter == 4){
hole(1);
hole(5);}
if (Middle_counter == 1)
hole(2);
if (Middle_counter == 2)
hole(8);
if (Middle_counter == 3){
hole(2);
hole(4);}
if (Middle_counter == 4){
hole(8);
hole(4);}
if (Right_counter == 1)
hole(10);
if (Right_counter == 2)
hole(7);
if (Right_counter == 3){
hole(10);
hole(9);}
if (Right_counter == 4){
hole(7);
hole(9);}
if (No_Purpose_Hole == 1)
hole(6);
}}}
module card(text){
difference(){
cube([3.3,1.8,.1]);
translate([0,0,-.5])union(){
//positioning holes
translate([1.65,.25,0])
cylinder(d=.25,h=1);
translate([1.65, 1.55,0])
cylinder(d=.25,h=1);
//threading holes
for(x=[.125,3.175])
for(y=[.125,1.675])
translate([x,y,0])
cylinder(d=.125,h=1);
}
if (Text_position == 0)
translate([.4,1.675,.1])
scale([.04,.04,.1])
writecube(text = Text, face = "top", size = .01);
if (Text_position == 1)
translate([.1,.9,.1])
scale([.04,.04,.1])
rotate([0,0,90])
writecube(text = Text, face = "top", size = .01);
if (Text_position == 2)
translate([.1,.9,.1])
scale([.04,.04,.1])
rotate([0,0,-90])
writecube(text = Text, face = "top", size = .01);
}
}
module hole (position){
translate([.3*position,0.7,-.5])
union(){
cylinder(d=.2, h=1);
translate([-.1,0,0])
cube([.2,.3,1]);
translate([0,.3,0])
cylinder(d=.2, h=1);
}}
Can you please specify how the rendering of thing-verse is off? The second image simply looks like the rendering of OpenSCAD. If you have already found an answer to your question, please let me know about the answer.

Resources