Skip to content

Commit a9c316a

Browse files
committed
Implement dragging of modal dialog in menu
On small canvas dialog can tag significant place
1 parent 678e282 commit a9c316a

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

modules/gui/menu.mjs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { settings, internals, browser, gStyle, isObject, isFunc, isStr, clTGaxis, nsSVG, kInspect, getDocument } from '../core.mjs';
2-
import { rgb as d3_rgb, select as d3_select } from '../d3.mjs';
2+
import { rgb as d3_rgb, select as d3_select, drag as d3_drag, pointer as d3_pointer } from '../d3.mjs';
33
import { selectgStyle, saveSettings, readSettings, saveStyle, getColorExec, changeObjectMember } from './utils.mjs';
44
import { getColor } from '../base/colors.mjs';
55
import { TAttMarkerHandler } from '../base/TAttMarkerHandler.mjs';
@@ -1576,32 +1576,42 @@ class StandaloneMenu extends JSRootMenu {
15761576
d3_select(`#${dlg_id}`).remove();
15771577
d3_select(`#${dlg_id}_block`).remove();
15781578

1579-
const w = Math.min(args.width || 450, Math.round(0.9 * browser.screenWidth));
1580-
modal.block = d3_select('body').append('div')
1581-
.attr('id', `${dlg_id}_block`)
1582-
.attr('class', 'jsroot_dialog_block')
1583-
.attr('style', 'z-index: 100000; position: absolute; left: 0px; top: 0px; bottom: 0px; right: 0px; opacity: 0.2; background-color: white');
1584-
modal.element = d3_select('body')
1585-
.append('div')
1586-
.attr('id', dlg_id)
1587-
.attr('class', 'jsroot_dialog')
1588-
.style('position', 'absolute')
1589-
.style('width', `${w}px`)
1590-
.style('left', '50%')
1591-
.style('top', '50%')
1592-
.style('z-index', 100001)
1593-
.attr('tabindex', '0');
1579+
const w = Math.min(args.width || 450, Math.round(0.9 * browser.screenWidth)),
1580+
b = d3_select('body');
1581+
modal.block = b.append('div')
1582+
.attr('id', `${dlg_id}_block`)
1583+
.attr('class', 'jsroot_dialog_block')
1584+
.attr('style', 'z-index: 100000; position: absolute; left: 0px; top: 0px; bottom: 0px; right: 0px; opacity: 0.2; background-color: white');
1585+
modal.element = b.append('div')
1586+
.attr('id', dlg_id)
1587+
.attr('class', 'jsroot_dialog')
1588+
.style('position', 'absolute')
1589+
.style('width', `${w}px`)
1590+
.style('left', '50%')
1591+
.style('top', '50%')
1592+
.style('z-index', 100001)
1593+
.attr('tabindex', '0');
15941594

15951595
modal.element.html(
15961596
'<div style=\'position: relative; left: -50%; top: -50%; border: solid green 3px; padding: 5px; display: flex; flex-flow: column; background-color: white\'>' +
1597-
`<div style='flex: 0 1 auto; padding: 5px'>${title}</div>` +
1597+
`<div style='flex: 0 1 auto; padding: 5px; cursor: pointer;' class='jsroot_dialog_title'>${title}</div>` +
15981598
`<div class='jsroot_dialog_content' style='flex: 1 1 auto; padding: 5px'>${main_content}</div>` +
15991599
'<div class=\'jsroot_dialog_footer\' style=\'flex: 0 1 auto; padding: 5px\'>' +
16001600
`<button class='jsroot_dialog_button' style='float: right; width: fit-content; margin-right: 1em'>${args.Ok}</button>` +
16011601
(args.btns ? '<button class=\'jsroot_dialog_button\' style=\'float: right; width: fit-content; margin-right: 1em\'>Cancel</button>' : '') +
16021602
'</div></div>'
16031603
);
16041604

1605+
const drag_move = d3_drag().on('start', () => { modal.y0 = 0; }).on('drag', evnt => {
1606+
if (!modal.y0)
1607+
modal.y0 = d3_pointer(evnt, modal.element.node())[1];
1608+
let p0 = Math.max(0, d3_pointer(evnt, b.node())[1] - modal.y0);
1609+
if (b.node().clientHeight)
1610+
p0 = Math.min(p0, 0.8 * b.node().clientHeight);
1611+
modal.element.style('top', `${p0}px`);
1612+
});
1613+
modal.element.select('.jsroot_dialog_title').call(drag_move);
1614+
16051615
modal.done = function(res) {
16061616
if (this._done)
16071617
return;

0 commit comments

Comments
 (0)