Align label widget to left of EventBox - gtk

I have been trying to align an entire label along with text to the left of an GtkEventBox where I placed it. However, I cannot do so. I tried to align the text on the label, because I do not know of any functions that would align the label itself to the left of my event box. The event box is placed in the table in this code:
label1 = gtk_label_new(res);
gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (label1), TRUE);
gtk_label_set_single_line_mode(GTK_LABEL(label1),TRUE);
//align = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
//gtk_container_add(GTK_CONTAINER(align), label1);
//gtk_table_attach(GTK_TABLE(table), align, 0, 10, 2, 3, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 20, 10);
embedLabel= gtk_event_box_new();
gtk_container_add( GTK_CONTAINER(embedLabel), label1 );
gtk_container_set_resize_mode(GTK_CONTAINER(embedLabel), FALSE);
gtk_table_attach(GTK_TABLE(table), embedLabel, 0, 10, 2, 3, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 20, 20);

Maybe try to set the alignment within the available space?
gtk_misc_set_alignment(GTK_MISC(label1), 0, .5);

Related

highcharts gauge chart height taking extra space

I want the gauge chart inside a 'rectangular' div, with height=300px and width =400px
If I setup the chart height=300, width=400,the resulting chart is not taking all the available height&width (see image), in fact it looks as if it is taking the necessary space for a circle instead of a semi-circle.
I set up height=300, width=400 for all internal pies, as well as these parameters in 'chart', with no improvements
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0,
plotBorderWidth: null,
margin: [0, 0, 0, 0],
spacing: [0, 0, 0, 0]
jsfiddle available here https://jsfiddle.net/perikut/0woz42vt/248/
thanks in advance
You are right, the space is adapted for a circle - please check this example: https://jsfiddle.net/BlackLabel/2jrch4xn/
You need to position the chart as you want by center property:
pane: {
...,
center: ['50%', '100%']
},
plotOptions: {
series: {
...,
center: ['50%', '115%']
},
...
}
Live demo: https://jsfiddle.net/BlackLabel/4m2t6p35/1/

How to get string value centered above bars in bar chart

