Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First snapping implementation #507

Merged
merged 8 commits into from
Mar 7, 2021

Conversation

mbfraga
Copy link
Collaborator

@mbfraga mbfraga commented Mar 5, 2021

Implements snapping between objects. Lays the groundwork for a future, more complete implementation.

Notable features:

  • Stateless implementation for snapping.
  • Snapping on object move
  • First pass cosmetic implementation for guide lines and snap points (probably needs some reworking)

Notable missing features are:

  • Adding the snapping functionality to other transformations (resize). It should mostly require some hooking up of existing code
  • Smarter generation of candidates, possibly only snapping to artboard items if the item is within an artboard. The code for this is mostly there, we mainly need a method to generate the list of items from an artboard.

Copy link
Member

@Alecaddd Alecaddd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this amazing submission.
Pretty much every comment I left is purely from a code formatting point of view. Let me know if you don't want to take care of this I can do that for you :D

Comment on lines +344 to +346
// This is a temporary approach to end operations. In the future we may want to have more specific
// methods.
selected_bound_manager.alert_held_button_release ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this method could be called on_butten_release ()

Comment on lines 340 to 343
Lib.Items.CanvasItem item,
double event_x,
double event_y
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can inline this with private void move_from_event (Items.CanvasItem item, double event_x, double event_y) {

double event_x,
double event_y
) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the empty line.

Comment on lines 374 to 375
// Make adjustment basted on snaps
// Double the sensitivity to allow for reuse of grid after snap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually try to end all the inline comments with a period.

// then be translated again.
// Make adjustment basted on snaps
// Double the sensitivity to allow for reuse of grid after snap
var sensitivity = (int) Utils.Snapping.adjusted_sensitivity (canvas.current_scale);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we always need an INTEGER from this method, we should return directly an integer from the method instead of type casting it every time we use it.

Comment on lines 199 to 201
List<weak Goo.CanvasItem> v_candidates,
List<weak Goo.CanvasItem> h_candidates,
List<Lib.Items.CanvasItem> selection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent these attributes.

Comment on lines 208 to 211
var candidate_item = cand as Lib.Items.CanvasItem;
if (candidate_item != null && selection.find (candidate_item) == null) {
populate_vertical_snaps (candidate_item, ref grid.v_snaps);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here is a bit wrong, as well as in the next foreach loop.

return grid;
}

/// Populates the horizontal snaps of an item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment block for methods, please :D


/// Populates the horizontal snaps of an item
private static void populate_horizontal_snaps (Lib.Items.CanvasItem item, ref Gee.HashMap<int, SnapMeta> map) {
int x_1 = (int)item.bounds.x1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after (int)

Comment on lines 261 to 276
if (map.has_key (pos)) {
SnapMeta k = map.get (pos);
k.normals.add (n1);
k.normals.add (n2);
k.normals.add (n3);
k.polarity += polarity;
}
else {
var v = new SnapMeta ();
v.normals = new Gee.HashSet<int> ();
v.normals.add (n1);
v.normals.add (n2);
v.normals.add (n3);
v.polarity = polarity;
map.set (pos, v);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since nothing happens after the callback condition, we can do an early return; in the first condition, and avoid the else.

@Alecaddd Alecaddd mentioned this pull request Mar 6, 2021
46 tasks
@mbfraga mbfraga requested a review from Alecaddd March 6, 2021 16:55
@Alecaddd Alecaddd mentioned this pull request Mar 6, 2021
3 tasks
@Alecaddd Alecaddd merged commit 3dff25e into akiraux:master Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants