Moving and expanding Text Field Objects
Posted: Sun Oct 04, 2020 7:57 pm
I am wanting to be able to move around some text fields and/or resize them then depending on where they are, snap into place. I have a bunch of vertical lines (whose left edge is in an array called vertsepleft) which designate the areas where the text fields need to be bounded by. The problem is that after moving around a field and then resizing it, it will sometimes randomly move part of the way across the stack to either the left or right or shrink really small. This is frustrating as I cannot figure out why it is doing this.
Here is my code (I have several fields which are grouped together into group "LettersinFields" and where this code resides.
(I'm going to add code to make it so the fields cannot overlap and so the bottom of them line up but haven't done so yet. Also I've added a little unnecessary code in efforts to try and figure out what's wrong).
global rleft
global rright
global rwidth
global rchangepos
global lchangepos
global fldname
global itsgrabbed
global clickedonfld
global vertsepleft
on mousedown
if the first word of the name of the target = "field" then
put true into clickedonfld
put the name of the target into fldname
put the left of fldname into rleft
put the right of fldname into rright
put the width of fldname into rwidth
if rright - (item 1 of the mouseloc) < 33 then
put true into rchangepos
end if
if (item 1 of the mouseloc) - rleft < 33 then
put true into lchangepos
end if
if rright - (item 1 of the mouseloc) > 33 and (item 1 of the mouseloc) - rleft > 33 then
grab the target
put true into itsgrabbed
end if
end if
end mousedown
on mousemove
if rchangepos or lchangepos then
put item 1 of the mouseloc into tmouseloc
if rchangepos then
put tmouseloc - rright into newpos
set the width of fldname to rwidth + newpos
set the left of fldname to rleft
end if
if lchangepos then
put rleft - tmouseloc into newpos
set the width of fldname to rwidth + newpos
set the right of fldname to rright
end if
end if
end mousemove
on mouseup
makegoodwidth
end mouseup
on mouserelease
makegoodwidth
end mouserelease
on makegoodwidth
if clickedonfld then
put false into rchangepos
put false into lchangepos
put false into clickedonfld
put false into itsgrabbed
put empty into snapfield
put empty into stayleft
if the width of fldname <= 50 then
set the width of fldname to 74
end if
repeat with i = 1 to the number of lines in the keys of vertsepleft
put abs(item 1 of the mouseloc - vertsepleft) & "," after snapfield
end repeat
put itemoffset(min(snapfield),snapfield) into sdfsdf
put vertsepleft[sdfsdf] + 2 into stayleft
set the left of fldname to stayleft
repeat with i = 1 to the number of lines in the keys of vertsepleft
put abs(the right of fldname - vertsepleft) & "," after snapfield1
put vertsepleft - the right of fldname & "," after snapfield2
end repeat
set the width of fldname to the width of fldname + item (itemoffset(min(snapfield1),snapfield1)) of snapfield2
set the left of fldname to stayleft
end if
end makegoodwidth
Here is my code (I have several fields which are grouped together into group "LettersinFields" and where this code resides.
(I'm going to add code to make it so the fields cannot overlap and so the bottom of them line up but haven't done so yet. Also I've added a little unnecessary code in efforts to try and figure out what's wrong).
global rleft
global rright
global rwidth
global rchangepos
global lchangepos
global fldname
global itsgrabbed
global clickedonfld
global vertsepleft
on mousedown
if the first word of the name of the target = "field" then
put true into clickedonfld
put the name of the target into fldname
put the left of fldname into rleft
put the right of fldname into rright
put the width of fldname into rwidth
if rright - (item 1 of the mouseloc) < 33 then
put true into rchangepos
end if
if (item 1 of the mouseloc) - rleft < 33 then
put true into lchangepos
end if
if rright - (item 1 of the mouseloc) > 33 and (item 1 of the mouseloc) - rleft > 33 then
grab the target
put true into itsgrabbed
end if
end if
end mousedown
on mousemove
if rchangepos or lchangepos then
put item 1 of the mouseloc into tmouseloc
if rchangepos then
put tmouseloc - rright into newpos
set the width of fldname to rwidth + newpos
set the left of fldname to rleft
end if
if lchangepos then
put rleft - tmouseloc into newpos
set the width of fldname to rwidth + newpos
set the right of fldname to rright
end if
end if
end mousemove
on mouseup
makegoodwidth
end mouseup
on mouserelease
makegoodwidth
end mouserelease
on makegoodwidth
if clickedonfld then
put false into rchangepos
put false into lchangepos
put false into clickedonfld
put false into itsgrabbed
put empty into snapfield
put empty into stayleft
if the width of fldname <= 50 then
set the width of fldname to 74
end if
repeat with i = 1 to the number of lines in the keys of vertsepleft
put abs(item 1 of the mouseloc - vertsepleft) & "," after snapfield
end repeat
put itemoffset(min(snapfield),snapfield) into sdfsdf
put vertsepleft[sdfsdf] + 2 into stayleft
set the left of fldname to stayleft
repeat with i = 1 to the number of lines in the keys of vertsepleft
put abs(the right of fldname - vertsepleft) & "," after snapfield1
put vertsepleft - the right of fldname & "," after snapfield2
end repeat
set the width of fldname to the width of fldname + item (itemoffset(min(snapfield1),snapfield1)) of snapfield2
set the left of fldname to stayleft
end if
end makegoodwidth