adding a widget to card using LC script
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
marksmithhfx
- VIP Livecode Opensource Backer

- Posts: 939
- Joined: Thu Nov 13, 2008 6:48 am
adding a widget to card using LC script
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
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
Re: adding a widget to card using LC script
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
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
Re: adding a widget to card using LC script
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:
Check "Create widget" in the dictionary for more info.
Best
Klaus
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"
...Best
Klaus
-
marksmithhfx
- VIP Livecode Opensource Backer

- Posts: 939
- Joined: Thu Nov 13, 2008 6:48 am
Re: adding a widget to card using LC script
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.Klaus wrote: ↑Thu Oct 23, 2025 9:14 pmThat is the thing to use in scripts:Check "Create widget" in the dictionary for more info.Code: Select all
... create widget "your name for the new widget here..." as "com.livecode.widget.headerbar" ...
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
Re: adding a widget to card using LC script
What you are describing is quite close to “script widgets”. This was an LC10 way of creating widgets using LiveCode rather than LCB.marksmithhfx wrote: ↑Thu Oct 23, 2025 9:00 pmHi, 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
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

- Posts: 939
- Joined: Thu Nov 13, 2008 6:48 am
Re: adding a widget to card using LC script
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.
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
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
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
Re: adding a widget to card using LC script
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
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

- Posts: 939
- Joined: Thu Nov 13, 2008 6:48 am
Re: adding a widget to card using LC script
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
Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2
Re: adding a widget to card using LC script
Hi Mark, the error you describe is likely because you should be defining the rect of the stack rather than the card.
Admittedly I have not done this by creating a stack and then elements on the card, but the logic seems transferrable.
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.marksmithhfx wrote: ↑Fri Oct 24, 2025 4:10 pmfrom 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.
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

- Posts: 939
- Joined: Thu Nov 13, 2008 6:48 am
Re: adding a widget to card using LC script
Thanks Craig. I'll give that a try!!stam wrote: ↑Fri Oct 24, 2025 9:06 pmNo, 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.
Mark
macOS 15.6 (Sequola), Xcode 15.3, LC 10.0.2, iOS 18.6.2