adding a widget to card using LC script

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 939
Joined: Thu Nov 13, 2008 6:48 am

adding a widget to card using LC script

Post by marksmithhfx » Thu Oct 23, 2025 9:00 pm

Hi, this is really a 2 part question.

Part 1. I am building a stack using primarily livecode script to place objects. I've am wondering if there is a guide to doing this kind of work lying around (and if not, I suppose I should think of creating one).

Part 2. How can I add a widget (in this case a header widget) to a card using script. What would the syntax look like?

Thanks
Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10392
Joined: Wed May 06, 2009 2:28 pm

Re: adding a widget to card using LC script

Post by dunbarx » Thu Oct 23, 2025 9:12 pm

Part 1. When you say "place", do you need a way to automate that process, because there are a lot of controls? Or because they need to follow some sort of pattern on the card? Something else?

Part 2. A widget is really just another type of control. You can pull it from the tools palette, from the Object menu or under script control. I suppose you could create a widget as well if you knew its type.

Craig

Klaus
Posts: 14255
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: adding a widget to card using LC script

Post by Klaus » Thu Oct 23, 2025 9:14 pm

Hi Mark,

1. sorry, no idea.
2. Take a look at the "kind" field in the inspector for widgets.
That is the thing to use in scripts:

Code: Select all

...
create widget "your name for the new widget here..." as "com.livecode.widget.headerbar"
...
Check "Create widget" in the dictionary for more info.


Best

Klaus

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 939
Joined: Thu Nov 13, 2008 6:48 am

Re: adding a widget to card using LC script

Post by marksmithhfx » Thu Oct 23, 2025 11:06 pm

Klaus wrote:
Thu Oct 23, 2025 9:14 pm
That is the thing to use in scripts:

Code: Select all

...
create widget "your name for the new widget here..." as "com.livecode.widget.headerbar"
...
Check "Create widget" in the dictionary for more info.
Thanks guys, that answers my question. And your example Klaus, and the one in the dictionary, were exactly what I was working on next. I had created a card under script control and now wanted to add the header and footer.

And I think elsewhere I explained to Craig why I am doing this, and it's bonkers but I want to see how far I can push the process of creating a complicated livecode app using Git for project management and version control. To that end I am trying to figure out what all the wrinkles and potential hurdles are creating the app using script-only stacks.

Many thanks to you both,
Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2

stam
Posts: 3140
Joined: Sun Jun 04, 2006 9:39 pm

Re: adding a widget to card using LC script

Post by stam » Fri Oct 24, 2025 8:10 am

marksmithhfx wrote:
Thu Oct 23, 2025 9:00 pm
Hi, this is really a 2 part question.

Part 1. I am building a stack using primarily livecode script to place objects. I've am wondering if there is a guide to doing this kind of work lying around (and if not, I suppose I should think of creating one).

Part 2. How can I add a widget (in this case a header widget) to a card using script. What would the syntax look like?

Thanks
Mark
What you are describing is quite close to “script widgets”. This was an LC10 way of creating widgets using LiveCode rather than LCB.
It’s uncertain whether either option will be available in the future with LC Create.

There is an LC lesson on this, but not that much else. I’m sure some must have used this and perhaps even documented this. I did for 1-2 of my own widgets but because this was never properly supported (as LCB wasn’t either) I suspect not many did adopt this or even remember this sadly.

In any case you can view the code for one of my script widgets here: https://github.com/stam66/tristate. It’s basically one long ScriptOnlyStack.

Stam

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 939
Joined: Thu Nov 13, 2008 6:48 am

Re: adding a widget to card using LC script

Post by marksmithhfx » Fri Oct 24, 2025 4:10 pm

Thanks Stam. I think that will be very helpful. But I've already run into a problem and I hope you (or someone) can spot the error of my ways (I'm probably not grasping some fundamental aspect of script-only stacks).

I created a small amount of code to (a) create a new card in a stack (b) size the card, and then (c) add a header and footer to the card. Code is below.

Code: Select all

