Page 1 of 1
My Stupid code 2
Posted: Mon May 07, 2018 6:07 pm
by MaxV
Hi,
another problem that I solved wasting a lot of cycles, do you have a better one?
I need to use the bigger font available to fit all the text inside the field.
Code: Select all
put true into ttt
put 1 into t2
repeat while ttt
add 1 to t2
set the textsize of field "presentazione" to t2
if the formattedheight of field "presentazione" > the height of field "presentazione" then
put false into ttt
set textsize of field "presentazione" to (t2 - 1)
end if
end repeat
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 12:08 pm
by richmond62
That seems to go round in circles until I hit the PANIC button.
"If you specify a
field, the
formattedWidth reports the width required by the field's text."
As the
textSize increases so does the
formattedWidth.
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 12:16 pm
by richmond62
-
this semi-works, in so far as it has a problem with wrapping test:
Code: Select all
on mouseUp
put 0 into DUN
put the textSize of fld "f1" into BIGG
repeat until DUN > 1
if the formattedWidth of fld "f1" > ((the width of fld "f1") - 1) then
add 1 to DUN
end if
if the formattedHeight of fld "f1" > ((the height of fld "f1") - 1) then
add 1 to DUN
end if
add 1 to BIGG
set the textSize of fld "f1" to BIGG
end repeat
end mouseUp
-
-
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 12:21 pm
by richmond62
If the
field is set to
dontWrap ones gets another stupid effect:
-
-
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 2:08 pm
by richmond62
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 3:02 pm
by bogs
Mind you, I haven't tested any of this yet (still working on my first cup of coffee
) but...
Wouldn't comparing the formatted width to the width of the field/label/etc like Richmond put there be the way to go? Something like that, but increase the subtraction level until it fits like your looking for -
Code: Select all
if the formattedWidth of field "xxx" > (the width of field "xxx" -5) then
for instance?
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 3:49 pm
by richmond62
Because the "subtraction level" would depend both on font size and word lengths.
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 5:02 pm
by jmburnod
Hi All,
This seems work:
Code: Select all
on mouseUp
put the short id of fld "f1" into tFldID
doSetTextSize tFldID,100,the height of fld "f1", the margins of fld "f1"
put the textsize of char 1 of fld "f1"
end mouseUp
on doSetTextSize pFldID,pTextSize,pHeightPoss,pMargin
put pTextSize into tSizeMax
set the textsize of char 1 to -1 of fld id pFldID to tSizeMax
set the fixedlineheight of fld id pFldID to false
put the width of fld id pFldID - (pMargin*2) into tMaxW
put the formattedheight of fld id pFldID into tFH
if tFH <= pHeightPoss then
set the height of fld id pFldID to tFH
end if
if tFH > pHeightPoss or the formattedwidth of fld id pFldID > tMaxW then
repeat with z = tSizeMax down to 6
if the optionkey is down then exit repeat --•• just for test
set the textsize of char 1 to -1 of fld id pFldID to z
put the formattedheight of fld id pFldID into tFH
if tFH <= pHeightPoss and the formattedwidth of fld id pFldID <=tMaxW then
exit repeat
end if
wait 1 milliseconds with messages
end repeat
end if
end doSetTextSize
Best
Jean-Marc
Re: My Stupid code 2
Posted: Sun Aug 26, 2018 10:01 pm
by jacque
I just tried MaxV's original handler and it seems to work fine, and is probably the shortest way to do it. The only problem I had was a sudden crash after the handler ended using LC 9.0.1(rc2) but I don't think that's the handler's fault. It may have been because I had other stacks open at the same time which may have interfered.
I wouldn't start the text at size 1 though, I'd start with something larger, maybe the effective textsize of the stack. Or alternately, see if the current size is too large and subtract from there, otherwise start with the current size and add up from there.