It IS a Cocoa project
so n is nil? With current plugins?
What does
MsgBox me.NSViewMBS.classPath
show for the label. Should include NSTextField.
XOJStaticText:NSTextField:NSControl:NSView:NSResponder:NSObject
In the plugins folder :
MBS Xojo Cocoa Plugin.xojo_plugin
MBS Xojo CocoaBase Plugin.xojo_plugin
MBS Xojo CocoaControls Plugin.xojo_plugin
MBS Xojo CocoaExtras Plugin.xojo_plugin
MBS Xojo GraphicsMagick Plugin.xojo_plugin
MBS Xojo MacOSX Plugin.xojo_plugin
MBS Xojo MacOSXCF Plugin.xojo_plugin
MBS Xojo MacOSXCG Plugin.xojo_plugin
MBS Xojo Main Plugin.xojo_plugin
MBS Xojo Picture Plugin.xojo_plugin
MBS Xojo Util Plugin.xojo_plugin
The code does not trigger unknown classes errors anyway, so it seems plugins are there.
Here is the project :
labellinespacing.xojo_binary_project
that project compiles well here and works.
Did you download 14.3pr5, just to make sure we use same version.
[quote=122088:@Christian Schmitz]that project compiles well here and works.
Did you download 14.3pr5, just to make sure we use same version.[/quote]
I was using 14.2, updating to 14.3pr2 fixed the issue.
I put a slider on the window which changes the value of m from 1 to 30, and it works splendidly.
Thank you Christian.
[quote=120374:@Christian Schmitz]With MBS Plugin:
[code] dim n as NSTextFieldMBS = me.NSTextFieldMBS
dim a as NSAttributedStringMBS = n.attributedStringValue
dim p as NSParagraphStyleMBS = a.attributeAtIndex(a.NSParagraphStyleAttributeName, 0)
dim m as NSMutableParagraphStyleMBS = p.mutableCopy
m.setLineSpacing 5
dim s as NSMutableAttributedStringMBS = a.mutableCopy
s.addAttribute(a.NSParagraphStyleAttributeName, m, new NSRangeMBS(0, s.length))
n.attributedStringValue = s[/code]
As you see we set the line spacing and put back the new paragraph style with the attributed string.[/quote]
Christian, I had occasion to try this and it works well. At least for labels; for textFields, exception at line 3 (dim p as…). Cocoa text fields also look as ugly as labels, so is there a way to tighten the line spacing for these?
P.
Well, here is a new version:
[code] // works for Labels, TextArea and TextFields
// control is either a textfield or a textview
dim n as NSTextFieldMBS = me.NSTextFieldMBS
dim v as NSTextViewMBS = me.NSTextViewMBS
// get text with attributes
dim a as NSAttributedStringMBS
if n<>Nil then
a = n.attributedStringValue
elseif v<>nil then
a = v.textStorage
end if
// get style
dim p as NSParagraphStyleMBS
try
p = a.attributeAtIndex(a.NSParagraphStyleAttributeName, 0)
catch ex as NSExceptionMBS
// we have none, so make one
p = new NSParagraphStyleMBS
end try
// modify it
dim m as NSMutableParagraphStyleMBS = p.mutableCopy
m.setLineSpacing 5
// add back to styled text
dim s as NSMutableAttributedStringMBS = a.mutableCopy
s.addAttribute(a.NSParagraphStyleAttributeName, m, new NSRangeMBS(0, s.length))
// and apply to control
if n<>Nil then
n.attributedStringValue = s
elseif v<>nil then
v.textStorage.setAttributedString s
end if[/code]
you can use it for labels, text areas and textfields.
[quote=125243:@Christian Schmitz]Well, here is a new version:
[code] // works for Labels, TextArea and TextFields
// control is either a textfield or a textview
dim n as NSTextFieldMBS = me.NSTextFieldMBS
dim v as NSTextViewMBS = me.NSTextViewMBS
// get text with attributes
dim a as NSAttributedStringMBS
if n<>Nil then
a = n.attributedStringValue
elseif v<>nil then
a = v.textStorage
end if
// get style
dim p as NSParagraphStyleMBS
try
p = a.attributeAtIndex(a.NSParagraphStyleAttributeName, 0)
catch ex as NSExceptionMBS
// we have none, so make one
p = new NSParagraphStyleMBS
end try
// modify it
dim m as NSMutableParagraphStyleMBS = p.mutableCopy
m.setLineSpacing 5
// add back to styled text
dim s as NSMutableAttributedStringMBS = a.mutableCopy
s.addAttribute(a.NSParagraphStyleAttributeName, m, new NSRangeMBS(0, s.length))
// and apply to control
if n<>Nil then
n.attributedStringValue = s
elseif v<>nil then
v.textStorage.setAttributedString s
end if[/code]
you can use it for labels, text areas and textfields.[/quote]
Thx Christian, much appreciated. Progress. Works for TextAreas, but TextFields are stubbornly resistant to change:
The TextField in the example has:
m.setLineSpacing 0
m.setMaximumLineHeight 5
m.setParagraphSpacingBefore 0
m.setAlignment(NSMutableParagraphStyleMBS.NSRightTextAlignment)
I tried everything to force the text to appear at the top of the field and not cropped as you can see in the png. The m.setAlignment finally convinced me that TextFields completely ignore all attempts at resetting their attributes. Is there a way to coax TextField to obey attributes as per NSMutableParagraphStyleMBS? (we’re almost there!)
As an aside, the whole Cocoa vs. text display is quite a mess I must say, we should not have to go thru these gymnastics just to get text to be properly displayed in a simple TextField. The same problem exists for text in panel tabs: it is often drawn too low in the tab and looks ugly. I don’t know if it’s Xojo’s or Cocoa’s fault. either way, it needs to be corrected.
P.