How to reduce the space occupied by an ipywidget checkbox below 100px? - checkbox

No matter what I do, it seems the smallest width of an ipywidgets.Checkbox is 100px. Anything smaller and the widget doesn't show. It seems a waste of space when grouping with other widgets in an ipywidgets.HBox
import ipywidgets as ipyw
ly = dict(margin='0px', border='solid', max_width='100px')
w = ipyw.Checkbox(value=True, layout=ly)
display(w)
Also the widget is right-justified by default. I didn't figure out how to change the justification.
Has anyone come up with a way to decrease the occupying space?

There is an option "indent". Set it to "False".
from ipywidgets import HBox, Checkbox
checkbox501 = Checkbox(True, description='501', indent=False, layout=Layout(width='50px', height='50px'))
checkbox502 = Checkbox(False, description='502')
HBox([checkbox501, checkbox502], layout=Layout(width='850px', height='80px'))

Related

Codename One container equal width and height

I have an Android project that uses several containers inside a Grid Layout.
The containers' height and width are different and I am looking for a way to make them square.
I have tried it the following way:
int w = container.getWidth();
container.setHeight (w);
This does not not work, because:
a) container.setHeight(i) does not change the height of the container, and
b) container.getWidth() returns 0.
What would be the best approach to obtain square containers?
EDIT
Here is a updated screenshot: left is before, right is after using the code sample.
Size is set by the layout manager. The layout manager effectively invokes setWidth/Height/X/Y to determine the bounds of the components. So any change you make to any one of those methods will be overridden by the layout manager.
To explicitly define the size override calcPreferredSize() and return a uniform size ideally one that is calculated and not hardcoded e.g.:
Container myContainer = new Container(new GridLayout(1, 1)) {
#Override
protected Dimension calcPreferredSize() {
Dimension d = super.calcPreferredSize();
int size = Math.max(d.getWidth(), d.getHeight());
d.setWidth(size);
d.setHeight(size);
return d;
}
};

Codename One: how to get the width in millimeters of a component?

I created an app to calculate the sizes of a multi-image, in order to use them in the Codename One designer.
As you can see in the screenshot below, my app has a slider and I get the width (in millimeters) of it. The problem is that the value of the selected width is incorrect. I tested the app on two Android devices and the measured lengths are different from the ones reported by the app.
You can see the full source code, however the relevant code is the following:
Label value = new Label("Move the cursor on the slider...");
Style thumbStyle = new Style();
thumbStyle.setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE), true);
Slider slider = new Slider();
slider.setMaxValue(1000);
slider.setMinValue(0);
slider.setProgress(20); // Set the starting value
slider.setThumbImage(FontImage.create("|", thumbStyle));
slider.setEditable(true); // to it works as a slider instead of a progress bar
slider.addActionListener(e -> {
Integer valueSelected = slider.getProgress();
Integer sliderWidth = slider.getWidth();
Double inch = sliderWidth.doubleValue() / (slider.getMaxValue() - slider.getMinValue()) * valueSelected / 100.0;
Integer millimeters = Double.valueOf(inch * 25.4).intValue();
value.setText("Value selected: " + millimeters.toString() + " mm");
});
Thank you very much for any help
Millimeter measures aren't accurate. A device can return different values or ratios for the convert method than the value it returns for the density flag.
Unfortunately, Googles test suite to certify a device as "good" doesn't actually cover these things. There isn't much we can do about that.

How to set pagesize in ConvertToXpsDocument(SaveOptions.XpsDefault);

