[Solved] How to style text and add images to Content Area of field?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: How to style text and add images to Content Area of field?

Post by ValiantCuriosity » Fri Mar 08, 2019 11:35 pm

@Bogs,

Opps! Yes, your code works. It just doesn't answer what I'm trying to do. I don't ever want the "raw" html code to show. I only want the styled result to show. I want the styled result to show no matter how many times I go from one card to another.

I am sending a sample so that you can see what I'm trying to do. The problem is that it only works one time. The second time it strips the text of the tags and displays, more or less, a standard LC text without styling.
HTMLText.livecode.zip
(1.44 KiB) Downloaded 181 times
TIA
-Rachel
May I never be cured of my curiosity! :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to style text and add images to Content Area of field?

Post by jacque » Fri Mar 08, 2019 11:42 pm

It sounds like you are creating (or retrieving) some htmlText on one card and you want it to show in another one when the card opens. Is that right?

If so, you can do it from card 1 if you want:

Code: Select all

on updateHTML
  -- retrieve the html here somehow, put it into a variable
  set the htmlText of fld "somefield" of card 2 to tVariable
end updateHTML
If instead you want to store the html somewhere and show it when card 2 opens later, put the retrieved html into a global variable (I don't like those but they work) or a custom property. Let's say you store it in a custom property:

Code: Select all

on updateHTML -- still on card 1
  -- retrieve the html here somehow, put it into a variable
  set the htmlVar of card 2 to tVariable -- creates a custom property of card 2 named "htmlVar"
end updateHTML
Then when card 2 opens:

Code: Select all

on preOpenCard -- on card 2
  set the htmltext of fld "somefield" to the htmlVar of this card
end preOpenCard
There is no specific "refresh" in LC but anything a script does to change the card is instantly displayed so it isn't needed very often.

Also, you can change almost anything from anywhere without actually being on that card; text in fields, appearance of controls, even scripts, as long as you use a full reference to the target object. The object can even be in a different stack.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to style text and add images to Content Area of field?

Post by jacque » Fri Mar 08, 2019 11:50 pm

I took a look at your stack. This line only retrieves the plain text:

Code: Select all

put field "Field" into tTemp
You haven't specified a text format, so it's getting the default which is plain text. If you want the htmltext, change the line to explicitly get what you want:

Code: Select all

put the htmltext of field "Field" into tTemp
It seems a little silly to get the html and then put it back, but I'm assuming you have bigger plans in mind. ;)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13866
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to style text and add images to Content Area of field?

Post by Klaus » Fri Mar 08, 2019 11:50 pm

AHA!

Must have overseen this in your earlier postings!
You do this:

Code: Select all

on preopenCard 
   put field "Field" into tTemp
   set the htmlText of field "Field" to tTemp
end preopenCard
The first time you open the card, LC takes the RAW source code text of that field and does the appropriate formatting to the same field (this is the key, see below).

OK, so far, so good.

But next time you visit that card
-> put field "Field" into tTemp
the field and tTemp does now contain the unformatted TEXT of that field,
because the field does NOT contain the above mentioned RAW html source anymore.

And you are right, I think you are thinking way too far. 8)
Why not just save your stack with the already nicely formatted field?
I really do not see any meaning in what your are currently doing "on preopencard", sorry :D


Best

Klaus

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: How to style text and add images to Content Area of field?

Post by ValiantCuriosity » Sat Mar 09, 2019 5:07 am

Thanks to everyone for your thought provoking replies.

I'll study your responses and see what I can do.

-Rachel
May I never be cured of my curiosity! :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to style text and add images to Content Area of field?

Post by bogs » Sat Mar 09, 2019 11:26 am

I took a look at the stack you posted. What I made of it was that you had put this text into the field initially -

Code: Select all

<h3 >Refrigerator Snacking?</h3>
<ul>
<li>Cheese with home made bread</li>
<li>Leftovers </li>
<li>Grapes </li>
<li>What ever you like and can find there.</li>
<li>Hey, when you are hungry, you are <p><b>HUNGRY!</b></p><li/>
</ul>

.. and you want that to display like this every time the card opens -
Selection_001.png
The htmlText...
.. and you want it to look that way every time you come to the card. First, I want to point out what Jacque was saying, you don't need code in the program to do this. Just to quickly convert your raw html to actual html displayed in the field, I did this in the message box -
Selection_002.png
Send da message...
.. then commented out all the code referring to it. That field is now set to the htmlText, and will display that way no matter how many times you open/close/navigate away/to it.
HTMLText1.livecode.zip
The power of the field!
(1.3 KiB) Downloaded 170 times
In the comments are the notes from this thread. Hope this helps out a bit more :D
Image

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: How to style text and add images to Content Area of field?

Post by ValiantCuriosity » Sat Mar 09, 2019 6:28 pm

@Bogs.

Are you superman in disguise?
SupermanBogs.png
SupermanBogs.png (4.27 KiB) Viewed 6559 times

That code snip is EXACTLY what I am trying to do. The days I spent on that and the solution was SO easy. You only convert ONE time. Sheesh! See what I mean about my not being a great coder. Everything I do takes me 100 times longer than most others.

