feat: allow to resize on any edge of the window
All checks were successful
gitea-sync/antos-frontend/pipeline/head This commit looks good

This commit is contained in:
DL 2024-06-25 16:27:10 +02:00
parent 147353327b
commit 73f925ac8c
2 changed files with 146 additions and 39 deletions

View File

@ -241,14 +241,26 @@ namespace OS {
this.attsw(v, "resizable"); this.attsw(v, "resizable");
if (v) { if (v) {
$(this.refs["maxbt"]).show(); $(this.refs["maxbt"]).show();
$(this.refs["grip"]).show(); $(this.refs["grip_br"]).show();
$(this.refs["grip_tl"]).show();
$(this.refs["grip_tr"]).show();
$(this.refs["grip_bl"]).show();
$(this.refs["grip_bottom"]).show(); $(this.refs["grip_bottom"]).show();
$(this.refs["grip_right"]).show(); $(this.refs["grip_right"]).show();
$(this.refs["grip_top"]).show();
$(this.refs["grip_left"]).show();
} else { } else {
$(this.refs["maxbt"]).hide(); $(this.refs["maxbt"]).hide();
$(this.refs["grip"]).hide(); $(this.refs["grip_br"]).hide();
$(this.refs["grip_tl"]).hide();
$(this.refs["grip_tr"]).hide();
$(this.refs["grip_bl"]).hide();
$(this.refs["grip_bottom"]).hide(); $(this.refs["grip_bottom"]).hide();
$(this.refs["grip_right"]).hide(); $(this.refs["grip_right"]).hide();
$(this.refs["grip_top"]).hide();
$(this.refs["grip_left"]).hide();
} }
} }
get resizable(): boolean { get resizable(): boolean {
@ -534,18 +546,37 @@ namespace OS {
const mouse_move_hdl = (e) => { const mouse_move_hdl = (e) => {
let w = $(this).width(); let w = $(this).width();
let h = $(this).height(); let h = $(this).height();
let coord = $(this).offset();
$(this.refs.win_overlay).show(); $(this.refs.win_overlay).show();
if (target != this.refs.grip_bottom) { if ((target == this.refs.grip_bottom) || (target == this.refs.grip_bl) || (target == this.refs.grip_br)) {
w += e.clientX - offset.left;
}
if (target != this.refs.grip_right) {
h += e.clientY - offset.top; h += e.clientY - offset.top;
} }
if ((target == this.refs.grip_right) || (target == this.refs.grip_br) || (target == this.refs.grip_tr)) {
w += e.clientX - offset.left;
}
if ((target == this.refs.grip_left) || (target == this.refs.grip_bl) || (target == this.refs.grip_tl)) {
w -= e.clientX - offset.left;
coord.left += e.clientX - offset.left;
}
if ((target == this.refs.grip_top) || (target == this.refs.grip_tr) || (target == this.refs.grip_tl)) {
h -= e.clientY - offset.top;
coord.top += e.clientY - offset.top;
}
w = w < 100 ? 100 : w; w = w < 100 ? 100 : w;
h = h < 100 ? 100 : h; h = h < 100 ? 100 : h;
coord.top = coord.top < 0 ? 0: coord.top;
coord.left = coord.left < 0 ? 0: coord.left;
offset.top = e.clientY; offset.top = e.clientY;
offset.left = e.clientX; offset.left = e.clientX;
this._isMaxi = false; this._isMaxi = false;
$(this)
.css("top", `${coord.top}px`)
.css("left", `${coord.left}px`);
this.setsize({ w, h }); this.setsize({ w, h });
} }
const mouse_up_hdl = (e) => { const mouse_up_hdl = (e) => {
@ -553,29 +584,25 @@ namespace OS {
$(window).off("pointermove", mouse_move_hdl); $(window).off("pointermove", mouse_move_hdl);
return $(window).off("pointerup", mouse_up_hdl); return $(window).off("pointerup", mouse_up_hdl);
} }
$(this.refs["grip"]).on("pointerdown", (e) => { $.each(
[
this.refs.grip_bl,
this.refs.grip_br,
this.refs.grip_tl,
this.refs.grip_tr,
this.refs.grip_left,
this.refs.grip_bottom,
this.refs.grip_right,
this.refs.grip_top
], function(){
$(this).on("pointerdown", (e) => {
e.preventDefault(); e.preventDefault();
offset.top = e.clientY; offset.top = e.clientY;
offset.left = e.clientX; offset.left = e.clientX;
target = this.refs.grip; target = this;
$(window).on("pointermove", mouse_move_hdl); $(window).on("pointermove", mouse_move_hdl);
$(window).on("pointerup", mouse_up_hdl); $(window).on("pointerup", mouse_up_hdl);
}); });
$(this.refs.grip_bottom).on("pointerdown", (e) => {
e.preventDefault();
offset.top = e.clientY;
offset.left = e.clientX;
target = this.refs.grip_bottom;
$(window).on("pointermove", mouse_move_hdl);
$(window).on("pointerup", mouse_up_hdl);
});
$(this.refs.grip_right).on("pointerdown", (e) => {
e.preventDefault();
offset.top = e.clientY;
offset.left = e.clientX;
target = this.refs.grip_right;
$(window).on("pointermove", mouse_move_hdl);
$(window).on("pointerup", mouse_up_hdl);
}); });
} }
/** /**
@ -693,8 +720,23 @@ namespace OS {
}, },
{ {
el: "div", el: "div",
ref: "grip", ref: "grip_br",
class: "afx-window-grip", class: "afx-window-grip-bottom-right",
},
{
el: "div",
ref: "grip_tl",
class: "afx-window-grip-top-left",
},
{
el: "div",
ref: "grip_bl",
class: "afx-window-grip-bottom-left",
},
{
el: "div",
ref: "grip_tr",
class: "afx-window-grip-top-right",
}, },
{ {
el: "div", el: "div",
@ -706,6 +748,16 @@ namespace OS {
ref: "grip_right", ref: "grip_right",
class: "afx-window-grip-right", class: "afx-window-grip-right",
}, },
{
el: "div",
ref: "grip_top",
class: "afx-window-grip-top",
},
{
el: "div",
ref: "grip_left",
class: "afx-window-grip-left",
},
{ {
el: "div", el: "div",
ref: "win_overlay", ref: "win_overlay",

View File

@ -60,7 +60,40 @@ afx-app-window div.afx-window-content
width: 100%; width: 100%;
flex-grow: 1; flex-grow: 1;
} }
afx-app-window div.afx-window-grip{
afx-app-window div.afx-window-grip-top-left{
height: 10px;
width: 10px;
user-select:none;
position: absolute;
top: 0;
left: 0;
cursor: nwse-resize;
background-color: transparent;
}
afx-app-window div.afx-window-grip-bottom-left{
height: 10px;
width: 10px;
user-select:none;
position: absolute;
left: 0;
bottom: 0;
cursor: nesw-resize;
background-color: transparent;
}
afx-app-window div.afx-window-grip-top-right{
height: 10px;
width: 10px;
user-select:none;
position: absolute;
top: 0;
right: 0;
cursor: nesw-resize;
background-color: transparent;
}
afx-app-window div.afx-window-grip-bottom-right{
height: 10px; height: 10px;
width: 10px; width: 10px;
user-select:none; user-select:none;
@ -71,24 +104,46 @@ afx-app-window div.afx-window-grip{
background-color: transparent; background-color: transparent;
} }
afx-app-window div.afx-window-grip-bottom{ afx-app-window div.afx-window-grip-top{
height: 3px; height: 5px;
user-select:none; user-select:none;
position: absolute; position: absolute;
bottom: -1px; top: -2px;
left: 0; left: 10px;
right: 10px;
cursor: ns-resize;
background-color: transparent;
}
afx-app-window div.afx-window-grip-left{
width: 5px;
user-select:none;
position: absolute;
top: 10px;
left: -2px;
bottom: 10px;
cursor: ew-resize;
background-color: transparent;
}
afx-app-window div.afx-window-grip-bottom{
height: 5px;
user-select:none;
position: absolute;
bottom: -2px;
left: 10px;
right: 10px; right: 10px;
cursor: ns-resize; cursor: ns-resize;
background-color: transparent; background-color: transparent;
} }
afx-app-window div.afx-window-grip-right{ afx-app-window div.afx-window-grip-right{
width: 3px; width: 5px;
user-select:none; user-select:none;
position: absolute; position: absolute;
bottom: 10px; bottom: 10px;
right: -1px; right: -2px;
top: 0; top: 10px;
cursor: ew-resize; cursor: ew-resize;
background-color: transparent; background-color: transparent;
} }