I'm writing an app and need to paint text, It must to measure text to get point to paint. But in my knowledge, titanium don't support it. How can I do that
Measure text as in length of the text string? If your text is in a textfield you can get the .value out of it and then use string lengths to get out it's length.
I feel like this is what you want;
var label1 = Ti.UI.createLabel({
color: '#900',
font: { fontSize:48 },
text: 'A simple label',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
top: 30,
width: Ti.UI.SIZE, height: Ti.UI.SIZE
});
win.add(label1);
label1.addEventListener('postlayout', function(e) {
var label1_height = e.source.rect.height;
var label1_width = e.source.rect.width;
Ti.API.info(label1_height, label1_width);
});
Change the window name to yours, then run it. Should do the trick. Print the width and height of your label.
Related
My task description is very long and when I'm exporting to .pdf the text is hide (I cannot make task column too much wide): how can I divide text into 2 or 3 lines inside the grid? Is it possible to force the text to new line?
you can use DHX Gantt templates for grid columns https://docs.dhtmlx.com/gantt/desktop__specifying_columns.html#settingthetemplateofdatapresentation
Then set and define a new class to the task text element. Something like this
gantt.config.columns = [
{name:"wbs", label:"WBS", width:40, template:gantt.getWBSCode },
{name:"text", label:"Task name", tree:true, width:170, template: function(task) {return "<div class='gantt_multiline'>" + task.text + "</div>"} },
{name:"start_date", align: "center", width: 90},
{name:"duration", align: "center" , width: 60},
{name:"add", width:40}
];
Then define CSS for this class
<style type="text/css">
.gantt_multiline {
white-space: normal;
background-color: #FFE0F9;
line-height: 110% !important;
font-size:8pt !important;
}
I've put the BG color just to indicate the area we are working with.
Then. When exporting to PDF, you just need to send this CSS definition into the header
https://docs.dhtmlx.com/gantt/desktop__export.html#customstylefortheoutputfile
gantt.exportToPDF({
name: "My Page.pdf",
header: "<div><style type='text/css'>.gantt_multiline{white-space:normal;background-color:#FFF0F9;line-height:110% !important;font-size:8pt !important;}</style></div>"
});
Also it's possible to set row height at DHX Gantt, for example
gantt.config.row_height = 40;
Here I found the live example of multiline at task's bars https://docs.dhtmlx.com/gantt/snippet/213a0e27
Note that at this example the class is being applied only for large task names
Best regards!
How can I set the font size of a TextField element in QML? wanna change size of the placeholderText and also for the text which the user enters.
I tried with a lot of ways without luck!
TextField {
id: name_TextField; horizontalAlignment: Text.AlignHCenter;
Layout.preferredWidth: parentCLayer.width * 0.90; Layout.preferredHeight: 50
style: TextFieldStyle {
font.pixelSize: 20 // This doesn't seem to work either
}
placeholderText: qsTr("Your name here")
}
You can use the style property to customize your TextField. For example:
TextField {
style: TextFieldStyle {
font.pixelSize: 14
}
}
I tried it and it works like a charm
Using the font member of TextField
The TextField type itself has a member font which contains an instance of the QML basic type font. It's sufficient to change the values of the inner-members of the font member of TextField to make the changes you want to see. Note that the color is provided by the TextField itself, not the font type.
TextField {
font.pointSize: 20
font.bold: true
font.family: "Times New Roman"
textColor: "red"
}
Default Style
Custom Style
Using the style member of TextField
If you want to do more in-depth styling of the TextField you can attach a TextFieldStyle to the style member of the TextField. The TextFieldStyle instance also has a font member, though in the IDE it will complain that font has no members if you reference them with dot notation, this may be bug QTCREATORBUG-11186. I believe the proper way to assign values is using group notation by referencing the font property with inner-items as such:
TextField {
style: TextFieldStyle {
background: Rectangle {
color: "red"
radius: 10
}
font {
bold: true
pointSize: 22
}
textColor: "white"
}
}
It could be that bug #11186 is a genuine bug, or maybe by design the font property is TextFieldStyle is null; someone with better Qt/QML knowledge could provide a clearer answer as to that part of the question.
This guide on styling may help: http://wiki.qt.io/Qml_Styling
Is there a way in cascades to get font size for a given text and fixed width?
I was trying with:
TextField{
autoFit: TextAutoFit.FitToBounds
}
But the text always appear left align. The requirement is to center align text with variable font size label render in fixed rect.
If you want just to center align text, you'd need to use textStyle.textAlign property like that:
textStyle.textAlign: TextAlign.Center
In order to center align text with variable font size label render in fixed rect, you basically need to specify the desired width and height of that rectangle for a Label use textStyle.textAlign property mentioned above and choose the font size via respective textStyle.fontSize Label property. Text aligning will be done by Cascades automatically (of course, if your text couldn't be fit in specified width/height it'd be cut off):
import bb.cascades 1.0
Page {
Container {
layout: DockLayout {}
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
Label {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
maxWidth: 300
minWidth: maxWidth
maxHeight: 100
minHeight: maxHeight
multiline: true
text: "Some very very very very very long text here"
textStyle.textAlign: TextAlign.Center
textStyle.fontSize: FontSize.XLarge
}
}
}
I'd recommend this approach for achieving the goal set.
However, if you really want to get absolute values of font being used in a widget, use textStyle.fontSize property for this (TextStyle official documentation).
There are no font metrics in BB10 Cascades at the moment so you won't be able to find out if the font does not fit in the label and resize it.
You can use sort of hack with layoutUpdateHandler to get some rough resizing, but I wouldn't recommend it. If the text changes frequently you will see flickering, but if it's only set once then it might be okay. Change the text set in "onCreationCompleted" to see if the text resizes for you.
Container {
id: root
implicitLayoutAnimationsEnabled: false
background: Color.Cyan
property int width: 500
property string text: ""
property double textSize: 20
layout: DockLayout {
}
attachedObjects: [
LayoutUpdateHandler {
onLayoutFrameChanged: {
if (layoutFrame.width > root.width) {
root.textSize = root.textSize - 1
}
}
}
]
Label {
implicitLayoutAnimationsEnabled: false
maxWidth: root.width
text: root.text
textStyle {
fontSize: FontSize.PointValue
fontSizeValue: root.textSize
}
}
Label {
implicitLayoutAnimationsEnabled: false
text: root.text
opacity: 0
textStyle {
fontSize: FontSize.PointValue
fontSizeValue: root.textSize
}
}
onCreationCompleted: {
root.text = "Hello World AAAAAAAA"
}
}
I am using a non-editable objectPicker and setting the empty text:
this.statePicker = Ext.create('Rally.ui.picker.MultiObjectPicker', {
modelType: 'State',
id: 'statePicker',
matchFieldWidth: false,
editable:false,
emptyText: "Select...",
placeholderText: "Select...",
width: 80,
listeners: {
select: this._getFilter,
deselect: this._getFilter,
scope: this
},
});
I want to format the emptyText (emptyText: "Select...",) to be white with a background color. Using the below CSS, the background color displays perfectly, but the text color stays gray.
.x-form-empty-field {
color: #FFFFFF !important;
background-color: #085478;
}
Ihave tried other classes but none change the font. It stays gray! Please help?
The 'emptyText' is applied to the field using the 'placeholder' HTML5 attribute. The answer is going to vary depending on which browser you are using.
Here is a guide that demonstrates how to style the placeholder text in the various browsers that support it: http://css-tricks.com/snippets/css/style-placeholder-text/
Here is some useful information about the placeholder attribute in general (also includes styling examples): http://www.hongkiat.com/blog/html5-placeholder/
Hope this helps!
Using the example from the docs Ext.chart.series.Bar it should be pretty easy to achieve this.
The series has a label config that contains a color properties. Changing this has no effect. Or am I missing something?
I would like to display a white text on top of the bars.
Working code for the example
http://jsfiddle.net/dfDb8/
On line 48 I try to set the color to white
label: {
display: 'insideStart',
field: 'data',
renderer: Ext.util.Format.numberRenderer('0'),
orientation: 'horizontal',
color: '#fff' //this is what I want to change
'text-anchor': 'middle'
},
Any ideas?
The following attribute:
fill: '#fff'
seems to work. I am not completely sure why though.