I try to load an excel file and show in xpsdocument viewer by following code
XpsDocument xpsDocument = ef.ConvertToXpsDocument(SaveOptions.XpsDefault);
documentViewer.Tag = xpsDocument;
documentViewer.Document = xpsDocument.GetFixedDocumentSequence();
That works so far. The problem is that during the conversion the pagesize changes. It seems that a 8 by 11 inch pagesize is assumed and the document is streched. Excel document is designed for A4 papersize. That means the width grows and the last column moves to the next page.
How can I influence the paper size and border width for SaveOptions.XpsDefault??
The A4 format is 8.267" x 11.692" so it seems that the assumption is right. Nevertheless, you can change the paper size like the following:
ExcelWorksheet ws = ef.Worksheets.ActiveWorksheet;
ws.PrintOptions.PaperType = PaperType.A4;
However, regarding the content being moved to next page, this will require investigating your Excel file's content.
But in case you're interested you can explicitly specify that the content's width (and/or height) should fit on a single page, like the following:
ws.PrintOptions.FitWorksheetWidthToPages = 1;
Last regarding the borders, you can specify the width by using LineStyle.

Custom heightForRowAtIndexPath (CGSize sizeWithFont) with NSAttributedString iOS

I have a table view where my cells height is defined dynamically depending on the text it is representing.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//getting my text for this cell, the row etc ...
...
//here is the part interesting us
NSAttributedString* theText = [myTextForThisCell objectAtIndex:indexPath.row];
NSInteger labelWidth = self.tableView.bounds.size.width-HORIZONTAL_CELL_PADDING;
CGSize textSize = [theText sizeWithFont:[UIFont systemFontOfSize:customFontSize] constrainedToSize:CGSizeMake(labelWidth, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
return textSize.height+VERTICAL_CELL_PADDING;
}
Ok so now my problem.
The tableview is the result of a search action which after scanning a plist file shows the lines containing a given string.
Up to now that was it. But now with iOS 6 and NSAttributedString allowing easily to bold part of strings I decided to bold the search word.
It is working, it bolds the words I want but now I am no more able to calculate the cell height as sizeWithFont ask for a NSString. And as bolding takes a wider width I cannot simply calculate the cell height with the string without attributes.
I am simply stuck here.
Anyone can help me ?
In fact I simply had to read apple documentation of NSAttributedText.
In my case I have to replace the last two lines of code by
CGRect rectSize = [theText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin context:NULL];
return rectSize.size.height+VERTICAL_CELL_PADDING;
FOLLOW UP iOS 7
I have been struggling making this work in iOS7 with attributed text.
Apple documentation says
In iOS 7 and later, this method returns fractional sizes (in the size
component of the returned CGRect); to use a returned size to size
views, you must use raise its value to the nearest higher integer
using the ceil function.
Which way obviously not working for me ! For me the solution was to add +1 to the ceil of height. This is probably a bug from Apple, but for me now everything works as in iOS6.
CGRect rectSize = [theAttributedText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin context:NULL];
return ceil(rectSize.size.height) + 1 + VERTICAL_CELL_PADDING;

extjs - set grid column's width wide enough to display text in it

I am loading a grid dynamically in extjs. As you can see below the column "Created" is not wide enough to display whole text in it. I want to set every column's width such that it display's its text completely.
Is this possible to do? Any suggestion?
Thanks for help.
use parameter width: ... with your column config. As simple as this. I do not see your code so I am guessing.
However it look like you have more vertical space -> maybe break date in 2 lines (using template) would be solution, or you can have special css class just for this cell with smaller letter in order to fit.
Edit:
in your case it could be combination of defaultWith in ColumnModel (at least get 120 to fit your date, if more columns grid would adjust) and setColumnWith() dynamically based on length of data and number of columns - logic is up to you
Thanks bensiu, I implemented the login. However, I cannot say that this is the ideal solution but it solves my purpose.
First, i navigate through data and find the longest string in that column (including header name of that column).
// Store the longest string for each column in columns[col].maxstring
// Define a hidden label
{
xtype: 'label',
id: 'lblTab',
hidden: true
}
var lblTab = Ext.getCmp('lblTab');
var hiddenField = Ext.util.TextMetrics.createInstance(Ext.getCmp('lblTab').el);
var widthValue = 0;
// Iterate through each columns to set its maximum width
for(var col in columns) {
// find width of string
widthValue = hiddenField.getWidth(columns[col].maxstring);
// set column width
colModel.setColumnWidth(columns[col].index, widthValue + 20, false);
}
I hope this helps somebody.

Resources