How to make Gtk.Box fill all the available space? - gtk3

The layout looks like on the image below: two boxes encapsulated in vertical box with a specified width. Single big box is positioned on the right. The big box should fill all the available space, however it is not happening despite Gtk.Align.FILL property set.
Please ignore the "Utilization" box.
cpu_utilization_chart = new Chart (cpu.core_list.size);
cpu_frequency_chart = new Chart (1);
cpu_temperature_chart = new Chart (1);
var smol_charts_container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
smol_charts_container.add (cpu_frequency_chart);
smol_charts_container.add (cpu_temperature_chart);
var big_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
big_box.add (smol_charts_container);
big_box.add (cpu_utilization_chart);
attach (title_grid, 0, 0, 1, 1);
attach (grid_usage_labels(), 0, 1, 1, 1);
attach (big_box, 0, 1, 1, 1);

To fix this I ditched Gtk.Grid and replaced it with a Gtk.Box.
pack_end (cpu_utilization_chart, true, true, 0);
pack_end(smol_charts_container, false, false, 0);
And also did smol_charts_container.hexpand = false;

Related

Not able to create UI Controls at runtime

I am trying to create a screen on which I have a Panel. The main Panel has another Panel and this Panel has a Grid which has four HBoxes, and each HBox finally has a Button.
onInit:function(){
oMainPanel.removeAllContent();
var oHbox1 = new sap.m.HBox(jQuery.sap.uid());
var oHbox2 = new sap.m.HBox(jQuery.sap.uid());
var oHbox3 = new sap.m.HBox(jQuery.sap.uid());
var oHbox4 = new sap.m.HBox(jQuery.sap.uid());
var oPanel ;
var oGrid;
for (var i = 0; i < 4; i++) {
oGrid = new sap.ui.layout.Grid(jQuery.sap.uid(),{
hSpacing: 1,
vSpacing: 1,
content: [oHbox1,oHbox2,oHbox3,oHbox4]
});
oPanel = new sap.m.Panel(jQuery.sap.uid(),{
headerText: "Some Text",
expandable: true,
expanded: true,
width:"100%",
content:[oGrid]
});
jQuery.sap.delayedCall(100, this, function() {
});
oMainPanel.addContent(oPanel);
}
I can see the content in each HBox, but only for the last Panel. I think these are being overlapped. How can I display the content of all the HBoxes in all Panels?.
You are trying to use the same instances of HBox as content of different Grids. You need to create a new instance for each Panel.
Try doing something like:
oGrid = new sap.ui.layout.Grid(jQuery.sap.uid(),{
hSpacing: 1,
vSpacing: 1,
content: [new sap.m.HBox(), new sap.m.HBox(),
new sap.m.HBox(), new sap.m.HBox()]
or initialize your variables (oHbox1, oHbox2, etc) inside the loop
I solved this problem by using the forEach instead of for loop.

Use FillLayout with Browser in SWT

I have a view that consists of a heading and a browser. I want the browser to fill my view. This is how it should look:
I have tried out different combinations.
c = new Composite(parent, SWT.NONE);
c.setLayout(new RowLayout(SWT.VERTICAL));
Label l = new Label(c, SWT.NONE);
l.setBackground(color);
l.setText("----------------------Heading--------------------------------");
l.setFont(new Font(null, new FontData(Constants.FONT, 12, SWT.BOLD)));
Composite wrapper = new Composite(c, SWT.NONE);
wrapper.setBackground(new Color(null, 0, 0, 0));
wrapper.setLayout(new FillLayout(SWT.VERTICAL));
browser = new Browser(wrapper, SWT.WRAP);
browser.setBackground(color);
produces:
Setting a FillLayout to c does not work either. By doing so both, heading and browser, share the view's size and have an equal size.
c = new Composite(parent, SWT.NONE);
c.setLayout(new FillLayout(SWT.VERTICAL));
Label l = new Label(c, SWT.NONE);
l.setBackground(color);
l.setText("----------------------Heading--------------------------------");
l.setFont(new Font(null, new FontData(Constants.FONT, 12, SWT.BOLD)));
browser = new Browser(c, SWT.WRAP);
browser.setBackground(color);
produces:
I have also tried the following:
composite with filllayout
-> composite with gridlayout
->composite with rowLayout (fixed height, grab right)
->composite with rowLayout
-> composite with fillLayout
-> composite with browser
Assuming that the header and browser have the same parent, you could use a GridLayout like this:
parent.setLayout( new GridLayout( 1, false ) );
label.setLayoutData( new GridData( SWT.FILL, SWT.TOP, true, false ) );
browser.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
Even though a one-cell-grid isn't really what a GridLayout is meant for, it should do the trick. The layout data advise the label to align at the top and use all horizontal space and the browser to use the horizontal and vertical space

Alignment in Flex table

How can I get the flex table (flex3) to align at the top in this Ui?
function doGet(e) {
var app = UiApp.createApplication();
var flex1 = app.createFlexTable().setBorderWidth(1);
var flex2 = app.createFlexTable().setBorderWidth(1).setWidget(0, 0, app.createLabel('flex2'))
.setWidget(1, 0, app.createTextArea().setHeight(400).setText('Text area in flex2'));
var flex3 = app.createFlexTable().setBorderWidth(1).setWidget(0, 0, app.createLabel('flex3'));
flex1.setWidget(0, 0, flex2).setWidget(0, 1, flex3);
app.add(flex1);
return app;
}
Was expecting...
var flex1 = app.createFlexTable().setBorderWidth(1).setStyleAttribute('vertical-align', 'top');
or
var flex1 = app.createFlexTable().setBorderWidth(1).setColumnStyleAttribute(1, 'vertical-align', 'top');
to work.
Also, using a flow panel instead of a flex for the root didn't work as expected either. That stacked the 2 flex vertically and not left to right.
Adding this line towards the bottom did the trick for me -
flex1.setStyleAttribute(0, 1, 'vertical-align', 'top');
Not sure why the global set style or set column style didn't work. However, setting it on a specific row/column seem to work. Let me know.
This might have to end up on the Issue Tracker, please check there and log an issue.

How I can remove a body elasticity? (andengine)

My character's body keeps bouncing.
body = PhysicsFactory.createCircleBody(mPhysicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(1, 1, 1));
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, true));
How can I prevent this?
Replace with: PhysicsFactory.createFixtureDef(1, 0, 0), so that elasticity is 0.

How can I remove the default top margin on a pdf document with itextsharp?

I´m trying to get my pdf document to start at (0,0) however it seems that the document object has a default top margin which I cannot set to 0.
Is there a way to do this?
My code looks like the following
using (MemoryStream memoria = new MemoryStream())
{
Document pdf = new Document(new Rectangle(288, 144));
try
{
PdfWriter writer = PdfWriter.GetInstance(pdf, memoria);
pdf.Open();
pdf.SetMargins(0, 0, 0, 0);
PdfPTable tPrincipal = new PdfPTable(2);
tPrincipal .WidthPercentage = 100;
tPrincipal .DefaultCell.Border = 0;
tPrincipal .TotalWidth = 288f;
tPrincipal .LockedWidth = true;
....
I just can´t get to set the top margin to 0. It just doesnt care about my setting to (0,0,0,0) and leaves a top margin (around 50f).
You'll need to set your margins in your Document constructor, like this:
Document pdf = new Document(new Rectangle(288f, 144f), 0, 0, 0, 0);
You won't need to use the Document.SetMargins() method. I believe you'd use SetMargins()after you create a new page by calling Document.NewPage().
Option 1:
Document doc = new Document();
doc.setMargins(0 , 0 , 0 , 0);
Option 2:
Document pdf = new Document(new Rectangle(595 , 842 ), 0, 0, 0, 0);
Where, 595x842 is A4 size paper.
I did like below where “…/XYZ.pdf” is the path to generated pdf file download path.
PdfDocument pdfDoc = new PdfDocument(new com.itextpdf.kernel.pdf.PdfWriter(“…/XYZ.pdf”));
Document doc = new Document(pdfDoc);
doc.setMargins(0f , 0f , 0f , 0f);