Skip to content

Commit

Permalink
DragWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Dec 15, 2024
1 parent 60037a2 commit 1f8f1b9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2024 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

qx.Class.define("osparc.dashboard.DragWidget", {
extend: qx.ui.basic.Atom,

construct: function() {
this.base(arguments);

this.set({
opacity: 0.9,
padding: 10,
zIndex: 1000,
font: "text-14",
backgroundColor: "strong-main",
decorator: "rounded",
visibility: "excluded",
});

const root = qx.core.Init.getApplication().getRoot();
root.add(this);
},

members: {
__onMouseMoveDragging: function(e) {
const domEl = this.getContentElement().getDomElement();
domEl.style.left = `${e.pageX + 15}px`; // Offset for better visibility
domEl.style.top = `${e.pageY + 15}px`;
},

start: function() {
this.show();
document.addEventListener("mousemove", this.__onMouseMoveDragging.bind(this), false);
},

end: function() {
this.exclude();
document.removeEventListener("mousemove", this.__onMouseMoveDragging.bind(this), false);
},
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {

__configureStudyCards: function(cards) {
// Create drag indicator
this.__dragIndicator = new qx.ui.basic.Atom().set({
opacity: 0.9,
padding: 10,
zIndex: 1000,
font: "text-14",
backgroundColor: "strong-main",
decorator: "rounded",
visibility: "excluded",
});
const root = qx.core.Init.getApplication().getRoot();
root.add(this.__dragIndicator);
this.__dragIndicator = new osparc.dashboard.DragWidget();

cards.forEach(card => {
card.setMultiSelectionMode(this.getMultiSelection());
Expand All @@ -670,12 +660,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
},

__attachDragHandlers: function(card) {
const onMouseMoveDragging = e => {
const dragWidget = this.__dragIndicator.getContentElement().getDomElement();
dragWidget.style.left = `${e.pageX + 10}px`; // Offset for better visibility
dragWidget.style.top = `${e.pageY + 10}px`;
};

card.setDraggable(true);

card.addListener("dragstart", e => {
Expand All @@ -690,21 +674,15 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
// init drag indicator
this.__dragIndicator.set({
label: card.getTitle(),
visibility: "visible",
});
// listen to mousemove while dragging
document.addEventListener("mousemove", onMouseMoveDragging, false);
this.__dragIndicator.start();
});

card.addListener("dragend", () => {
// bring back opacity after drag
card.setOpacity(1);
// hide drag indicator
this.__dragIndicator.set({
visibility: "excluded",
});
// remove listener
document.removeEventListener("mousemove", onMouseMoveDragging, false);
this.__dragIndicator.end();
});
},

Expand Down

0 comments on commit 1f8f1b9

Please sign in to comment.