Normally to change the characteristics (Font, color) of a Section in Plain mode we have to create an entire view from scratch.
In cases where a simple change is needed in color/size, is there an easier way to do this?
Here's what I tend to do:
var header = new UILabel(new RectangleF(0, 0, 320, 25)){
Font = UIFont.BoldSystemFontOfSize (22),
TextColor = UIColor.White,
BackgroundColor = SomethingPretty,
Text = "Something"
};
Section secGroup = new Section(header);
This appears to be the simplest way:
var header = new UILabel(new RectangleF(0, 0, 320, 25)){
Font = UIFont.BoldSystemFontOfSize (22),
TextColor = UIColor.White,
BackgroundColor = SomethingPretty,
Text = "Something"
};
Section secGroup = new Section(header);
Related
In fabric.js, how do you adjust stroke thickness for the object selection box and control handles?
There's a bunch of customization options available, however it isn't clear on how you can customized stroke thickness. Is it possible, perhaps through an indirect way?
Note: The properties selectionColor, selectionBorderColor, selectionLineWidth are misleading... they have to do with the temporary selection box that appears when attempting to do a fresh drag-select across the canvas. Once your selection is made, it disappears and then you see the persistent object selection box with control handles (the thing I'm trying to customize).
See links:
http://fabricjs.com/customization
http://fabricjs.com/controls-customization
Ok here's a 2-part solution:
https://codepen.io/MarsAndBack/pen/bGExXzd
For the selection box stroke thickness:
Use fabric.Object.prototype.set to customize any object selection globally. Also, borderScaleFactor is documented, but not included in the fabric.js customization demos:
fabric.Object.prototype.set({
borderScaleFactor: 6
})
For the control handle stroke thickness:
Here we override differently, and actually draw new elements using standard HTML5 canvas properties. Through this method you could also target specific control handles and even use image icons.
fabric.Object.prototype._drawControl = controlHandles
fabric.Object.prototype.cornerSize = 20
function controlHandles (control, ctx, methodName, left, top) {
if (!this.isControlVisible(control)) {
return
}
var size = this.cornerSize
// Note 1: These are standard HTML5 canvas properties, not fabric.js.
// Note 2: Order matters, for instance putting stroke() before strokeStyle may result in undesired effects.
ctx.beginPath()
ctx.arc(left + size / 2, top + size / 2, size / 2, 0, 2 * Math.PI, false);
ctx.fillStyle = "pink"
ctx.fill()
ctx.lineWidth = 4 // This is the stroke thickness
ctx.strokeStyle = "red"
ctx.stroke()
}
SO code snippet:
const canvas = new fabric.Canvas("myCanvas")
canvas.backgroundColor="#222222"
this.box = new fabric.Rect ({
width: 240,
height: 100,
fill: '#fff28a',
myType: "box"
})
canvas.add(this.box)
this.box.center()
// Selection box border properties
// ----------------------------------------
fabric.Object.prototype.set({
borderColor: "white",
borderScaleFactor: 6
})
// Control handle properties
// ----------------------------------------
fabric.Object.prototype._drawControl = controlHandles
fabric.Object.prototype.cornerSize = 20
function controlHandles (control, ctx, methodName, left, top) {
if (!this.isControlVisible(control)) {
return
}
var size = this.cornerSize
// Note 1: These are standard HTML5 canvas properties, not fabric.js.
// Note 2: Order matters, for instance putting stroke() before strokeStyle may result in undesired effects.
ctx.beginPath()
ctx.arc(left + size/2, top + size/2, size/2, 0, 2 * Math.PI, false);
ctx.fillStyle = "pink"
ctx.fill()
ctx.lineWidth = 4
ctx.strokeStyle = "red"
ctx.stroke()
}
<script src="https://pagecdn.io/lib/fabric/3.6.3/fabric.min.js"></script>
<canvas id="myCanvas" width="700" height="400"></canvas>
I have this code to try to set the background color of a cell (among other things):
private static readonly Color CONTRACT_ITEM_COLOR = Color.FromArgb(255, 255, 204);
. . .
cell = pivotTableSheet.Cells[4, 0];
cell.PutValue(AnnualContractProductsLabel);
style = cell.GetStyle();
style.HorizontalAlignment = TextAlignmentType.Center;
style.VerticalAlignment = TextAlignmentType.Center;
style.Font.IsBold = true;
pivotTableSheet.Cells.SetRowHeight(4, 25);
style.BackgroundColor = CONTRACT_ITEM_COLOR;
pivotTableSheet.Cells[4, 0].SetStyle(style);
The setting of horizontal and vertical alignment works, as does bold and height - everything but color:
What is yet needed? I have even tried setting ForegroundColor as well as Background colors, to :
style.ForegroundColor = Color.Red;
style.BackgroundColor = Color.Blue;
...but neither does anything - the cell still looks exactly the same as the screenshot above.
Please change your code segment to (see the highlighted lines):
e.g
Sample code:
. . .
cell = pivotTableSheet.Cells[4, 0];
cell.PutValue(AnnualContractProductsLabel);
style = cell.GetStyle();
style.HorizontalAlignment = TextAlignmentType.Center;
style.VerticalAlignment = TextAlignmentType.Center;
style.Font.IsBold = true;
pivotTableSheet.Cells.SetRowHeight(4, 25);
**style.ForegroundColor = CONTRACT_ITEM_COLOR;
style.Pattern = BackgroundType.Solid;**
pivotTableSheet.Cells[4, 0].SetStyle(style);
..........
it should work fine.
I am working as Support developer/ Evangelist at Aspose.
Sometimes setting background works, sometimes it doesn't. Aspose is full of bugs -- ClosedXML is much more reliable but harder to use. Wish I would not have spent the money on a product that was developed by third party in third world county.
var cells = worksheet.Cells; //get cells collection from active worksheet <br>
var srcCells = workbook.Worksheets[1].Cells;<br>
for (int i = 0; i<rowCount; i++)<br>
{<br>
var srcStyle = srcCells[i, 0].GetStyle();<br>
var destStyle = cells[i, 0].GetStyle();<br>
destStyle.Pattern = BackgroundType.Solid;<br>
destStyle.ForegroundColor = Color.FromArgb(srcStyle.ForegroundArgbColor);<br>
cells[i, 0].SetStyle(destStyle);<br>
}<br>
Above Code does not work. srcStyle Foreground color argb is 170,215,255.
Debugging code destStyle ForegroundColor is set to 170,215,255 but when saved as xlsx all the cell backgrounds are white.
In ClosedXML code the following code works perfectly
worksheet.Row(i).Cell(0).Style.BackgroundColor = Color.FromArgb(argb)
Conclusion: Save $$$$$ and use ClosedXML
enter image description here
all is fine only ForegroundColor is not showing
I want to add a label that doesn't always face the camera. Instead, I want it to follow a defined path. Similar to how street names follow the direction of their streets in google maps (they aren't always horizontal).
I can think of 2 possible implementations for rotating text but haven't had any luck.
That Label() or label : have a rotation property I haven't found. IE something like this:
viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
label : {
text : 'Philadelphia'
//rotation : Cesium.Math.toRadians(-45)
}
});
or this
var labels = scene.primitives.add(new Cesium.LabelCollection());
var l = labels.add({
position : Cesium.Cartesian3.fromRadians(longitude, latitude, height),
text : 'Hello World',
font : '24px Helvetica'
//rotation: Cesium.Math.toRadians(-45)
});
Create Pictures of each label in photoshop and import them as an image, then rotate the image (or use it as a material and rotate the entity). Very labor intensive if you have a lot of labels (like street names).
Or perhaps there is a way for cesiumjs to recognize text as a fixed position 2D object and skew it appropriately as the view angle changes.
Any ideas?
If your text doesn't change, You can use an image, and load it by Cesium.SingleTileImageryProvider .
If your text does change, you can use a billboard.image, set an HTML canvas to it, and rotate the canvas like so:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "20px Georgia";
ctx.fillText("Hello World!", 10, 50);
ctx.font = "30px Verdana";
// Create gradient
var gradient = ctx.createLinearGradient(0, 0, c.width, 0);
gradient.addColorStop("0", "magenta");
gradient.addColorStop("0.5", "blue");
gradient.addColorStop("1.0", "red");
// Fill with gradient
ctx.rotate(20*Math.PI/180);
ctx.fillStyle = gradient;
ctx.fillText("Big smile!", 10, 90);
billboard.image = ctx;
The only way I know how to rotate a label is like #Henri Aloni said with canvas.
Cesium has already a function called: writeTextToCanvas.
example in typescript :
viewer.entities.add({
position: Cartesain3.fromDegrees(34, 32, 0),
billboard: {
image: writeTextToCanvas('baruch', {
font: '30px sans-serif'
}),
rotation: 45
}
});
I have learned how to apply colours to background of excel table row using jxl library by using the below code
WritableFont cellFonts = new WritableFont(WritableFont.ARIAL, 11, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat cellFormats = new WritableCellFormat(cellFonts);
cellFormats.setBackground(Colour.AQUA);
but i dont know how to apply custom color as background
when i tried this Colour myColour = Colour(221,221,221); i got exception
WritableFont cellFonts = new WritableFont(WritableFont.ARIAL, 11, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat cellFormats = new WritableCellFormat(cellFonts);
Colour myColour = Colour(221,221,221);
cellFormats.setBackground(myColour);
can anyone please tell me some solution for this
first you need to create a method:
private final WritableCellFormat getCellFormat(Colour colour) throws WriteException {
WritableFont cellFonts = new WritableFont(WritableFont.ARIAL, 11, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat cellFormats = new WritableCellFormat(cellFonts);
myColour= new Colour(10000, "1", 221, 221, 221) {
};
cellFormats.setBackground(myColour);
return cellFormats;
}
You need to:
change this:
Colour myColour = Colour(221,221,221);
cellFormats.setBackground(myColour);
to this:
myColour= new Colour(10000, "1", 221, 221, 221) {
};
and set in cell:
Label label1 = new Label(column, row, "text of cell or nothing", getCellFormat(myColour));
I hope helps.
I am trying to customize the position of text in Section element headers in MonoTouch Dialog. I read up on how you are supposed to create you own UILabel to create styled text and then assign that to the HeaderView of the Section object. That part works great.
The problem that I am faced with now is: how can I get a similar text offset as the offset used in the default unstyled Section element (see comparison in attached image). I cannot seem to find a way to get the "Styled Section" text moved away from the left edge of the screen no matter what I do. I tried changing the x coordinate specified in the RectangleF declaration, but whatever I specify appears to be disregarded when the view is rendered.
Here is the backing code for the screenshot:
Root = new RootElement ("Login2Screen");
var labelHeader = new UILabel();
labelHeader = new UILabel(new RectangleF(0, 0, 320, 48));
labelHeader.Text = "Styled
labelHeader.TextColor = UIColor.Blue;
labelHeader.BackgroundColor = UIColor.Clear;
var styledSection = new Section(labelHeader);
styledSection.Add(new EntryElement("Username", string.Empty, string.Empty));
styledSection.Add(new EntryElement("Password", string.Empty, string.Empty));
Root.Add(styledSection);
var defaultStyleSection = new Section("Default Section");
Root.Add (defaultStyleSection);
Add the labelHeader into an UIView and then set the x-coordinate of your UILabel to 10.
var viewLabelHeader = new UIView(new RectangleF(0, 0, 320, 48));
var labelHeader = new UILabel(new RectangleF(10, 0, 320, 48));
labelHeader.Text = "Styled section";
labelHeader.TextColor = UIColor.Blue;
labelHeader.BackgroundColor = UIColor.Clear;
viewLabelHeader.AddSubview (labelHeader);
var styledSection = new Section(viewLabelHeader);
Result:
Haven't read anything about the position of text in Section element, but
labelHeader = new UILabel(new RectangleF(0, 0, 320, 48));
You are positioning it at 0,0? if you make it 10,0 it should move. i.e. move x position to 10
labelHeader = new UILabel(new RectangleF(10, 0, 320, 48));