Static windows used to make me sad: they looked like stickers stuck to the screen. Today I implemented the resizing system!
For the user, it’s the most trivial thing in the world: you see a handle in the corner, drag it, and the window expands. Easy, right? NO. Anyone who’s ever tried to program an interface knows that behind that simple gesture is a bloodbath of math. 🩸
I had to orchestrate a dance between mouse events:
mousedown: Got it. (activate the isResizing flag)
mousemove: Real-time X and Y coordinate calculations.
mouseup: Hold still! (save the new size)
At first, it was tragic. If I dragged the mouse too quickly to the left, the window width would go negative (width < -50px). Result? The DIV would “flip” and disappear into nothingness. I spent 20 minutes searching for ghost windows in the DOM.
Luckily, I had a lightbulb moment 💡 (I remembered an old project where I solved something similar). I added a “safety block” both in the CSS and JS:
if (newWidth > 50) { element.style.width = newWidth + ‘px’ }
Basically, I’m telling the code, “Hey, if it gets smaller than a stamp, stop!” I also had to wrestle with getBoundingClientRect() to calculate the absolute position relative to the parent, but in the end, after several attempts, I did it!
Now it’s super smooth. I can create a setup with giant cinema windows or tiny sticky notes. Shard is slowly taking shape and is starting to look like a real OS! 🚀
P.S. This is already the second Dev Log I’ve ended with the spaceship emoji, I think NASA might actually hire me 🙃