Skip to content

Commit

Permalink
Merge pull request #1373 from ichan-mb/feat_dragdrop
Browse files Browse the repository at this point in the history
Draggable Enhancement
  • Loading branch information
mortend authored Sep 14, 2020
2 parents 8e107fa + 9d3196b commit 0ea7401
Show file tree
Hide file tree
Showing 5 changed files with 813 additions and 48 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Unreleased

### Fuse.physics
- Refactor `Draggable` using IGesture System.
- Introduce `Translation` property to `Draggable` to track translation position when user drag a visual with `Dragabble` behavior attached
- Introduce two new Triggers:
- `DragStarted` Pulse when dragging activity has been started
- `DragEnded` Pulse when dragging activity has been ended
- Drag and Drop API. Experimental support for drag and drop between visual element. Introduce sets of Triggers:
- `WhileDraggingOver` Activated when Visual that contain `Draggable` behavior and `WhileDraggingOver` trigger is overlaped / intersected with the `Target` Visual property that is defined in `WhileDraggingOver`
- `WhileDroppingBy` Activated when Visual that contain `WhileDroppingBy` trigger being overlaped / intersected by `Source` Draggable Visual
- `Dropped` Pulse when Draggable Visual is being dropped to the target visual and vice versa.

### Fuse.Controls.Primitives
- `TextControl` accessibility feature. Introduce `MinFontScale` and `MaxFontScale` Property to control the minimum or maximum text scaling behavior when the text/font size configuration setting on the phone has changed. Now default Fuse will honor the phone's text/font size configuration setting and will change all of the texts or labels in the Fuse App to match the setting. If you don't want the behavior you can pass a compiler flag:`IGNORE_FONT_SCALING` when building the app i.e: `uno build ios -DIGNORE_FONT_SCALING`

Expand Down
1 change: 1 addition & 0 deletions Source/Fuse.Elements/Fuse.Elements.unoproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"Fuse.iOS",
"Fuse.iOS.Bindings",
"Fuse.Controls.Video",
"Fuse.Physics",
],
"Packages": [
"Uno.Graphics.Utils",
Expand Down
85 changes: 76 additions & 9 deletions Source/Fuse.Physics/Body.uno
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Uno;
using Uno.Collections;
using Uno.UX;
using Fuse.Elements;

namespace Fuse.Physics
{
internal class Body
internal class Body: IPropertyListener
{
static readonly PropertyHandle _frictionHandle = Properties.CreateHandle();

Expand All @@ -25,30 +26,71 @@ namespace Fuse.Physics
get { return GetFriction(Visual); }
set { SetFriction(Visual, value); }
}

internal readonly World World;
internal readonly Visual Visual;

internal int PinCount;

readonly Translation _translation;
readonly Draggable _draggable;

internal float3 _deltaFromCenter = float3(0);
internal ITransformOrigin _prevTransform;

public void SetPointerPosition (float3 worldPos) {
_deltaFromCenter = float3(0);
_deltaFromCenter = worldPos - CenterPosition;

Element ele = Visual as Element;

if (ele != null) {
var localPos = float3(ele.ActualSize / 2, 0) + _deltaFromCenter;

_prevTransform = ele.TransformOrigin;
ele.ExplicitTransformOrigin = new Size2(
Size.Percent(localPos.X * 100 / Visual.LocalBounds.Maximum.X),
Size.Percent(localPos.Y * 100 / Visual.LocalBounds.Maximum.Y),
);
}
}

public void ReleasePointer() {
_deltaFromCenter = float3(0);
Element ele = Visual as Element;

if (ele != null) {
ele.TransformOrigin = _prevTransform;
}
}

internal float3 CenterPosition
{
get { return Vector.Transform(Visual.LocalBounds.Center, Visual.WorldTransform).XYZ; }
get
{
return Vector.Transform(Visual.LocalBounds.Center + _deltaFromCenter, Visual.WorldTransform).XYZ;
}
}

internal Body(World world, Visual node)
internal Body(World world, Visual node)
{
Visual = node;

_translation = new Translation();
_draggable = Visual.FirstChild<Draggable>();
_position = float3(_draggable.Translation.X, _draggable.Translation.Y, 0);
_translation.Vector = _position;

Visual.Children.Add(_translation);

World = world;

_draggable.AddPropertyListener(this);
}

internal void Dispose()
{
_draggable.RemovePropertyListener(this);
Visual.Children.Remove(_translation);
}

Expand All @@ -69,12 +111,28 @@ namespace Fuse.Physics
if (_motionOwner != null) return false;

_motionOwner = owner;

for (var fft = Visual.FirstChild<DragStarted>(); fft != null; fft = fft.NextSibling<DragStarted>())
{
fft.OnTriggered(this, _position);
}

return true;
}

internal void UnlockMotion()
{
_motionOwner = null;

for (var fft = Visual.FirstChild<DragEnded>(); fft != null; fft = fft.NextSibling<DragEnded>())
{
fft.OnTriggered(this, _position);
}

for (var dropped = Visual.FirstChild<Dropped>(); dropped != null; dropped = dropped.NextSibling<Dropped>())
{
dropped.OnTriggered(this, _position);
}
}

internal void Move(float3 delta)
Expand All @@ -87,7 +145,7 @@ namespace Fuse.Physics
internal void ConstrainToBounds(Element elm)
{
_constraint = elm;

}

internal void ApplyForce(float3 force)
Expand All @@ -97,14 +155,14 @@ namespace Fuse.Physics

internal float3 Position { get { return _position; } }

internal float3 WorldPosition
internal float3 WorldPosition
{
get
get
{
return Visual.WorldPosition;
}
}

float3 _velocity;
float3 _position;

Expand Down Expand Up @@ -144,10 +202,12 @@ namespace Fuse.Physics
_velocity = float3(0);
}
}

_draggable.Translation = float2(_position.X, _position.Y);
}

void ApplyFriction(double deltaTime)
{
{
var friction = Friction;

for (double t = 0; t < deltaTime; t += 0.001)
Expand All @@ -161,6 +221,13 @@ namespace Fuse.Physics
if (_motionOwner != null) return;
_position += _velocity * (float)deltaTime * 5;
}

void IPropertyListener.OnPropertyChanged(PropertyObject obj, Selector prop)
{
if (obj == _draggable && prop.Equals("Translation")) {
_position = float3(_draggable.Translation.X, _draggable.Translation.Y, 0);
}
}
}

}
Loading

0 comments on commit 0ea7401

Please sign in to comment.