Skip to content

Commit

Permalink
Improving DnD UX/UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
phase1geo committed Jan 14, 2025
1 parent 552781a commit 4904123
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/Brainstorm.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,25 @@ public class Brainstorm : Box {
});

_ideas = new ListBox() {
selection_mode = SelectionMode.NONE,
selection_mode = SelectionMode.SINGLE,
show_separators = true
};

var key = new EventControllerKey();

_ideas.add_controller( key );

key.key_pressed.connect((keyval, keycode, state) => {
var current = _ideas.get_selected_row();
if( current != null ) {
if( keyval == Gdk.Key.Delete ) {
_ideas.remove( current );
return( true );
}
}
return( false );
});

var sw = new ScrolledWindow() {
vscrollbar_policy = PolicyType.AUTOMATIC,
hscrollbar_policy = PolicyType.NEVER,
Expand Down Expand Up @@ -86,24 +101,34 @@ public class Brainstorm : Box {

_ideas.append( label );

var index = (label.get_parent() as ListBoxRow).get_index();

var drag = new DragSource() {
actions = DragAction.MOVE
};

drag.set_icon( create_icon( label, text ), 10, 10 );

label.add_controller( drag );

drag.set_icon( create_icon( label, text ), 10, 10 );

drag.prepare.connect((x, y) => {
var val = new Value( typeof(string) );
val.set_string( text );
var provider = new ContentProvider.for_value( val );
return( provider );
});

drag.drag_begin.connect((d) => {
_ideas.remove( label.get_parent() );
});

drag.drag_cancel.connect((d) => {
return( false );
});

drag.drag_end.connect((d, del) => {
if( del ) {
_ideas.remove( label.get_parent() );
if( _win.get_current_da().attach_node == null ) {
_ideas.insert( label, index );
}
});

Expand Down Expand Up @@ -151,7 +176,9 @@ public class Brainstorm : Box {
// Make sure that the entry field receives the focus if the box
// is given focus.
public override bool grab_focus() {

return( _entry.grab_focus() );

}

}
15 changes: 15 additions & 0 deletions src/DrawArea.vala
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public class DrawArea : Gtk.DrawingArea {
}
}
}
public Node? attach_node {
get {
return( _attach_node );
}
}

/* Allocate static parsers */
public MarkdownParser markdown_parser { get; private set; }
Expand Down Expand Up @@ -2282,6 +2287,16 @@ public class DrawArea : Gtk.DrawingArea {
sticker = _stickers.is_within( x, y );
}

//-------------------------------------------------------------
// Returns true if a node is droppable at the given coordinates
public bool text_droppable( double x, double y ) {
Node? node;
Connection? conn;
Sticker? sticker;
get_droppable( scale_value( x ), scale_value( y ), out node, out conn, out sticker );
return( node != null );
}

/* Returns the origin */
public void get_origin( out double x, out double y ) {
x = origin_x;
Expand Down

0 comments on commit 4904123

Please sign in to comment.