script "OrganizeMain"
-- v1.0.0
-- Main stack for Organize iOS app
--
on preOpenStack
   -- Initialize when stack opens
   -- put "Organize starting..." into msg
   layoutCards
end preOpenStack

command layoutCards
   -- design the primary cards of the stack
   -- in essence, create the UI in script
   -- we'll do this for iPhone 15 for now, then add responsive elements afterwords
   
   create card "Main" in stack "OrganizeMain"
   -- set the myProperty of card "MyCard" to "value"
   set the width of card "Main" to "320"  <--- at this line I get an error, discussed below
   set the height of card "Main" to "568"
   set the left of card "Main" to "0"
   set the top of card "Main" to "0"
   set the layer of card "Main" to "1"
   
   -- header bar
   create widget "Header Bar" as "com.livecode.widget.headerbar"
   set the width of widget "Header Bar" to 320
   set the height of widget "Header Bar" to 64
   set the left of widget "Header Bar" to 0
   set the top of widget "Header Bar" to 0
   set the layer of widget "Header Bar" to 1
   
   -- navigation bar
   create widget "Navigation Bar" as "com.livecode.widget.navbar"
   set the width of widget "Header Bar" to 320
   set the height of widget "Header Bar" to 49
   set the left of widget "Header Bar" to 0
   set the top of widget "Header Bar" to 519
   set the layer of widget "Header Bar" to 2
   
end layoutCards
Basically, at the line 18 above, depending on how I run this code I get one of 2 error messages. If I execute the code by clicking on the /src/script file in my Github folder I get the message "stack "OrganizeMain": execution error at line 18 (Object: can't set this property)"

If instead I open the file from the LC file menu, then open the msg box and say "start using stack "OrganizeMain" and close the box, click on it again it runs the stack but produces an error at the same line that says "stack "OrganizeMain": execution error at line 18 (Chunk: can't find card), char 1"

I haven't gotten very far into this but from what I am seeing I'm guessing you can't create UI elements using a script-only stack? Or, if I'm wrong, what is the "proper" way to go about it.

Many thanks,
Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2

Klaus
Posts: 14255
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: adding a widget to card using LC script

Post by Klaus » Fri Oct 24, 2025 4:22 pm

Hi Mark,

a cards size is defined by the stacks size!
So you cannot set the width/height of a card separately, that'll throw an error.

Best

Klaus

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 939
Joined: Thu Nov 13, 2008 6:48 am

Re: adding a widget to card using LC script

Post by marksmithhfx » Fri Oct 24, 2025 4:53 pm

Thanks Klaus, that gives me an idea. (Although terribly difficult to wrap my head around as I am used to doing apps, well programs, either entirely in scripts (not LC of course) or entirely in a UI (glide and Lc come to mind). The challenge in doing something hybrid is knowing where the binary object ends and the text/script bit begins.

Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2

stam
Posts: 3140
Joined: Sun Jun 04, 2006 9:39 pm

Re: adding a widget to card using LC script

Post by stam » Fri Oct 24, 2025 9:06 pm

Hi Mark, the error you describe is likely because you should be defining the rect of the stack rather than the card.
marksmithhfx wrote:
Fri Oct 24, 2025 4:10 pm
from what I am seeing I'm guessing you can't create UI elements using a script-only stack? Or, if I'm wrong, what is the "proper" way to go about it.
No, I don't think that's right. If you look at my widget script, it essentially creates UI objects as part of a group. For native objects you basically create the template object for that native UI element or a new instance of of an existing widget.
Admittedly I have not done this by creating a stack and then elements on the card, but the logic seems transferrable.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 939
Joined: Thu Nov 13, 2008 6:48 am

Re: adding a widget to card using LC script

Post by marksmithhfx » Fri Oct 24, 2025 9:41 pm

stam wrote:
Fri Oct 24, 2025 9:06 pm
No, I don't think that's right. If you look at my widget script, it essentially creates UI objects as part of a group. For native objects you basically create the template object for that native UI element or a new instance of of an existing widget.
Admittedly I have not done this by creating a stack and then elements on the card, but the logic seems transferrable.
Thanks Craig. I'll give that a try!!

Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2

Post Reply