I am having trouble aligning the text above the correct bars in the following bar graph, I can't figure out where it's going wrong?
CODE:
bar(two_weeks,zAxis);
text(1:length(two_weeks),zAxis,num2str(zAxis),'vert','bottom','horiz','center');
box off
ylabel('Z Axis')
BAR CHART:
The arrows were added post production and are showing where they should be aligned to. Also note that I was too lazy to draw all of the arrows.
DATA:
two_weeks =
1×14 datetime array
[ 21-Nov-2018, 22-Nov-2018, 23-Nov-2018, 24-Nov-2018, 25-Nov-2018, 26-Nov-2018, 27-Nov-2018, ...
28-Nov-2018, 29-Nov-2018, 30-Nov-2018, 01-Dec-2018, 02-Dec-2018, 03-Dec-2018, 04-Dec-2018 ]
zAxis =
[ 5, 12, 1, 7, 13, 24, 2, 27, 62, 0, 3, 17, 74, 4 ].'
Your x axis is specified using a datetime array. What you're then using is guesswork to align indices (1:length(two_weeks)) for the x coordinates of your text items.
Instead, simply use the same datetime array for the position of the text!
bar( two_weeks, zAxis );
text( two_weeks, zAxis, arrayfun(#num2str,zAxis,'uni',0) );
As you did in the question, we want to set 'VerticalAlignment' to 'bottom' and 'HorizontalAlignment' to 'center' to neaten things up above the bars:
bar( two_weeks, zAxis );
text( two_weeks, zAxis, arrayfun(#num2str,zAxis,'uni',0), ...
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center' );
Output:

Pyglet: why does the text in my example become fuzzy when I resize the window?

In the following toy example, I have a text layout in a resize-able window. When the window is re-sized, the text becomes fuzzy for some resolutions (give it a try). Why is that?
import pyglet
width, height = 500, 500
window = pyglet.window.Window(width, height, resizable=True)
batch = pyglet.graphics.Batch()
document = pyglet.text.document.FormattedDocument()
document.insert_text(0, 'Hello world!', attributes=dict(font_name='Arial', font_size=12, color=(255, 255, 255, 255)))
layout = pyglet.text.layout.IncrementalTextLayout(document, width, height, multiline=True, batch=batch)
# for drawing graphics
pyglet.gl.glLineWidth(3)
outline = batch.add(4, pyglet.gl.GL_LINE_LOOP, None, ('v2f', (0, 0, width, 0, width, height, 0, height)), ('c4B', (255, 0, 0, 0)*4))
#window.event
def on_resize(width, height):
document.delete_text(0, len(document.text))
document.insert_text(0, "Layout has been resized to {}x{}".format(0.9*width, 0.9*height))
layout.width = 0.9*width
layout.height = 0.9*height
layout.x = (width - layout.width)*0.5
layout.y = (height - layout.height)*0.5
outline.vertices = (layout.x, layout.y, layout.width + layout.x, layout.y, layout.width + layout.x, layout.height + layout.y, layout.x, layout.height + layout.y)
#window.event
def on_draw():
window.clear()
batch.draw()
pyglet.app.run()
Things start to become wonky because the layout is being given decimal width and height. Fixing that removes the fuzzy text issues:
import pyglet
width, height = 500, 500
window = pyglet.window.Window(width, height, resizable=True)
batch = pyglet.graphics.Batch()
document = pyglet.text.document.FormattedDocument()
document.insert_text(0, 'Hello world!', attributes=dict(font_name='Arial', font_size=12, color=(255, 255, 255, 255)))
layout = pyglet.text.layout.IncrementalTextLayout(document, width, height, multiline=True, batch=batch)
# for drawing graphics
pyglet.gl.glLineWidth(3)
outline = batch.add(4, pyglet.gl.GL_LINE_LOOP, None, ('v2f', (0, 0, width, 0, width, height, 0, height)), ('c4B', (255, 0, 0, 0)*4))
#window.event
def on_resize(width, height):
width, height = int(width), int(height)
window.set_size(width, height)
layout_width, layout_height = int(0.9*width), int(0.9*height)
document.delete_text(0, len(document.text))
document.insert_text(0, "Layout has been resized to {}x{}".format(layout_width, layout_height))
layout.width, layout.height = layout_width, layout_height
layout.x = int((width - layout_width)*0.5)
layout.y = int((height - layout_height)*0.5)
outline.vertices = (layout.x, layout.y, layout.width + layout.x, layout.y, layout.width + layout.x, layout.height + layout.y, layout.x, layout.height + layout.y)
#window.event
def on_draw():
window.clear()
batch.draw()
pyglet.app.run()
I had the same problem and I made it work like this:
You will need a wrapper class which will have the on_resize event handler. Also it needs the parent window.
class Label(pyglet.text.Label):
def __init__(self, window,**kwargs):
self.window = window
self.window.push_handlers(self)
self.init_settings = dict()
for k,v in kwargs.items():
if callable(v):
kwargs[k] = v(self.window)
self.init_settings[k] = v
super().__init__(**kwargs)
def on_resize(self, width, height):
for k,v in self.init_settings.items():
setattr(self,k,v(self.window))
Usage:
Each property you need to update on resizing the window will be a lambda function. Here you should write the initial values of the label with the initial window sizes.
class WindowSubclass(pyglet.window.Window):
def __init__(self,*args,**kwargs):
self.initial_size = self.width,self.height
self.label = Label(window=self,
text='PAUSED',
multiline=False,
font_name='Times New Roman',
bold=True,
font_size=lambda win:24*win.height/win.initial_height,
width=lambda win:win.width/4,
x=lambda win:win.width/2,
y=lambda win:win.height/2,
color=(255, 255, 255, 255),
anchor_x='center', anchor_y='center')

iTextSharp watermark multiline text

I have seen answers to question of how to add text watermark to an existing PDF document using iTextSharp. My question is how can we do multiline text. Is there a way to do this without having multiple PdfContentByte defined. I have tried to insert a newline character with no luck.
Here is the code from the internet. I just added
pdfData.ShowTextAligned(Element.ALIGN_CENTER, editDate, (pageRectangle.Width / 2) + 100, (pageRectangle.Height / 2) - 100, 45);
as the second line to get the second line of the watermark, it works but uses same parameters (color, size, etc.) as the first.
iTextSharp.text.Rectangle pageRectangle = PDFreader.GetPageSizeWithRotation(1);
//pdfcontentbyte object contains graphics and text content of page returned by pdfstamper
PdfContentByte pdfData = stamper.GetOverContent(1);
//create fontsize for watermark
pdfData.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 120);
//create new graphics state and assign opacity
PdfGState graphicsState = new PdfGState();
graphicsState.FillOpacity = 0.2F;
//set graphics state to pdfcontentbyte
pdfData.SetGState(graphicsState);
//set color of watermark
pdfData.SetColorFill(iTextSharp.text.Color.BLUE);
//indicates start of writing of text
pdfData.BeginText();
//show text as per position and rotation
pdfData.ShowTextAligned(Element.ALIGN_CENTER, "E D I T E D" , (pageRectangle.Width / 2), (pageRectangle.Height / 2), 45);
pdfData.ShowTextAligned(Element.ALIGN_CENTER, editDate, (pageRectangle.Width / 2) + 100, (pageRectangle.Height / 2) - 100, 45);
//call endText to invalid font set
pdfData.EndText();

GWT Flex Table Problem

I am creating a flex table dynamically with the following code.
for (int CurrentRow=1;CurrentRow<2;CurrentRow++)
{
Label lblGettingName = new Label("Getting Name...");
View.getMainFlex().setWidget(CurrentRow, 0, lblGettingName);
Button btnViewDetails = new Button("View Details");
View.getMainFlex().setWidget(CurrentRow, 1, btnViewDetails);
Label lblGettingBid = new Label("Getting Bid...");
View.getMainFlex().setWidget(CurrentRow, 2, lblGettingBid);
View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 2, "BackNormalNotBold");
Label lblGettingBidDesription = new Label("Getting Bid Desription...");
lblGettingBidDesription.setStyleName("BidDesc");
View.getMainFlex().setWidget(CurrentRow, 3, lblGettingBidDesription);
View.getMainFlex().getCellFormatter().setWidth(CurrentRow, 3, "40");
View.getMainFlex().getFlexCellFormatter().setStylePrimaryName(CurrentRow, 3, ".BidDesc");
Label lblCalculating = new Label("Calculating..");
Label lblCalculatingTime = new Label("Calculating Time...");
View.getMainFlex().setWidget(CurrentRow, 4, lblCalculatingTime);
View.getMainFlex().getFlexCellFormatter().setStyleName(1,4, "BackNormalNotBold");
TextBox textBox = new TextBox();
View.getMainFlex().setWidget(CurrentRow+1, 3, textBox);
View.getMainFlex().getCellFormatter().setWidth(CurrentRow+1, 3, "40");
View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 0, "BackNormalNotBold");
View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 1, "BackNormalNotBold");
View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 2, "BackNormalNotBold");
View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow+1, 3, "BackNormalNotBold");
View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 4, 3);
View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 2, 3);
View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 1, 3);
View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 0, 3);
View.getMainFlex().getFlexCellFormatter().setColSpan(CurrentRow+1, 3, 2);
View.getMainFlex().getFlexCellFormatter().setColSpan(CurrentRow, 3, 2);
View.getMainFlex().getFlexCellFormatter().setColSpan(CurrentRow-1, 3, 2);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 1, HasHorizontalAlignment.ALIGN_CENTER);
View.getMainFlex().getCellFormatter().setVerticalAlignment(CurrentRow, 1, HasVerticalAlignment.ALIGN_MIDDLE);
View.getMainFlex().getCellFormatter().setVerticalAlignment(CurrentRow, 0, HasVerticalAlignment.ALIGN_MIDDLE);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 0, HasHorizontalAlignment.ALIGN_CENTER);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 2, HasHorizontalAlignment.ALIGN_CENTER);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow+1, 3, HasHorizontalAlignment.ALIGN_CENTER);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 3, HasHorizontalAlignment.ALIGN_CENTER);
Button btnPlaceBid = new Button("Bid!");
View.getMainFlex().setWidget(CurrentRow+2, 3, btnPlaceBid);
View.getMainFlex().getCellFormatter().setWidth(CurrentRow+2, 3, "20");
btnPlaceBid.setSize("66px", "26px");
ToggleButton tglbtnAutomate = new ToggleButton("Automate");
View.getMainFlex().setWidget(3, 4, tglbtnAutomate);
View.getMainFlex().getCellFormatter().setWidth(3, 4, "20");
tglbtnAutomate.getDownHoveringFace().setText("TurnOFF");
tglbtnAutomate.getUpHoveringFace().setText("TurnON");
tglbtnAutomate.getDownDisabledFace().setText("Enable");
tglbtnAutomate.setHTML("Auto:OFF");
tglbtnAutomate.getUpFace().setHTML("Auto:OFF");
tglbtnAutomate.getDownFace().setHTML("Auto:ON");
tglbtnAutomate.setSize("54px", "18px");
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow+2, 3, HasHorizontalAlignment.ALIGN_RIGHT);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow-1, 4, HasHorizontalAlignment.ALIGN_CENTER);
View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 4, HasHorizontalAlignment.ALIGN_CENTER);
}
FlexTableHelper.fixRowSpan(View.getMainFlex());
When the loop executes only once, the correct layout is generated but when i try to create more than 1 row, the layout degerate
Most likely problems with flextable are caused by setRowSpan/setColSpan methods which can easily wreak havoc in layout. Instead of using those methods you can create composite widget/Html and place it in cells so Flextable will have less amount of rows/columns.
FlexTable uses old element attributes of td like width, height, align etc.
It is not yet adapted to use CSS instead even in the newest release. IE11 does no longer support <td align="..."> at all, for example.