Big bunch of questions
Big bunch of questions
-can I / how do I wrap text in a widget?
-if I put text into a rect, and the text is to long to stay within the rect, how can I cut it off?
-can I (and how) can I align text (e.g. center or right-align)
-are there any functions built in for drawing SVGs within an widget?
-are there any easy methods for converting a list, point, rect, or paint into a string?
-if I put text into a rect, and the text is to long to stay within the rect, how can I cut it off?
-can I (and how) can I align text (e.g. center or right-align)
-are there any functions built in for drawing SVGs within an widget?
-are there any easy methods for converting a list, point, rect, or paint into a string?
Greg (pink) Miller
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Re: Big bunch of questions
Hm.pink wrote: ↑Thu Aug 09, 2018 3:46 am-can I / how do I wrap text in a widget?
-if I put text into a rect, and the text is to long to stay within the rect, how can I cut it off?
-can I (and how) can I align text (e.g. center or right-align)
-are there any functions built in for drawing SVGs within an widget?
-are there any easy methods for converting a list, point, rect, or paint into a string?
- Hopefully, someone that works in the newer vers. of the IDE will pop in for this one.
- I assume by "cut it off" you mean to wrap it. Just make sure that the 'dontWrap' is unchecked (see picture below).
- The easiest way would be to go to the 'text formatting' properties of the field you want to set (see second picture below).
- Again, I'll leave this to people who use the newer IDEs to answer.
- Sure, if I understand what your asking (not sure what you mean by "point" and "paint", but see the code block below for what I think I did understand...
Code: Select all
// converting a list into a string...
# I am guessing you are working from a file or text field, or even from a function.
# if you open the message box and type in the single line field
put the colorNames
# you will see a list of the different color names available in Lc. to put this list into a string,
# the code would look something like (create a default stack, one button, one field) ~
// in the button code ...
on mouseUp
put "" into field "lstField" // put the name of your field or string variable here...
repeat for each word x in the colorNames
put " " & x after field "lstField" // the quotes have 2 spaces for separation...
end repeat
end mouseUp
Code: Select all
# change the code in the button ...
on mouseUp
put "" into field "lstField"
put the rect of me into field "lstField"
// the rect of the button is now a string in the field...
end mouseUp
Code: Select all
on mouseUp
put "" into field "lstField"
put the mouseLoc into field "lstField"
// you will now see the coordinates of the mouse position on screen in the field...
// if you move it to different parts of the button, you'll see the points change...
end mouseUp
Re: Big bunch of questions
Hi Bogs,
I think ALL of Gregs questions relate to LiveCode Builder!
Simply because this is the LiveCode Builder forum, and Greg is no newbie.
Best
Klaus
I think ALL of Gregs questions relate to LiveCode Builder!
Simply because this is the LiveCode Builder forum, and Greg is no newbie.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Big bunch of questions
To 1 and 2pink wrote:1-can I / how do I wrap text in a widget?
2-if I put text into a rect, and the text is to long to stay within the rect, how can I cut it off?
3-can I (and how) can I align text (e.g. center or right-align)
4-are there any functions built in for drawing SVGs within an widget?
5-are there any easy methods for converting a list, point, rect, or paint into a string?
You have to do your own wordwrap algorithm. Helpers:
the image bounds of text tText on this canvas (respects the current font settings for the canvas),
the [layout] bounds of text tText on this canvas (respects the current font settings for the canvas),
the [layout] bounds of text tText with tFont.
To 3
Use "fill text mText at mAlignment of mRect on mCanvas". For centering compute linewise the bounds of the "text boxes" and center the "text boxes".
To 4
Not generally. Only for placing simple SVG pathes (like the iconPath of SVG Icon widget).
For that
use com.livecode.library.iconsvg
and you can for example "put path iconSVGPathFromName(tText) into tPath".
To 5
There are a few, as "formatNumberListAsItems(pList)". Else you have to write your own.
You can use for that "combine" or build the string with concatenation ("&").
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Location: Overland Park, Kansas
- Contact:
Re: Big bunch of questions
Here are a couple of functions I've used.
Fit text within a certain width. Add ... if it doesn't fit.
Convert a color to string
Convert a point to string
Fit text within a certain width. Add ... if it doesn't fit.
Code: Select all
public handler fitStringToRect(inout pString as String, in pFont as Font, in pMaxWidth as Number) returns nothing
-- Now make sure that text will fit within the available width
variable tTextRect as Rectangle
variable tEllipsis as String
variable tCharCount as Integer
put "..." into tEllipsis
put the number of chars in tEllipsis into tCharCount
put the bounds of text pString with pFont into tTextRect
if the width of tTextRect > pMaxWidth then
put tEllipsis into char -tCharCount to -1 of pString
put the bounds of text pString with pFont into tTextRect
repeat forever
if the width of tTextRect <= pMaxWidth or pString is tEllipsis then
exit repeat
else
put "..." into char -(tCharCount+1) to -1 of pString
put the bounds of text pString with pFont into tTextRect
end if
end repeat
end if
end handler
Code: Select all
public handler colorToString(in pColor as Color, in pIncludeAlpha as Boolean) returns String
variable tColor as String
if pColor is nothing then
return ""
end if
put FormatInt(the rounded of ((the red of pColor) * 255)) into tColor
put "," & FormatInt(the rounded of ((the green of pColor) * 255)) after tColor
put "," & FormatInt(the rounded of ((the blue of pColor) * 255)) after tColor
if pIncludeAlpha then
put "," & FormatInt(the rounded of ((the alpha of pColor) * 255)) after tColor
end if
return tColor
end handler
----------
-- this handler converts a String of numbers to an RGBA color
public handler stringToColor(in pString as String) returns Color
if the number of chars in pString is 0 then
return ""
end if
variable tRed as Number
variable tGreen as Number
variable tBlue as Number
variable tAlpha as Number
variable tComponentList as List
split pString by "," into tComponentList
variable tComponentCount
put the number of elements in tComponentList into tComponentCount
if tComponentCount is not 3 and tComponentCount is not 4 then
// Invalid number of components detected
throw "Invalid color"
end if
put (element 1 of tComponentList) parsed as number into tRed
put (element 2 of tComponentList) parsed as number into tGreen
put (element 3 of tComponentList) parsed as number into tBlue
if tComponentCount is 4 then
if element 4 of tComponentList is "inf" then
put 255 into tAlpha
else
put the minimum value of [255, (element 4 of tComponentList) parsed as number] into tAlpha
end if
else
put 255 into tAlpha
end if
return color [ tRed/255, tGreen/255, tBlue/255, tAlpha/255 ]
end handler
Code: Select all
public handler stringToPoint(in pString as String) returns Point
variable tList as List
variable tPoint as Point
put point [0,0] into tPoint
split pString by ","
put the result into tList
put tList parsed as list of number into tList
if the number of elements in tList is 2 then
put point [element 1 of tList, element 2 of tList] into tPoint
end if
return tPoint
end handler
public handler pointToString(in pPoint as Point) returns String
return FormatInt(the x of pPoint) & "," & FormatInt(the y of pPoint)
end handler
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Big bunch of questions
Thanks guys, this helped out a lot
Greg (pink) Miller
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Re: Big bunch of questions
@pink: Yes - you can render SVG inside widgets. In LiveCode 9 we added the 'drawing' (drw) format emitted by the drawingCompileSvg function as a known image format. This means such data can be set as the text of an image *and* used with the image from data / file constructors available in LCB.
Note: SVG text is not supported - it has to passed though drawingCompileSvg first (the drawing format is basically a binary form of SVG in some sense - its actually a metafile format which supports a good subset of SVG operations).
Note: SVG text is not supported - it has to passed though drawingCompileSvg first (the drawing format is basically a binary form of SVG in some sense - its actually a metafile format which supports a good subset of SVG operations).