backColor and indented text

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

Post Reply
scrabbles
Posts: 25
Joined: Sat Dec 20, 2014 4:32 am

backColor and indented text

Post by scrabbles » Sun Mar 08, 2015 1:05 pm

Hi,

I can't for the life of me find out how to get a line of text in a scrolling text field to have a backcolor across the whole line (width of field) when the text has a left indent set. If i use firstIndent, the indented area keeps the background color i have set, but leftIndent does not and uses the field's or cards backcolor. Some of the lines of my text wrap around, so i can't rely on first indent. I've tried margins but they only seem to be for the field as a whole - i need to do it for only a couple of lines in the field (of say 50 lines, only 10).

This is on OS X yosemite with LC 7.0.2

thanks for any help

- Mark

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

Re: backColor and indented text

Post by dunbarx » Sun Mar 08, 2015 4:07 pm

Hi.

Try this, with a regular field of ordinary width, with some text in it:

Code: Select all

on mouseUp
   set the leftIndent of line 2 of fld 1 to -10
   set the rightindent of line 2 of fld 1 to -25
   set the backColor of line 2 of fld 1 to yellow
end mouseUp
You cannot just set those values to "-9999999" to cover all possibilities, because the width of the field and its text needs to be managed to keep everything in range. Try it. Set one of those values to "-99999". The line disappears, because I assume the indent went off the edge of the field. If you play around with the above handler, and add or subtract text to that line, you will see what I mean. The back color will track the text if it gets too far from the index value, but fill right to the edge when you "get in range".

I have not played with this much, but I imagine the formatted width could be used to find the limits of those negative indices.

Craig Newman

scrabbles
Posts: 25
Joined: Sat Dec 20, 2014 4:32 am

Re: backColor and indented text

Post by scrabbles » Sun Mar 08, 2015 9:57 pm

Thanks Craig, I played around with this for about half an hour. The negative "offsets" work a treat for fixing the backcolor, but then of course, I lose the indenting of my text. What I don't understand is why firstIndent works the way i want (except for wrapped lines), but normal indent does not.

What I'm trying to achieve is a text field with indented text, having a number of heading lines where those heading lines have a different background colour for the whole line across the width of the field, similar to attached.

thanks again for your help

- mark
Attachments
indent-bc-lc.jpg
indent-bc-lc.jpg (34.83 KiB) Viewed 4222 times

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

Re: backColor and indented text

Post by dunbarx » Sun Mar 08, 2015 11:08 pm

Hmmm.

So if it true that there is no way to use any of these native tools to advantage, then, if you are an adventurous sort, I would create a set of properly sized graphic rectangles and set them at the lines of interest. This is a kluge and a half, but that would not stop me. This requires constant management, but it is simple management, and likely fun to code.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: backColor and indented text

Post by jacque » Mon Mar 09, 2015 6:25 pm

Set the backcolor of the heading line, and set the leftIndent of the text line:

Code: Select all

set the backcolor of line 1 of fld 1 to "green"
set the leftIndent of line 2 of fld 1 to 18
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: backColor and indented text

Post by dunbarx » Mon Mar 09, 2015 9:39 pm

Jacque.

The OP wanted the backColor of the line to extend edge to edge, regardless of the length of the text of that line. That is why I suggested using a negative indent on both sides. You just have to manage the values of those negative numbers, because if those values are too great, the text will shoot off one side or the other.

There is no mention of this in the dictionary, so I think I will add a note.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: backColor and indented text

Post by jacque » Tue Mar 10, 2015 2:32 am

Or set the leftmargin and rightmargin of the field to 0, and leave the top and bottom margins bigger. If the text of the headings is too scrunched against the side, add a few spaces before the text, or a tab with a short tabstop.

The indented text lines can have their own independent left and right indents so the field margins won't matter.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply