Beginner questions

Moderators: LCMark, LCfraser

Post Reply
MaxV
Posts: 1354
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Beginner questions

Post by MaxV » Wed Mar 15, 2017 6:18 pm

Hi,
I'm going crazy with widgets, I'm so full of questions. :oops:
  1. where is a documentation about canvas?
  2. where is a documentation about text to display?
  3. rProperties and pProperties are special internal array variables?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1551
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Beginner questions

Post by [-hh] » Thu Mar 16, 2017 2:07 am

Hi Max.

To 1.+2.
Choose API: LC Builder in the dictionary. Search for 'text' or 'canvas' and look at the examples.
To 3.
These are the parameter names usually used in OnSave and OnLoad.

That's all, there isn't more documentation.

But there are a lot of examples around as snippets or full working examples -- working at least in 8.1.1. The team uses to change the format regularly (without telling us) and it's usually NOT downward compatible, in some rare cases after recompiling or workarounds. So if some examples don't run this is not your or the authors fault, the format has changed. (That's why I stopped building until a stable release/guaranteed stable widget format.)

p.s. One simple and in LC 8.1.-8.1.3 fully working text example to start is here: Orientable text (rotate).

Just tested to work in LC 8.1.3 and to work NOT in LC 9.
Let me add the steps (not for you but for widget beginners).
  1. Unzip and put the lcb file in a new folder(where it is the _only_ lcb file).
  2. Open LC 8.1.3
  3. Open the Extension Builder.
  4. Open the lcb file (folder icon at top right).
  5. Click Test, a stack window with the widget opens.
  6. Open the property inspector for the widget.
  7. Play with the controls
shiftLock happens

MaxV
Posts: 1354
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Beginner questions

Post by MaxV » Thu Mar 16, 2017 1:20 pm

Thank you for your answer, but dictionary example are too short for me.
Moreover the new dictionary is very hard to read: I have continuously to resize all, and still I can't read comfortably :lol: .

Probably who used Java or C++ for graphics can understand the examples, but to me are indecipherable.
What is a canvas?
Do I need to initialize it? How?
Another mystery to me is this code:

Code: Select all

public handler OnLoad(in pProperties as Array)
	put pProperties["widgetTheme"] into mWidgetTheme
	put pProperties["colorScheme"] into mColorScheme
	put pProperties["checked"] into mSwitchIsOn
end handler

public handler OnSave(out rProperties as Array)
	put the empty array into rProperties
	put mWidgetTheme into rProperties["widgetTheme"]
	put mColorScheme into rProperties["colorScheme"]
	put mSwitchIsOn into rProperties["checked"]
end handler
If onSave save in a never declared before array called rProperties some properties, why OnLoad can retrieve those properties from another never declared before array called pProperties?
Where do these arrays go?
Where are stored? How the widget storing values principles work?

At the present I just understood of widget: metadata, use, properties and how to show them in the property inspector.
I have very difficult to go on, and I worked with C++, Java, PHP, Pascal, and other languages before (but never for graphic).
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1551
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Beginner questions

Post by [-hh] » Thu Mar 16, 2017 3:28 pm

OnSave writes out an array that is stored with the widget in the stack.
OnLoad gets the saved array back.

These handlers have an array as *parameter*, name it as you like it.
Parameters are not declared outside of the handler (just as in LC Script).

These handlers have nothing special to do with graphics. They simply enable you to "restore" a widget's state.
shiftLock happens

MaxV
Posts: 1354
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Beginner questions

Post by MaxV » Thu Mar 16, 2017 6:16 pm

[-hh] wrote:OnSave writes out an array that is stored with the widget in the stack.
OnLoad gets the saved array back.
Ok, but:
  • Do I have to use an array?
  • May I use just a variable? Or 2 variables?
  • If the name is not important, how can I be sure that is reading the properties array and not another array?
  • Why I have to declare in or out ad the beginning of the onSave() or onLoad()?
Documentation just states: "Handler the OnSave message to execute code when a stack containing the widget is saved." No more!
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1551
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Beginner questions

Post by [-hh] » Thu Mar 16, 2017 6:50 pm

OnSave and OnLoad together are the built-in "preferences mechanism" for a widget. This uses ONE array, you could call it "the prefs" of the widget.
Of course you can write and use your own mechanism.

The "in" and "out" are among the prefixes of params of every handler in LC Builder.
That's in the docs, read the LC Builder language guide in the dictionary to that.
shiftLock happens

MaxV
Posts: 1354
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Beginner questions

Post by MaxV » Fri Mar 17, 2017 1:19 pm

Thank you for your patience.
I need just another hint.
If I want a very simple widget that draw a line from the corner top left to the corner bottom right, what is the code?
You can skip all metas, properties, etc. I need just to know how to draw something inside a widget.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1551
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Beginner questions

Post by [-hh] » Fri Mar 17, 2017 3:40 pm

Hi Max.
Just use the dictionary examples (API: LC Builder) for fill and stroke inside your OnPaint() handler.
OnPaint() is forced to execute whenever you wirte "redraw all".

You could also look into my "basic template" and change it in steps. There are already your next questions answered: Community snippets #41, which contains
  • Public handler:
    OnPaint, OnCreate, OnLoad, OnSave, OnMouseDown (with popup menu) and several other mouse actions.
  • Timer handling:
    OnTimer, OnOpen, OnClose.
  • Basic properties:
    Color etc. , incl. using the property editor and dictionary entries.
  • Utility handler.
    hhStringToColor, hhColorToString, postRect, numListToStringList, numListToString, outsetRect.
To climb the first hill for an own widget is not this easy, because one has to write 'unusual code' compared to LC Script. But this is only the first hill. The next hills are much lower.
shiftLock happens

Post Reply

Return to “LiveCode Builder”