Margin in a TextArea?

Hi,
I know how to append text to the end of an already populated TextArea.
I also know how to insert text at the beginning of an already populated TextArea.

BUT:
How do I insert a string variable center aligned at the beginning of an already populated (left aligned) TextArea without changing the alignment of the existing text?

Hope that made sense :slight_smile:

Thank you all in advance.

Use the StyledText Class

Matthew,
I decided against it and kept everything left aligned.

I have another question though:
If I have a TextArea which is 700 pixels wide - is it possible to set a margin of 20 pixels on the left, so that all text entered has this left margin?

Thanks.

Maybe you can switch the TextArea’s borders off and draw the borders using a Canvas or Rectangle. Then just position the TextArea on the Canvas with the margins you need.

Thomas,
I am already doing that and I thought it had worked BUT, I then realised that if the TextArea’s content is above a certain amount - the TextArea’s scrollbar is obviously not right aligned with the Canvas - it is right aligned with the TextArea - thus showing a large white space on the right :frowning:

Try it and you will see what I mean.
That is why I am now trying to use a separate scrollbar to scroll the content.

That is a good approach, but it’s complicated and tricky to get right.

Another way is to use the MBS plugins – there’s a command I found in there (it’s been a while so I don’t remember it off-hand) that lets you specify the margins. Probably a declare can do that as well (it might even be in MacOSLib; I haven’t checked). Of course, with those approaches, it’s only for Mac OS X.

Yep, with OS X you can do it with a couple of declares. I don’t know about other platforms…

My app is OS X only at the moment, so are you saying the best way is to use MacOSLib, in order to use the appropriate declares?

Just out of curiosity - why is it tricky to use a scrollbar to scroll a TextArea? I would have thought it would have been a simple case or associating it with the TextArea? Obviously I am only a novice, so am probably looking at it through rose coloured glasses.

Try this in the TextArea.Open event:

[code]Dim margin As NSSize
margin.width = 50
margin.height = 50

Declare Function documentView Lib “Cocoa” Selector “documentView” (obj_id As Integer) As Ptr
Dim ref As Ptr = documentView(Me.Handle)

Declare Sub setTextContainerInset Lib “Cocoa” Selector “setTextContainerInset:” (obj_id As Ptr, value As NSSize)
setTextContainerInset(ref, margin)[/code]

You’ll have to create a structure NSSize with two fields, width As Single and height As Single.

Thomas,
I didn’t understand your very last line at all :frowning:

What is a structure?

Scrollbars are integrated into the TextArea control… you have no control over WHERE they appear… just IF they appear or not.

As to a structure… .the LangRef and User Guides are your friend :slight_smile:
But in simple terms… a structure is a datatype made up of one or more (usually more) fields…
in archaric terms it can be thought of as a stupid class (as it can have no methods or attributes… just… well uh… structure :slight_smile:

Look at Xojo Menu : INSERT -> Structure

you would be creating something like

STRUCTURE myStructurename
     width as single
     height as single
END STRUCTURE

Structures are NORMALLY (but not always) used to interact with Declares…

One common structure I use a lot is

   STRUCTURE myPOINT
       x as single
       y as single
  END STRUCTURE

Then I can do things like this [ROUGH example]

Dim pt as myPOINT //<---- the structure defined above
pt.x=3
pt.y=14

call somemethod(pt)

Thank you for the explanation Dave - somehow I managed to do it first time :slight_smile:

Shame it will only work on OS X :frowning:

What only works with OSX???
Structures? work OSX/WIN
TextArea same…

I had to use 2 Cocoa declares with the structure code - as advised above by Thomas?

The code to set TextArea margins has been very helpful. I’d like to do the same with TextFields, but it chokes on those. Is there an equivalent method for TextFields? Thanks.

Ugh that is painful :slight_smile: