Page 1 of 1

Canvas

Posted: Thu Aug 02, 2018 3:42 pm
by MaxV
Hello,
I'm struggled with Canvas. After 2 years no real documentation so I'm wandering in the dark.
I tried this widget, but I get an empty widget, what's wrong?

Code: Select all

widget com.livecode.widget.testmax
-- proviamo un semplice test
 --Libraries

 use com.livecode.canvas
 use com.livecode.widget
 use com.livecode.engine
 use com.livecode.logic

 --Metadata
 metadata title is "Test Text"
 metadata author is "Massimiliano Vessi"
 metadata version is "0.0.1"
 metadata svgicon is "M1123 1409L1123 1228Q1035 1284 949 1284 898 1284 861 1261 832 1244 822 1216 811 1186 811 1087L811 792 1085 792 1085 611 811 611 811 320 647 320Q636 410 607 467 578 524 529 566 481 606 413 629L413 792 540 792 540 1196Q540 1274 557 1317 574 1359 616 1395 659 1432 720 1452 782 1472 860 1472 927 1472 989 1458 1046 1445 1123 1409ZM1536 416L1536 1376Q1536 1495 1451.5 1579.5 1367 1664 1248 1664L288 1664Q169 1664 84.5 1579.5 0 1495 0 1376L0 416Q0 297 84.5 212.5 169 128 288 128L1248 128Q1367 128 1451.5 212.5 1536 297 1536 416Z"

 --Properties
 property theText get gText set setText
 metadata theText.editor is "com.livecode.pi.string"
 metadata theText.label is "The text to show"
 metadata theText.default is "Ciao!"

--Variables
 private variable gText as String
 private variable mTextPaint as Paint

--handlers

--handler onCreate()
--   put "The text to show" into mText
--end handler

handler OnPaint()
   put solid paint with color [1,1,1] into mTextPaint
   set the paint of this canvas to mTextPaint
   set the font of this canvas to font "FreeSans" at size 12
   fill text gText at point [0,12] on this canvas
end handler

private handler setText(in pText as String)
	put pText into gText
end handler

handler onSave(out rProperties as Array)
   put the empty array into rProperties
   put gText into rProperties["theText"]
end handler

handler OnLoad(in pProperties as Array)
   put pProperties["theText"] into gText
end handler

end widget


Re: Canvas

Posted: Thu Aug 02, 2018 4:45 pm
by trevordevore
You need to define your OnPaint() handler as `public`.

Code: Select all

public handler OnPaint()
   put solid paint with color [1,1,1] into mTextPaint
   set the paint of this canvas to mTextPaint
   set the font of this canvas to font "FreeSans" at size 12
   fill text gText at point [0,12] on this canvas
end handler

Re: Canvas

Posted: Mon Aug 06, 2018 1:35 pm
by MaxV
Thank Trevore, it works... but I knew that all handlers are public if not declared as private. Like variables.

Re: Canvas

Posted: Mon Aug 06, 2018 2:04 pm
by trevordevore

Re: Canvas

Posted: Tue Aug 07, 2018 11:03 am
by [-hh]
Max, before you waste time with testing public/private:
For *user-variables* and *user-handlers* being public is not yet implemented in LCB ...

Re: Canvas

Posted: Tue Aug 07, 2018 11:56 am
by MaxV
So what handlers must be declared as public?

Re: Canvas

Posted: Tue Aug 07, 2018 12:22 pm
by [-hh]
AFAIK there is no closed list of such handlers.
I use as a thumb rule: All handlers must be public that handle LCB messages starting with "On".
OnAttach, OnClick, ..., OnVisibilityChanged. See the examples in the Dictionary.

Re: Canvas

Posted: Mon Aug 13, 2018 9:29 am
by livecodeali
Hi Max,
I added an overview of the canvas API with examples in the Extending LiveCode document in the 9.0 GM release:

https://github.com/livecode/livecode-id ... canvas-api

Please give that a read and let me know what we can do to improve it. Thanks!

Re: Canvas

Posted: Mon Aug 20, 2018 12:20 pm
by MaxV
livecodeali wrote:
Mon Aug 13, 2018 9:29 am
Hi Max,
I added an overview of the canvas API with examples in the Extending LiveCode document in the 9.0 GM release:

https://github.com/livecode/livecode-id ... canvas-api

Please give that a read and let me know what we can do to improve it. Thanks!
WOW, I really need it!