I was planning on tackling HTMLtext again today, but I sure wasn't looking forward to it. Finding your sample was a major relief.

Jacque's solution made good sense but I haven't studied creating properties yet so I was thinking I'd need to do that first. Plus, even with properties, I'd still have been trying to convert, save, and convert. (endless loop)

Properties look so KOOL. I read a little about them last night, they will last beyond what a global variable lasts and will save the app's state. Probably a great use for the famous "To Do" app.

The only thing that keeps me going with LC is this forum and all of the people who make it so friendly.

Now off I go to see what other trouble I can manage to find in LiveCode.

Thank you, thank you, thank you. MAJOR joy.
-Rachel
May I never be cured of my curiosity! :D

Klaus
Posts: 13866
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to style text and add images to Content Area of field?

Post by Klaus » Sat Mar 09, 2019 6:37 pm

ValiantCuriosity wrote:
Sat Mar 09, 2019 6:28 pm
You only convert ONE time.
Not that we have been trying to explain this on the first page of this thread a couple of times... 8)

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: How to style text and add images to Content Area of field?

Post by ValiantCuriosity » Sat Mar 09, 2019 7:12 pm

Klaus,
Sometimes, "a picture is worth a thousand words"!

Thanks for your patience.

PS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
-Rachel
May I never be cured of my curiosity! :D

Klaus
Posts: 13866
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to style text and add images to Content Area of field?

Post by Klaus » Sat Mar 09, 2019 7:21 pm

ValiantCuriosity wrote:
Sat Mar 09, 2019 7:12 pm
Sometimes, "a picture is worth a thousand words"!
yep, sometimes. 8)
ValiantCuriosity wrote:
Sat Mar 09, 2019 7:12 pm
PS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
Oh, good question, although I'm an admin, I have no idea. :oops:
But this is really not neccessary.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to style text and add images to Content Area of field? [Solved]

Post by bogs » Sat Mar 09, 2019 9:26 pm

ValiantCuriosity wrote:
Sat Mar 09, 2019 6:28 pm
That code snip is EXACTLY what I am trying to do. The days I spent on that and the solution was SO easy. You only convert ONE time. Sheesh! See what I mean about my not being a great coder. Everything I do takes me 100 times longer than most others.
Since it took me a ^10 the amount of times it did you, I think you'll be fine :wink:
(Klaus and Jacque did say it first, me, I just take your request at face value and put what I think would work for that situation. Superman, or super silly, tough call :mrgreen: )
ValiantCuriosity wrote:
Sat Mar 09, 2019 6:28 pm
Properties look so KOOL.
Properties are very simple to make, set, and get, and as was also pointed out earlier in the thread, used a lot in place of almost anything else.
ValiantCuriosity wrote:
Sat Mar 09, 2019 7:12 pm
PS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
As simple as going to your first post in the topic, and typing [Solved] in any way you wish.
Selection_004.png
Problem solved ~ Jacques Clouseau
Image

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: [Solved] How to style text and add images to Content Area of field?

Post by ValiantCuriosity » Sun Mar 10, 2019 6:18 pm

@Bogs!
You are "THE Man" of the hour. I missed that one. Now, maybe, this whole long and painful journey with HTMLtext will save some other poor wandering soul. :shock:

-Rachel
May I never be cured of my curiosity! :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: [Solved] How to style text and add images to Content Area of field?

Post by jacque » Sun Mar 10, 2019 6:54 pm

I'm a one trick pony and LC is really the only language I know. But I did try dabbling in a couple of others way back when, and I found there is much more to it than just learning the terms and syntax. That's actually the easier part. You also have to know how the language interacts with the environment, and that varies. Learning that is as big a job as learning the rest of it.

If you're coming from a web based environment, you're used to recreating every page from scratch on every reload. That's not the behavior LC uses, where changes are permanent for the session, and if the stack is saved, permanent forever. It's stuff like this that can sometimes be a bigger hurdle than just figuring out what syntax to use.

You'll get there, but the first few weeks can be frustrating.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: [Solved] How to style text and add images to Content Area of field?

Post by ValiantCuriosity » Wed Apr 03, 2019 10:10 pm

@Bogs,

imageSource is "the bee's knees"! Thanks for pointing it out. It allows me to insert the photos into my descriptive text in a scrolling field. Happy Dancing here. :mrgreen:

Hey, I can even style the images to be centered or right aligned. BOY, did this all take some study. This the simplest part of a little test rewrite for one of my more basic apps. At first, I thought LC just would not do what I needed. Looks like there is a way!

It doesn't seem to flow the text around the image, but I can make due with what I've got for now.

Thanks to all who responded to this rather lengthy forum question.

-Rachel
May I never be cured of my curiosity! :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: [Solved] How to style text and add images to Content Area of field?

Post by bogs » Wed Apr 03, 2019 10:42 pm

We knew you could do it :D
ValiantCuriosity wrote:
Wed Apr 03, 2019 10:10 pm
It doesn't seem to flow the text around the image, but I can make due with what I've got for now.
No, imageSource will certainly not do that. What it is doing is taking one character in the field, and putting an image in its place, that is it. Think of it as a quick cheat (but maybe not the best cheat :wink: ).
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”