I have been experiencing some really weird problems with gtk_label text positioning.
I have a gtk_label positioned on a fixed container, the label has been set to:
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
However when a single word is present in the label, instead of getting centered it gets left aligned.
If I unset gtk_label_set_line_wrap(GTK_LABEL(label), TRUE) to FALSE the word then appears in the center of the label, but I lose wrapping.
How should this be fixed?
From the documentation (emphasis mine):
gtk_label_set_justify ()
Sets the alignment of the lines in the text of the label relative to each other. GTK_JUSTIFY_LEFT is the default value when the widget is first created with gtk_label_new(). If you instead want to set the alignment of the label as a whole, use gtk_misc_set_alignment() instead. gtk_label_set_justify() has no effect on labels containing only a single line.
As suggested in the above quote, you may wish to add a call to the gtk_misc_set_alignment() function, with its xalign parameter set to 0.5, before calling gtk_label_set_justify().
Related
I am writing an application in ncurses and I am dealing with colour displaying in pads. I add some text into pad p with colour attribute on like this:
if(has_colors())
start_color();
init_pair(0, COLOR_GREEN, COLOR_BLACK);
attron(COLOR_PAIR(0));
while( (ch=fgetc(f)) != EOF){
waddch(p,ch);
}
attroff(COLOR_PAIR(0));
fclose(f);
But then when I display part of the tab with prefresh(p,0, 0, 0,0, LINES-1,COLS-1); the text is printed without any change. (only the background is a bit different because I started colour mode). I am afraid that when the text is copied from the pad to screen, it does not copy the formatting, is that right? If so, is there any way how to accomplish that?
Thanks!
|||-----EDIT------|||
So even when I cahnge the key to something different than zero, it doesn't work. I am printing into the pad with this:
init_pair(3,COLOR_RED,COLOR_CYAN);
attron(COLOR_PAIR(3));
for (i=0;i<str.length();i++){
waddch(p,str[i]);
}
attroff(COLOR_PAIR(3));
and the text after prefresh is displayed as normal.
Color pair 0 is special, because (referring to the manual page) it is always the default foreground and background colors:
Color pair 0 is assumed to be white on black, but is
actually whatever the terminal implements before color
is initialized. It cannot be modified by the application.
There are three components of color pairs which combine to form a cell's color (see manual page):
background character
window attribute set via wattron, etc.
video attributes (including COLOR_PAIR value) passed in the parameter to waddch.
The last two affect the result if a nonzero color-pair is passed; otherwise they do not (and the preceding item on the list is used). These are all window operations. The functions attron/attron apply to stdscr, not to the pad or window p. If those were changed to wattron(p,COLOR_PAIR(3));, etc., the result would be improved.
this excerpt from the man pages for ncurses indicates the problem is using color pair 0.
The init_pair routine changes the definition of a color-pair. It takes three arguments: the number of the color-pair to be changed, the foreground color number, and the background color number. For portable applications:
The value of the first argument must be between 1 and COLOR_PAIRS-1, except that if default colors are used (see use_default_colors) the upper limit is adjusted to allow for extra pairs which use a default color in foreground and/or background. " emphasis mine
I'm using ICSharpCode's AvalonEdit text editor, and I have a custom DocumentColorizingTransformer.
I would like to center certain lines of text inside of ColorizeLine. Is this possible?
I've been able to figure out how to change the line's text in every other way I want (color, italics, underline, etc), but I can't figure out how to change the line's text alignment...
I ended up having to dig into the editor's source for this:
First, in VisualLineTextParagraphProperties.cs, I had to expose the TextAlignment via a new internal property (defaulted to LeftAligned), so I could set it (and, of course, return it from the getter of the public property).
Then, in TextView.cs, in the BuildVisualLine method, I had to test the text of documentLine for the conditions under which I wanted the line centered, then change the paragraphProperties object accordingly.
Do note that I had to make a copy of paragraphProperties - otherwise the centered alignment would bleed over into the next line (because the given paragraphProperties object seems to be reused).
Also note that I could not find a way to use a VisualLineElementGenerator to do this - even though it still looks to me like that would be the place to change something like TextAlignment...
I know it is possible to set MaximumSize to prevent a label from resizing off of a form, but is it possible to also clip the text if necessary?
For example, if you pass the sentence Hello, my name is Dave. to a label, making the width greater than the maximum, I'd like it to show Hello, my name is.... Thanks.
Use the AutoEllipsis property and don't forget to set AutoSize to False
MSDN says:
Gets or sets a value indicating whether the ellipsis character (...)
appears at the right edge of the Label, denoting that the Label text
extends beyond the specified length of the Label.
We need to position a constrained Window (like in this example) relative from the top and the center of the container where it is constrained to. But in the config we only found x and y which would require to calculate the center on each document change.
Isn't there any other way to archive this?
You could use
alignTo() docs
alignTo(element, [position], [offsets], [animate] )
Aligns the element with another element relative to the specified
anchor points. If the other element is the document it aligns it to
the viewport. The position parameter is optional, and can be specified
in any one of the following formats:
Blank: Defaults to aligning the element's top-left corner to the
target's bottom-left corner ("tl-bl"). One anchor (deprecated): The
passed anchor position is used as the target element's anchor point.
The element being aligned will position its top-left corner (tl) to
that point. This method has been deprecated in favor of the newer two
anchor syntax below. Two anchors: If two values from the table below
are passed separated by a dash, the first value is used as the
element's anchor point, and the second value is used as the target's
anchor point. In addition to the anchor points, the position parameter
also supports the "?" character. If "?" is passed at the end of the
position string, the element will attempt to align as specified, but
the position will be adjusted to constrain to the viewport if
necessary. Note that the element being aligned might be swapped to
align to a different position than that specified in order to enforce
the viewport constraints. Following are all of the supported anchor
positions... for more info see the docs
or
anchorTo() docs
anchorTo(element, [position], [offsets], [animate], [monitorScroll], [callback])
Anchors an element to another element and realigns it when the window is resized.
Edit
If you do something of this in a early state the positioning may fail. I would try to add a delay to the alignment by using Ext.Function.createDelayed. Try something between 10-50 as delay.
Example:
Ext.Function.createDelayed(windowRef.anchorTo,50)(Ext.getBody(),'t-t',[-100,0]);
I think Ext.window.Window's showBy method provides the easiest way to do this as it doesn't require the window to be rendered, etc. before it can be applied. A solution that uses the body of the app as the parent container looks like this:
let appBody = Ext.getBody();
Ext.create({
xtype: 'window'
}).showBy(appBody, 't-t', [-100, 0])
See the Ext docs for more info on the showBy method (here are links for Ext 4 and 6)
Let's say that I have a RichTextBox and its contents take up about 3 times the height compared to the visible height. There's no color formatting, I want to highlight keywords. If I use SelectionStart, SelectionLength and SelectionColor, then I have to set SelectionStart back to the caret's original position.
If, for example, I'm looking at the first page and my caret is half-way down the page, but I want a keyword highlighted near the end, when the caret is returned, the RichTextBox will only scroll up far enough for the caret to be on the top visible line, so my visible position has moved.
Is there any way for me to format colors out of view without affecting the view position? Or, is there any way for me to get and set/reset the view position after formatting?
The solution is here:
"Get/Set the ScrollBars’ positions"
http://codebetter.com/blogs/patricksmacchia/archive/2008/07/07/some-richtextbox-tricks.aspx
After I return the caret to its original position with SelectionStart, I can use the code shown on the blog to return the view to its original position.