Skip to content

Commit

Permalink
Cleanup ctx menu positionner
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Nov 29, 2023
1 parent 3f3f674 commit d25a74a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/electron.renderer/ui/Modal.hx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Modal extends dn.Process {


function applyAnchor() {
anchorInvalidated = false;

var docHei = App.ME.jDoc.innerHeight();

switch anchor {
Expand Down Expand Up @@ -304,9 +306,7 @@ class Modal extends dn.Process {

override function postUpdate() {
super.postUpdate();
if( anchorInvalidated ) {
anchorInvalidated = false;
if( anchorInvalidated )
applyAnchor();
}
}
}
30 changes: 10 additions & 20 deletions src/electron.renderer/ui/modal/ContextMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ContextMenu extends ui.Modal {
ME.destroy();
ME = this;

setTransparentMask();
addClass("contextMenu");

if( openEvent!=null || jNear!=null ) {
var jEventTarget = jNear!=null ? jNear : new J(openEvent.target);
jAttachTarget = jEventTarget;
Expand All @@ -34,28 +37,21 @@ class ContextMenu extends ui.Modal {
jAttachTarget.addClass("contextMenuOpen");

if( jEventTarget.is("button") || jEventTarget.parent().is("button") || jNear!=null )
placer = ()->setAnchor( MA_JQuery(jEventTarget) );
setAnchor( MA_JQuery(jEventTarget) );
else if( openEvent!=null )
placer = ()->setAnchor( MA_Coords(new Coords(openEvent.pageX, openEvent.pageY)) );

setAnchor( MA_Coords(new Coords(openEvent.pageX, openEvent.pageY)) );
}
else {
jAttachTarget = new J("");
if( m!=null )
placer = ()->setAnchor( MA_Coords(m) );
setAnchor( MA_Coords(m) );
}

setTransparentMask();
addClass("contextMenu");
placer();
}

public function enableNoWrap() {
jContent.addClass("noWrap");
}

dynamic function placer() {}

public static inline function isOpen() return ME!=null && !ME.destroyed;

override function onDispose() {
Expand Down Expand Up @@ -104,14 +100,8 @@ class ContextMenu extends ui.Modal {
}


override function onResize() {
super.onResize();
checkPosition();
}


function checkPosition() {
placer();
override function applyAnchor() {
super.applyAnchor();

var pad = 16;
var docHei = App.ME.jDoc.innerHeight();
Expand All @@ -127,7 +117,7 @@ class ContextMenu extends ui.Modal {
public function addTitle(str:LocaleString) {
var jTitle = new J('<div class="title">$str</div>');
jTitle.appendTo(jContent);
checkPosition();
applyAnchor();
}

public function add(a:ContextAction) {
Expand Down Expand Up @@ -160,7 +150,7 @@ class ContextMenu extends ui.Modal {
if( a.separatorAfter )
jButton.addClass("separatorAfter");

checkPosition();
applyAnchor();
return jButton;
}
}

0 comments on commit d25a74a

Please sign in to comment.