How to center-align text in Scintilla? - scintilla

In my application I have a custom control that implements syntax highlighting via the scintilla.dll.
There are all sorts of codes for setting the style of the text in the control.
However, I've searched and searched and can't figure out how to center-align text in the control.
What's the scintilla code for center-aligning a text style?

There is no "center-align" command in scintilla.
Here is what to do, however, to center the text:
Fetch the text from the control
Know what style is being used
Use TEXTWIDTH (2276) to figure the width of the text using that style
Use controlwidth /2 - textwidth /2 to figure the location of the left margin
Use SETMARGINLEFT (2155) to move the left margin
Note that the default style is 32.
You'll have to figure your code to update the location every time, however, maybe via some callback function.
In Autohotkey, it could look like this:
guicontrolget, editor
guicontrolget, editor, pos
textwidth := hwndeditor.2276(32,editor)
setplace := (editorW /2) - textwidth /2
hpeditor.2155(0,setplace)

Related

Firemonkey how to set font color for selected text in TEdit

I'm trying to find a way to use styles to set the color of the selected text in a TEdit in Firemonkey.
In Delphi VCL, the text color by default changes to white (or perhaps a windows constant) when the text is selected, so that it shows clearly through the selection highlight.
In FMX, the default style is for the text color not to change. That results in the text being hard to read. I'd like to set it so that it works like VCL, but I can't find anywhere in the style to set the text color of the selected text.
Thanks for any help you can provide.
Scott

Change Unity GUI.Box text colour

I am kind of new to Unity, and was just wondering how to change the text colour of a GUI.Box?
This is the line of code I am using:
GUI.Box(Rect(0, 0, width, height),"Hello World", "");
I tried putting:
GUI.color = Color.red;
above it, but that didn't work.
Thanks,
Fjpackard.
GUI.skin.box.normal.textColor = Color.red;
Perhaps a better way is take a look at GUIStyles (http://docs.unity3d.com/Documentation/Components/class-GUIStyle.html) since GUIStyle is an easy way to modify the appearance of the whole GUI.
In some cases you may want to change only a specific word or sentence, so you just need to make your text like that:
sb.Append("<size=10> <color=yellow>WARNING: </color> Some text here</size>");
In this case my style font size is 8, so this text will be a bit bigger then the other lines, the word WARNING will be written in yellow and 'Some text here' is the default color. All the other text inside my string builder will use the Box Style
For more details check:
https://docs.unity3d.com/Manual/StyledText.html

Poorly rendered text (NSFont) in MacRuby/Cocoa. Any advice?

I have a small MacRuby app that displays some text inside a NSTextView. I have a method called make_label() that builds an NSTextView with some text and returns it, which I use to add to another NSView via addSubview()
make_label() looks like this:
def make_label( x, y, width, height, color, font_size, text )
label = NSTextView.alloc.initWithFrame( NSMakeRect( x, y, width, height) )
font = NSFont.systemFontOfSize(font_size)
label.setFont( font )
label.insertText( text )
label.setTextColor( color )
label.setDrawsBackground(false)
label.setRichText(true)
label.setEditable(false)
label.setSelectable(false)
label
end
My question is, how come my text looks so poorly rendered? It looks very pixelated and not antialiased at all (from what I can see).
Click here for screenshot
This screenshot shows 2 different sizes of the font, with the same phenomenon.
Cocoa can't draw sub-pixel antialiased text if it's rendering to a context that isn't opaque.
I come from the objective-C side, so I'm guessing a bit, but try setting label.setDrawsBackground(false) to true.
The culprit was setWantsLayer(true) which was called for the view I was drawing in. I deleted that line and I also needed to label.setDrawsBackground(false) as joerick described.

How to align text to the top of the button in Matlab GUI?

I have a GUI with big buttons and wouls like to align the text in the button to the top, all I found is "horizontal alignment" property.
Thanks...
You need to access the underlying Java Swing component (I am using FINDJOBJ function):
figure('Menubar','none', 'Position',[200 200 300 200])
h = uicontrol('Style','pushbutton', 'String','click', ...
'Units','normalized', 'Position',[0.3 0.3 0.5 0.5]);
jh = findjobj(h);
jh.setVerticalAlignment( javax.swing.AbstractButton.BOTTOM );
I'm afraid I think you can't do this - text is always vertically aligned at the middle on a uicontrol. The only hacks I can think of that might achieve something like what you want are
Add extra return characters after your main text, so that the real text ends up at the top while the whole text remains centred
(REALLY horrible) Create an image with your text right at the top, and use this with the CData property of the button.

Alternating the background color of rows or text boxes

I have data coming from data base in crystal report by SAP with VS2010 SQLServer, displayed in text boxes since Crystal doesn't have data grids.
How can there I alternate the background colors of those text boxes?
Create a custom formula; call it 'Colorize':
//Color every other row as light tan (alter RGB to suit tastes)
Function (Numbervar row, Optional Numbervar Color := RGB(239,235,220))
If Remainder(row,2)=0 Then
Color
Else
crNoColor
Add the following to the Detail section's Background Color conditional-formatting formula:
Colorize(RecordNumber)
//or over-ride color
Colorize(RecordNumber, crSilver)
You can also use it with group header section by passing the GroupNumber keyword:
Colorize(GroupNumber)
If you are doing anything fancy w/ grouping, you may want to use a running-total formula:
//{#G1}
WhilePrintingRecords;
Numbervar i;
i:=1+1;
Add this formula to group-header section, then suppress it.
Change the grouper-header's conditional formula to:
WhilePrintingRecords;
Numbervar i;
Colorize(i);
There are two ways that I do this. The first is the easiest but least robust. In the details section, you can just add a background color formatting formula like this: if recordnumber mod 2 = 0 then crgray else crnocolor
The second is if you need more control over your formatting, say if you're not displaying the details section at all and just group footers/headers. It just involves keeping track of a single boolean variable. In the section that you want to flip-flop, add this to your background color formatting formula: whileprintingrecords;
booleanvar fliprow;
fliprow := not fliprow;
if fliprow then crgray else crnocolor
To achieve this for text boxes. You are going to create a custom formula, I created "Toggle"
WhilePrintingRecords;
Global booleanVar g_bGreyRow := Not(g_bGreyRow);
Then insert a text box and add the Toggle formula field. Then you will want to select the text box and format the text. Select the border tab and check the background box and in the custom formula editor add
Global booleanVar g_bGreyRow;
If g_bGreyRow
Then color(231, 231, 231)
Else crNoColor
Now your text box will toggle the background color on and off. There is one small issue though and that is you will see the text True or False. I fixed this by first selecting Edit Text... then select the text and right click for text formatting. I set the color of the text to white and the size to 1, then I changed the format of the Toggle text from true and false to T and F, this makes it basically non-visible. Also make sure to move your text box to the back. I use this method when I do not want or need the entire sections background to be changed and just a portion.

Resources