BlackBerry - Resize the width of horizontal manager - user-interface

Is it possible to resize the width of horizontal manager. I want to create two buttons in horizontal manag, set the background border. I am using the following code for that. It is working fine. But as there are only two buttons and doesn't occupy the entire screen of 320 width, setting border is happening only for those two buttons background. So i could see the white space apart from the horizontal width in forward and backward spaces. So i want to create a Horizontal manager itself with 320 width, so that setting border color will show for the entire width. Is it possible to resize the width of horizontal manager?
XYEdges borderColor = new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK);
XYEdges noPadding = new XYEdges(2, 2, 2, 2);
HorizontalFieldManager hzBtnFldManager = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
createButton = new CustomControl("Create", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER, 83, 15);
cancelButton = new CustomControl("Cancel", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER, 83, 15);
hzBtnFldManager.add(createButton);
hzBtnFldManager.add(cancelButton);
Border btnBarPaddingBorder = BorderFactory.createSimpleBorder(noPadding, borderColor, Border.STYLE_SOLID);
hzBtnFldManager.setBorder(btnBarPaddingBorder);
hzBtnFldManager.setBackground(BackgroundFactory.createSolidBackground(Color.GRAY));
this.setStatus(hzBtnFldManager);

Maybe try using the Field.USE_ALL_WIDTH style on the HorizontalFieldManager?

Related

iText 7 - How to fill a canvas rectangle with a transparent color

In iText 7.1.9 I am taking a pdf created programmatically (not via iText) and need to apply a transparent rectangle along the left side and bottom to ensure the no content exists within a predefined clear zone (for print).
The below code places the yellow rectangles correctly but the desired result is the for the yellow fill to be semi-transparent or not 100% opaque so that visual inspection will show the content that that intersects with the rectangle instead of the rectangle clipping the content.
var page = pdf.GetPage(1);
PdfCanvas canvas = new PdfCanvas(page);
canvas.SaveState();
canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.YELLOW);
var pageHeight = page.GetPageSize().GetHeight();
var pageWidth = page.GetPageSize().GetWidth();
// left side
canvas.Rectangle(0, 0, 15, pageHeight);
// bottom
canvas.Rectangle(0, 0, pageWidth, 15);
canvas.Fill();
canvas.RestoreState();
I attempted to use a TransparentColor but canvas.SetFillColor won't accept a TransparentColor, are there any other options?
When we speak about low-level content stream instructions, color itself and transparency levels are specified separately in PDF syntax. The TransparentColor class that you speak about was designed to simplify lives of users who are less familiar with nuances of PDF syntax, but it it a higher-level class that you can use e.g. in layout module, and in your case you operate with the document on quite low level.
Long story short, to set color transparency you only need one additional line next to setting the color itself:
canvas.SetExtGState(new PdfExtGState().SetFillOpacity(0.5f));
So the code becomes:
var page = pdf.GetPage(1);
PdfCanvas canvas = new PdfCanvas(page);
canvas.SaveState();
canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.YELLOW);
canvas.SetExtGState(new PdfExtGState().SetFillOpacity(0.5f));
var pageHeight = page.GetPageSize().GetHeight();
var pageWidth = page.GetPageSize().GetWidth();
// left side
canvas.Rectangle(0, 0, 15, pageHeight);
// bottom
canvas.Rectangle(0, 0, pageWidth, 15);
canvas.Fill();
canvas.RestoreState();

Sub 10 height request layouts/views not allowed

I'm trying to add line dividers between views. However, there is a forced margin on every element I try (Image, BoxView, Frame, Label). I set the margin to be 0, the HeightRequest is always 3, but as you can see the view bounds expand past the actual view. Is there a specific view I'm supposed to be using? I just want the gray line and nothing more.
var line2 = new Frame
{
WidthRequest = (App.ScreenDpWidth / 2),
MinimumHeightRequest = 3,
HeightRequest = 3,
BackgroundColor = Color.FromHex("#229EBB"),
Margin = new Thickness(0, 0)
};
I assume you are layouting your elements either in a Grid or a StackLayout.
By default, the StackLayout.Spacing, Grid.RowSpacing and Grid.ColumnSpacing properties are set to 6d.
Without more information, I think that's what you're seeing in your code. Change those values to 0d.
Also, if you only want a gray line, you can use a BoxView which will draw a gray box, and set it's Height to 1d.

Xamarin Forms Stacklayout StackOrientation.Horizontal

When i set StackOrientation.Horizontal for stacklayout and setting 5 labels it displays properly.
But when the number of labels count is increased labels text size reduced and all labels are aligned for available width.
How to display full text for all labels also move label to next line if the labels count exceeds?
Use WrapLayout instead:
var layout = new WrapLayout {
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.Fill,
Padding = new Thickness (0, padding, 0, padding)
};
layout.Children.Add (item);
Result:
StackLayout with Horizontal orientation will only use "one line".
For that case you should use a GridLayout or WrapLayout (From Xlabs).
In alternative you could use a StackLayout with Horizontal orientation and each Child is a StackLayout with Vertical orientation.
Xamarin 3.0 introduced FlexLayout for exactly this use-case. It's based on CSS Flexboxes.

JavaFX: Navigating through a Canvas within a ScrollPane of equal dimensions

I created a 10 000 x 10 000 pixel canvas, placed it inside a scroll pane with dimensions 300 x 300. This was implemented fine. The whole grid was drawn and I could scroll through it.
I'm tasked to instead create the same functionality, except with a 300 x 300 canvas instead. As speed is important in this program, I'm told this would work much faster.
My problem is that when I do this, I lose access to the scroll bars on the bottom and right of the scroll pane. How do I regain access to those scroll bars, to physically scroll?
The canvas is updating at 60 steps per second. What's being drawn is a square grid from the information in a 2D array.
Since the the viewport handling will be done by the drawing logic, it's rather easy to create a "ScrollPane" yourself using a GridPane:
public static ScrollBar createScrollBar(Orientation orientation, double fullSize, double canvasSize) {
ScrollBar sb = new ScrollBar();
sb.setOrientation(orientation);
sb.setMax(fullSize - canvasSize);
sb.setVisibleAmount(canvasSize);
return sb;
}
Canvas canvas = new Canvas();
canvas.setHeight(300);
canvas.setWidth(300);
ScrollBar vScroll = createScrollBar(Orientation.VERTICAL, 10000, 300);
ScrollBar hScroll = createScrollBar(Orientation.HORIZONTAL, 10000, 300);
GridPane scrollPane = new GridPane();
scrollPane.addColumn(0, canvas, hScroll);
scrollPane.add(vScroll, 1, 0);

How to set no border when drawing background colored rectange?

Is there a way to set no border when drawing background-color filled rectangle? Or make border color match background-color filled rectange?
PrimitiveComposer primitiveComposer = new PrimitiveComposer(page);
{
BlockComposer blockComposer = new BlockComposer(primitiveComposer);
primitiveComposer.SetLineWidth(0.0f);
primitiveComposer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.DarkGray));
primitiveComposer.DrawRectangle(new RectangleF(_boxMarginX, _boxMarginY, (page.Size.Width - (_boxMarginX * 2)), 205f), 0f);
primitiveComposer.FillStroke();
}
You use
primitiveComposer.FillStroke();
which is the command to fill and stroke a path. As you don't want the borders, i.e. you don't want to stroke, use
primitiveComposer.Fill();
instead.
By the way,
primitiveComposer.SetLineWidth(0.0f);
The PDF specification defines a line width of 0 to mean the smallest line the target device can render.

Resources