In SwiftUI, "onHover" does not call back when Path draws non-filled graphics - swift

In SwiftUI, when I use Path to draw a non-filled graphic, for example, draw a hollow rectangle, as follows:
code show as below:
Path {
$0.addRect(CGRect(x: 100, y: 100, width: 200, height: 200))
}.stroke(Color.red,lineWidth: 10).onHover { isHover in
print(isHover)
}
when I set "onHover", when the mouse moves to the graph, the "onHover" method does not make a callback. Is there a good way to monitor the hover state of Path

Related

Working with PDFKit: How to make page breaks?

Looking for some direction
I'm working with PDFKit. Everything is going fine but having trouble finding the methods (documentation / WWDC / elsewhere ) on how to stop text from drawing at a certain y position and start the next page. Any saved references or a snippet of code would be a great help.
I dont know, wether this is the best way to implement your use case, but it worked for me.
When adding a new line into the PDF_Context, I recalculate a variable the keeps tracking of the current content height of my PDF_Page. When it exceeds a certain value, I create a NEW page, set the content height to zero and go on filling, ...
And you might wanna find some good answers, practices HERE -> RayWenderlich.
// my initial value
private var myCurrentPageContentHeight: CGFloat = 20
// in your PDF fill procedures add something like
myCurrentPageContentHeight += 40
// I also have a struct the encapsulates
// PageSize with padding, ...
enum PDF_PageSize {
case din_A4_Portrait
case din_A4_Landscape
// -------------------------------
// getPDF_TotalRect
// -------------------------------
func getPDF_TotalRect() -> CGRect {
switch self {
case .din_A4_Portrait : return CGRect(x: 0, y: 0, width: 595, height: 842)
case .din_A4_Landscape : return CGRect(x: 0, y: 0, width: 842, height: 595)
}
}
// ....
}

What is the correct way to parent ImageBundles in the Bevy game engine so the child image doesn't alter the size of the parent image?

When I try to parent two ImageBundles together I don't get the expected result. The child image causes the parent image to resize to the size of the child image. I am trying to place the button image on top of the background image, but the following code places the button image on the background image and then scales the background image to the size of the button image.
If I comment out the push_children line of code then both images are displayed at the correct size.
let ent1 = commands.spawn_bundle(ImageBundle {
style: Style {
align_self: AlignSelf::Center,
..Default::default()
},
material: materials.add(
asset_server.load("Background.png").into()),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..Default::default()
}).id();
let ent2 = commands.spawn_bundle(ImageBundle {
style: Style {
align_self: AlignSelf::Center,
..Default::default()
},
material: materials.add(
asset_server.load("button.png").into()),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..Default::default()
}).id();
commands.entity(ent1).push_children(&[ent2]);

Tween transition in Kinetic js

I've been using the old 'transitionTo()' in my program but since Kineticjs is using Tween, i am a bit lost.
I've tried a simple shape transition using Tween and i've got some issues:
If you drag the shape to another point before doing anything, then click on the button for the transition, the shape comes back to the original hard coded coordinates and then does the transition.
I want the shape to start the transition where it has been dropped.
2.The 1st time it will do the transition, but afterwards it won't take the whole duration. It will just shift to the end point of the transition, like mentioned here.
Some codes:
var rect = new Kinetic.Rect({
x: 100,
y: 100,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
draggable: true
});
layer.add(rect);
stage.add(layer);
var tween = new Kinetic.Tween({
node: rect,
x: 200,
y: 200,
rotation: 0,
duration:5
});
jsFiddle provided above.
Any help will be appreciated; thanx :)
This is what I would propose to solve your problems :
var stage = new Kinetic.Stage({
container: 'container',
width: 700,
height: 300
});
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
x: 100,
y: 100,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
draggable: true
});
layer.add(rect);
stage.add(layer);
document.getElementById('run').addEventListener('click', function() {
var tween = new Kinetic.Tween({
node: rect,
x: 200,
y: 200,
rotation: 0,
duration:5
});
tween.play();
}, false);
Just instantiate the Tween transition at the moment, you want to use it. Otherwise, the transition will start with the position at the moment you instantiated it.
Here is the fork of your fiddle with my proposal : http://jsfiddle.net/kMvzy/

gamequery collision detection doesnt react

i created 2 sprite objects and want to check if they collide, but it doesnt seem to work.
My code:
creation of the sprites:**
.addGroup("flying", {width: 366, height: 254})
.addSprite("flyinganimation",{animation: flight,
posx: 0, posy: 0, width: 366, height: 254})
.addGroup("obstacles", {width: 169, height: 67})
.addSprite("obstaclenames", {animation: obstacleimage,
width: 169,height: 67,
posx: 300,
posy: 400})
looped code in the callback function:**
var collision = $("#flying,.group").collision("#obstacles,.group");
if (collision > 0)
{
document.write ("collision");
}
I see two potential problems here:
1) collision() returns a jQuery object so you will need to do a .size() in order to retrieve the number of collisions
2) you should apply collision() to only one object.
To sum up your first line should look like this:
var collision = $("#flying").collision("#obstacles,.group").size();

Raphael-GWT: fill image of a shape (Rect) appears offset. How to resolve this?

I'm wondering about the behavior of {Shape}.attr("fill","url({image.path})").
when applying a fill image to a shape:
public class AppMapCanvas extends Raphael {
public AppMapCanvas(int width, int height) {
super(width, height);
this.hCenter = width / 2;
this.vCenter = height / 2;
...
Rect rect = this.new Rect(hCenter, vCenter, 144, 40, 4);
rect.attr("fill", "url('../images/app-module-1-bg.png')"); // <--
...
}
}
The background image seem to teal accross the canvas behind the shape, thus gets weird positioning (an illustration snapshot is enclosed - i marked the original image borders in red).
This seem to resolve itself in the presence of an animation along a path (a mere path.M(0,0) is sufficiant).
How can i position the fill-image properly in the first place?
The proper way to do this from what I can understand would be to use an SVG pattern declaration to specify the portion and position of the image you would want to use. Then you would use that pattern to fill the rectangle element. Unfortunately, the Raphael javascript library doesn't have support for patterns... so there's no direct way to use an image to fill a rectangle.