Skip to content

Commit

Permalink
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core
Browse files Browse the repository at this point in the history
… into gh-pages
  • Loading branch information
JensLincke committed Oct 10, 2023
2 parents 1a0a85f + 1b2a884 commit 7df1c69
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/client/lively.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,21 +723,18 @@ export default class Lively {
}

static setExtent(node, extent) {
// node.style.width = '' + extent.x + 'px';
// node.style.height = '' + extent.y + 'px';
// node.dispatchEvent(new CustomEvent("extent-changed"))
this.setWidth(node, extent.x, true);
this.setHeight(node, extent.y);
}

static setWidth(node, x, noevent) {
node.style.width = '' + x + 'px';
if (!noevent) node.dispatchEvent(new CustomEvent("extent-changed"));
if (!noevent) node.dispatchEvent(new CustomEvent("extent-changed", {detail: {extent: this.getExtent(node)}}));
}

static setHeight(node, y, noevent) {
node.style.height = '' + y + 'px';
if (!noevent) node.dispatchEvent(new CustomEvent("extent-changed"));
if (!noevent) node.dispatchEvent(new CustomEvent("extent-changed", {detail: {extent: this.getExtent(node)}}));
}

// #important
Expand Down
2 changes: 1 addition & 1 deletion src/components/tools/lively-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class Container extends Morph {

this.addEventListener("extent-changed", function(evt) {
if (this.target) {
this.target.dispatchEvent(new CustomEvent("extent-changed"));
this.target.dispatchEvent(new CustomEvent("extent-changed", evt));
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/lively-resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class Resizer extends Morph {
lively.setPosition(element, newPosition)
lively.setExtent(element, newExtent)

element.dispatchEvent(new CustomEvent("extent-changed"))
element.dispatchEvent(new CustomEvent("extent-changed", {detail:{extent:lively.getExtent(element)}}))

evt.stopPropagation();
evt.preventDefault();
Expand Down
12 changes: 8 additions & 4 deletions src/components/widgets/lively-window-docking.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class LivelyWindowDocking extends Morph {
// because the window can be resized, the screen is seen from 0,0 to 1,1
if (!this.availableDockingAreas) {
if (this.getAttribute("availableDockingAreas")) {
console.log("Parsing docking areas from store");
var store = JSON.parse(this.getAttribute("availableDockingAreas"));
this.availableDockingAreas = store.map(ea => {
var win = null;
Expand All @@ -25,6 +26,7 @@ export default class LivelyWindowDocking extends Morph {
return {"bounds": Rectangle.fromLiteral(ea.bounds), "window": win};
})
} else {
console.log("Restoring default docking areas");
this.availableDockingAreas = [{"bounds": rect(0,0,1,1), "window": null}];
}
}
Expand Down Expand Up @@ -278,15 +280,16 @@ export default class LivelyWindowDocking extends Morph {
}

resizeMySlot(win, newSize) {
newSize = this.clientCoordsToDockingCoords(newSize);
if (!newSize) throw new Error("newSize is missing")

var slot = this.availableDockingAreas.find((area) => (area.window == win)); // recheck diff between var and let
lively.notify("Resize slot called");
debugger;
if (slot && slot.bounds) {

if (slot && slot.bounds) {
this.availableDockingAreas.forEach(ea => {
// @TODO make sure slot !== ea
var newBounds = null;
debugger;
lively.notify("huh");
if (ea.bounds.left() == slot.bounds.left() && ea.bounds.width == slot.bounds.width) { // vertical setup
lively.notify("shoiuld NOT");
Expand All @@ -313,6 +316,7 @@ export default class LivelyWindowDocking extends Morph {
}
if (newBounds) {
ea.bounds = newBounds;
lively.notify("NEW ADJACENT");
if (ea.window) {
// resize window in other slot
lively.setPosition(ea.window, pt(newBounds.left(), newBounds.top()));
Expand All @@ -321,7 +325,7 @@ export default class LivelyWindowDocking extends Morph {
}
});
// only finally resize it's own slot after each neighboring slot has been accounted for. expect newSize to be compatible with bounds?
slot.bounds = newSize;
slot.bounds = rect(slot.bounds.x, slot.bounds.y, newSize.x, newSize.y);
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/components/widgets/lively-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export default class Window extends Morph {
}

setExtent(extent) {
lively.setExtent(this, extent)
console.log(extent);
lively.setExtent(this, extent);
if (this.target)
this.target.dispatchEvent(new CustomEvent("extent-changed"))
this.target.dispatchEvent(new CustomEvent("extent-changed", {detail: {extent: lively.getExtent(this.target)}}))
}
/*MD ## Setup MD*/

Expand Down Expand Up @@ -140,7 +141,7 @@ export default class Window extends Morph {

bindEvents() {
try {
this.addEventListener('extent-changed', evt => { this.onExtentChanged(); });
this.addEventListener('extent-changed', evt => { this.onExtentChanged(evt); });
this.windowTitle.addEventListener('pointerdown', evt => { this.onTitleMouseDown(evt) });
this.windowTitle.addEventListener('dblclick', evt => { this.onTitleDoubleClick(evt) });
this.addEventListener('mousedown', evt => lively.focusWithoutScroll(this), true);
Expand Down Expand Up @@ -529,11 +530,13 @@ export default class Window extends Morph {
}

onExtentChanged(evt) {
console.log(evt);
debugger;
// console.log(evt); // evt has no content? => current bounds must already have been refreshed
if (this.target) {
this.target.dispatchEvent(new CustomEvent("extent-changed"));
this.target.dispatchEvent(new CustomEvent("extent-changed", evt));
if (this.isDocked()) {
lively.windowDocking.resizeMySlot(this, evt);
lively.windowDocking.resizeMySlot(this, evt.detail.extent);
}
}
}
Expand Down Expand Up @@ -605,8 +608,10 @@ export default class Window extends Morph {
this.style.height = targetArea.height + "px";
document.body.style.overflow = "hidden"
// @TODO I dont know why this is necessary yet
/*
if (this.target)
this.target.dispatchEvent(new CustomEvent("extent-changed"))
*/
this.classList.add("docked")

// DO display resize handles to change slot sizes. Could be made custom in the future to disallow out-of-bounds dragging
Expand Down

0 comments on commit 7df1c69

Please sign in to comment.