Skip to content

Commit 3e57b1b

Browse files
committed
Added resizable rectangle shape
1 parent 78fd39c commit 3e57b1b

3 files changed

Lines changed: 68 additions & 9 deletions

File tree

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ <h1>Telugu Text Wrapper Pro</h1>
5252
<button id="addToSquareBtn" class="add-shape-btn square-btn">
5353
➕ Square
5454
</button>
55+
<button id="addToRectBtn" class="add-shape-btn square-btn">
56+
➕ Rect
57+
</button>
5558
</div>
5659
</div>
5760

@@ -99,6 +102,10 @@ <h1>Telugu Text Wrapper Pro</h1>
99102
<label>Custom: <span id="sizeValue">150px</span></label>
100103
<input type="range" id="imageSize" min="100" max="400" value="150">
101104
</div>
105+
<div id="rectHeightControl" class="control-group" style="display: none;">
106+
<label>Rectangle Height: <span id="rectHeightValue">150px</span></label>
107+
<input type="range" id="rectHeight" min="50" max="400" value="150">
108+
</div>
102109
</div>
103110

104111
<div class="text-section">

script.js

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const addToCircleBtn = document.getElementById('addToCircleBtn');
99
const addToHexadecagonBtn = document.getElementById('addToHexadecagonBtn');
1010
const addToFlowerBtn = document.getElementById('addToFlowerBtn');
1111
const addToSquareBtn = document.getElementById('addToSquareBtn');
12+
const addToRectBtn = document.getElementById('addToRectBtn');
13+
const rectHeightControl = document.getElementById('rectHeightControl');
14+
const rectHeight = document.getElementById('rectHeight');
15+
const rectHeightValue = document.getElementById('rectHeightValue');
1216

1317
const teluguText = document.getElementById('teluguText');
1418
const imageSize = document.getElementById('imageSize');
@@ -106,19 +110,50 @@ addToCircleBtn.addEventListener('click', () => setShape('circle'));
106110
addToHexadecagonBtn.addEventListener('click', () => setShape('hexadecagon'));
107111
addToFlowerBtn.addEventListener('click', () => setShape('flower'));
108112
addToSquareBtn.addEventListener('click', () => setShape('square'));
113+
// Add Rectangle Handler
114+
addToRectBtn.addEventListener('click', () => setShape('rectangle'));
115+
116+
// Add Slider Handler
117+
rectHeight.addEventListener('input', (e) => {
118+
rectHeightValue.textContent = e.target.value + 'px';
119+
updatePreview();
120+
});
109121

110122
function setShape(shape) {
111-
if (!currentImageSrc) return;
112-
113123
currentShape = shape;
114-
resetImageAdjustment();
115124

116-
// Show controls
117-
imageAdjustControl.style.display = 'block';
118-
borderColorControl.style.display = 'block';
119-
positionControl.style.display = 'block';
125+
// 1. Show standard controls
126+
// Note: If you have a variable for imageAdjustControl, make sure it matches.
127+
// If your code uses 'imageAdjustControl', keep it.
128+
// If your previous code used specific IDs, ensure they match.
129+
// Based on your previous uploads, this is the standard set:
130+
if (document.getElementById('imageAdjustControl')) document.getElementById('imageAdjustControl').style.display = 'block';
131+
if (document.getElementById('borderColorControl')) document.getElementById('borderColorControl').style.display = 'flex';
132+
if (document.getElementById('positionControl')) document.getElementById('positionControl').style.display = 'block';
133+
134+
// 2. Show height slider ONLY for rectangle
135+
if (shape === 'rectangle') {
136+
rectHeightControl.style.display = 'block';
137+
} else {
138+
rectHeightControl.style.display = 'none';
139+
}
140+
141+
// 3. Reset position variables
142+
// (We use global variables typically found in your script)
143+
if (typeof imageX !== 'undefined') imageX = 0;
144+
if (typeof imageY !== 'undefined') imageY = 0;
145+
if (typeof imageScale !== 'undefined') imageScale = 1;
146+
147+
// 4. Reset zoom slider if it exists
148+
const zoomSlider = document.getElementById('imageZoom');
149+
if (zoomSlider) zoomSlider.value = 1;
120150

151+
// 5. Update the drawing
121152
updatePreview();
153+
154+
// 6. Scroll to result
155+
const resultContainer = document.getElementById('resultContainer');
156+
if (resultContainer) resultContainer.scrollIntoView({ behavior: 'smooth' });
122157
}
123158

124159
// ============================================
@@ -285,7 +320,18 @@ function createShapeWrapper(size, shape, src, borderColor) {
285320

286321
// Outer div (border)
287322
outerDiv.style.width = size + 'px';
288-
outerDiv.style.height = size + 'px';
323+
324+
// NEW: Calculate height for rectangle
325+
if (shape === 'rectangle') {
326+
const currentW = parseInt(document.getElementById('imageSize').value);
327+
const currentH = parseInt(document.getElementById('rectHeight').value);
328+
// Calculate ratio so it works for both Preview and Download
329+
const ratio = currentH / currentW;
330+
outerDiv.style.height = (size * ratio) + 'px';
331+
} else {
332+
outerDiv.style.height = size + 'px';
333+
}
334+
289335
outerDiv.style.background = borderColor;
290336
outerDiv.style.display = 'flex';
291337
outerDiv.style.justifyContent = 'center';
@@ -314,7 +360,7 @@ function createShapeWrapper(size, shape, src, borderColor) {
314360
outerDiv.style.shapeOutside = 'circle(50%)';
315361
innerDiv.style.borderRadius = '50%';
316362
img.style.borderRadius = '50%';
317-
} else if (shape === 'square') {
363+
} else if (shape === 'square' || shape === 'rectangle') {
318364
// Square shape logic (no radius, no clip-path)
319365
outerDiv.style.borderRadius = '0';
320366
outerDiv.style.shapeOutside = 'none';

style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,10 @@ textarea:focus {
484484
.color-picker-container {
485485
gap: 5px;
486486
}
487+
}
488+
/* Add this for the Rectangle Icon */
489+
.rect-icon {
490+
width: 28px;
491+
height: 18px;
492+
border: 2px solid #667eea;
487493
}

0 commit comments

Comments
 (0)