TCPDF create move-able "box" with text without using ln settings - tcpdf

I am trying to create a bit of a unique table in TCPDF as shown below:
Getting the captions, headers and rows setup is easy. The hard part is the "bar".
The bar needs a few things:
Editable X-position
Text
Originally I was trying to use MultiCell; however, I got some weird behavior as shown below:
Multi-Cell:
I believe this is because of the ln settings. If we look at my code you can see that I am trying to create a Cell and then a MultiCell inside of it. Both of these use the have the ln setting to put the next cell below.
I tried setting the MultiCell's ln to 0 (to the right) but it had no visible change.
//multi cell
// extend TCPF with custom functions
class MYPDF extends TCPDF {
// SCC table
public function SCCTable($headers,$rows) {
// Colors, line width and bold font
$this->SetFillColor(0,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$num_headers = count($headers);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell(
$headers[$i]->width,
$headers[$i]->height,
$headers[$i]->text,
1,
0,
'C',
1
);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$num_rows = count($rows);
for($i = 0; $i < $num_rows; ++$i){
$this->Cell(//Row
$headers[$i]->width * $num_headers, //Row width should be the sum of all header width.
$rows[$i]->height,
//Row's Text
$this->MultiCell(
$rows[$i]->width,
$rows[$i]->height,
$rows[$i]->text,
0, //Border
"C", //Text Align
false, //fill, determines if the background is painted or transparent (false).
2, //ln, 1 = Next cell starts at beginning of new line.
$rows[$i]->x,
$rows[$i]->y
),
1, //Border
2, //ln, 1 = Next cell starts at beginning of new line.
"L" //text align
);
}
}
}
After this I found out about TextField. When I tried this I got just as weird behavior...
//text field
// extend TCPF with custom functions
class MYPDF extends TCPDF {
// SCC table
public function SCCTable($headers,$rows) {
// Colors, line width and bold font
$this->SetFillColor(0,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$num_headers = count($headers);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell(
$headers[$i]->width,
$headers[$i]->height,
$headers[$i]->text,
1,
0,
'C',
1
);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$num_rows = count($rows);
for($i = 0; $i < $num_rows; ++$i){
$this->Cell(//Row
$headers[$i]->width * $num_headers, //Row width should be the sum of all header width.
$rows[$i]->height,
//Row's Text
$this->TextField(
$rows[$i]->text,
$rows[$i]->width,
$rows[$i]->height,
[],
[],
$rows[$i]->x,
$rows[$i]->y
),
1, //Border
2, //ln, 1 = Next cell starts at beginning of new line.
"L" //text align
);
}
}
}
Finally I thought of using the Rect function to create a rectangle and Text to the draw the text. Using variables I could "glue" the Text to the Rectangle; however, the textfield uses the ln setting as well; furthermore, looking at the actual code there is this line:
$this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
Seeing as it creates a cell, then it should run into the same problem as MultiCell, as the only difference between Cell and MultiCell in my case is the ability to change the x-position from the left border.
So I'm stuck with this question: How can I draw a "box" that has text and can be pushed along horizontally?
How this is done is not that important except that images aren't an option.

I realized I didn't actually need to have the original row. I could just make due with the "bar".
$this->MultiCell(
$rows[$i]->width,
$rows[$i]->height,
$rows[$i]->text,
1, //Border
"C", //Text Align
true, //fill, determines if the background is painted (true) or transparent (false).
2, //ln, 1 = Next cell starts at beginning of new line.
$rows[$i]->x,
$rows[$i]->y
);
Though with that said it would still be nice to know how to do with rows...

Related

Jetpack Compose - Row Clipping Children When Width Increases

Here on the right , I have a list of items in a composable , Every item is inside a row , All the items are inside a column
All the children of the are getting clipped to fit the screen which I don't want , I want these items to render completely even if outside of screen since I have a zoomable container above them
As you can see how text in the text field is all in one line vertically rather than expanding the width , This is the problem
Code :
Row(
modifier = modifier.zIndex(3f),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
) {
SimpleNodesList(
modifier = Modifier.padding(8.dp),
parentNode = state.center,
nodes = state.center.left,
renderRight = false,
)
SimpleNode(node = state.center, parentNode = null)
SimpleNodesList(
modifier = Modifier.padding(8.dp),
parentNode = state.center,
nodes = state.center.right,
renderLeft = false
)
}
Simple Nodes List is a column of rows , I have one column on left and one on the right , If the width of the left column increases , right row get's clipped by the screen
Using this modifier does the job for the row , In my case I also needed this layout modifier , wrapContentSize(unbounded = true) was working but children weren't clickable for some reason outside the bounds of the zoom container !
I also had to create a modifier zoomable rather than use a zoomable box , so the zoomable touch events would be dispatched on the this composable rather than the parent !
modifier = Modifier
.layout { measurable, constraints ->
val r =
measurable.measure(constraints = constraints.copy(maxWidth = Constraints.Infinity))
layout(r.measuredWidth, r.measuredHeight, placementBlock = {
r.placeWithLayer(0, 0, 0f) {
}
})
}
.wrapContentSize(unbounded = true)
If you are using hard-coded width for the text, applying Modifier.wrapContentSize() on every container might do the job
Use SimpleFlowRow in place of Row. It will fix the clipping issue.

The effect of BufferType.Normal and BufferType.Spannable for textView

I have this code:
TextView tv1 = FindViewById<TextView>(Resource.Id.textView1);
tv1.Text = "Text";
SpannableString wordtoSpan = new SpannableString(tv1.Text);
wordtoSpan.SetSpan(new UnderlineSpan(), 0, tv1.Text.Length, 0);
tv1.SetText(wordtoSpan, TextView.BufferType.Normal);
Whether I use BufferType.Normal or BufferType.Spannable, A line is drawn below the text,
a line appears below the text. So what is the effect of BufferType.Normal and BufferType.Spannable?
TextView.BufferType:
Normal: normal;
Editable: characters can be appended;
Spannable: use styles in the given character area;
The type of the text buffer that defines the characteristics of the text such as static, styleable, or editable. It could be used for changing the TextView in runtime.
TextView.BufferType.Editable: Insert
TextView tv2 = FindViewById<TextView>(Resource.Id.textView2);
tv2.SetText("Hello", TextView.BufferType.Editable);
var s = tv2.EditableText;
s.Insert(1, " Hello");
OutPut:
TextView.BufferType.Spannable: set the different color in a single Textview
TextView tv3 = FindViewById<TextView>(Resource.Id.textView3);
tv3.Text = "Hello World";
SpannableString wordtoSpan3 = new SpannableString(tv3.Text);
wordtoSpan3.SetSpan(new ForegroundColorSpan(Color.Red), 0, 5, 0); // "Hello" is red
wordtoSpan3.SetSpan(new ForegroundColorSpan(Color.Blue), 7, 11, 0); // "orld" is blue
tv3.SetText(wordtoSpan3, TextView.BufferType.Spannable);
Output:

Remove spacing between the first row and second row in the Gridlayout

Thank you very much for your help in advance.
Let me explain the problem,
I have grid layout where I am adding the labels in the first row (its called header row). In the next 5 rows, I am adding text field, combo and date fields.
The problem I am facing is, I would like to remove the space between header(first) row and second row and continue to have default space from second row to the last rows. I have highlighted the space as red line in the snapshot
Please find the snapshot in attachment.
Any hints, please advise.
As I've mentioned in the comments, position of a component in a GridLayout defined by a top value in css. So you would need to change it if you want to re-position(remove space, in this case) an element. The problem here is that
GridLayout not necessary starts from top, so you would need to figure out a correct value for a top,
and then you would need to differentiate a correct component(label in this case) using :n-th child, since a class name applied to a component, is not propagated to a parent's v-gridlayout-slot.
As for an alternative, you could add a common styleName to all components (except labels) and using this style set margins(left, right, bottom)to all the components. (In the example below used a pink color to verify styles are applied.)
In this scenario, output is like this:
The css part:
.addPadding{
margin-bottom: 15px;
margin-left: 15px;
margin-right: 15px;
background-color: pink;
}
Code used:
setContent(addGridLayout())
////
private GridLayout addGridLayout(){
// Create a 4 by 4 grid layout.
GridLayout grid = new GridLayout(4, 4);
//grid.setSpacing(true);
grid.addStyleName("example-gridlayout");
// Fill out the first row using the cursor.
for (int i = 0; i < 4; i++) {
Label l=new Label("Col " +
(grid.getCursorX() + 1));
grid.addComponent(l);
grid.setComponentAlignment(l,Alignment.BOTTOM_CENTER);
}
// Fill out the first column using coordinates.
for (int i = 1; i < 4; i++) {
TextField x=new TextField();
x.addStyleName("addPadding");
grid.addComponent(x, 0, i);
}
// Fill out the secondcolumn using coordinates.
for (int i = 1; i < 4; i++) {
TextField x=new TextField();
x.addStyleName("addPadding");
grid.addComponent(x, 1, i);
}
// Fill out the third column using coordinates.
for (int i = 1; i < 4; i++) {
DateField x=new DateField();
x.addStyleName("addPadding");
grid.addComponent(x, 2, i);
}
// Fill out the third column using coordinates.
for (int i = 1; i < 4; i++) {
ComboBox x=new ComboBox<String>();
x.addStyleName("addPadding");
grid.addComponent(x, 3, i);
}
return grid;
}
if the columns have fixed width you could create 2 GridLayouts one for the header and one for the content. Both of them should have no margin and the layout that contains them should have no spacing.

vaadin label not showing although the textbox appears fine

This is the constructor of the class I wrote, the textbox is showing but the label not:-
public StartingTest(String op) {
this.op = op;
setStyleName("mainpanel");
setCaption("Bonus Row");
row = new GridLayout(2, 1);
lblSource.setCaption("Source Profile: ");
lblSource.setSizeUndefined();
row.addComponent(lblSource, 0, 0);
row.addComponent(txtSourceProfile, 1, 0);
this.addComponent(row);
}
Your label's size is undefined. That means that your label's width is only as wide as it has to be to show the label's value. Your label's value is empty so you don't see your label. A fix would be to use setValue() instead of setCaption(). Also you could remove setSizeUndefined() and use the default label width of 100%.

highcharts grouped chart using custom bar width with no pointPadding

Basically i want to use pointPadding with custom bar width (pointWidth) both at the same time. But i can't, here is my problem:
I want a chart with no-padding in the bars of one group when showing grouped chart. For this purpose i used pointPadding: "0" and it shows me exactly right chart. like:
if(chart_json.chart.defaultSeriesType=='column'){
if(chart_json.xAxis.categories.length >= 1 ){
chart_json.plotOptions.column.groupPadding = "0.05";
chart_json.plotOptions.column.pointPadding = "0.00";
}
}
var chart=new Highcharts.Chart(chart_json,startupObj.startupFunction);
chartObjArray.push(chart);
But when i set my custom width it adds some spaces in between bars of one group.
Actually i want to put max and min limit on bar width, but i can't find any support from Highchart library. So for this purpose when highchart generate the chart, if the generated chart bar width exceeds my max-limit i set it to my max-limit and same for lower limit.
if(chart_json.chart.defaultSeriesType=='column'){
if(chart_json.xAxis.categories.length >= 1 ){
chart_json.plotOptions.column.groupPadding = "0.05";
chart_json.plotOptions.column.pointPadding = "0.00";
}
}
var chart=new Highcharts.Chart(chart_json,startupObj.startupFunction);
chartObjArray.push(chart);
//set bar width
if(chart_json.chart.defaultSeriesType=='column' || chart_json.chart.defaultSeriesType=='bar'){
setChartBarMaxMinWidth(chart,chart_json);
}
setChartContainerWidth(chart_json,chart);
////************************************///////////////////
function setChartBarMaxMinWidth(chart,json){
var maximumBarWidth=70;
var minimumBarWidth=15;
chart_json=eval('('+json.chart_json+')');
for(var j=0;j<chart.series.length;j++){
var series=chart.series[j];
if (series.data[0].pointWidth > maximumBarWidth) {
chart.series[j].options.pointWidth = maximumBarWidth;
isMaxMin='MAX';
}
if (series.data[0].pointWidth < minimumBarWidth) {
chart.series[j].options.pointWidth = minimumBarWidth;
isMaxMin='MIN';
}
};
function setChartContainerWidth(chartOptions,chart){
// calculate # of bars
var numberOfBars=seriesGroupLength*categoriesLength;
// calculate container width
// var containerWidth=numberOfBars*43;
// get chart bar width
var containerWidth=numberOfBars*barWidth;
chart.setSize($(container).width(),$(container).height());
};
In setChartContainerWidth() i used highchart setSize() method to resize chart..
Thanks if someone can help me to remove spaces in between bars of one group.
Thanks
I used the spacingTop attribute to enforce a maximum pointWidth:
if (series[0].data[0].pointWidth > maximumBarWidth) {
this.options.chart.spacingTop = this.options.chart.height - (maximumBarWidth * series.length) - 30;
this.isDirtyBox = true;
this.redraw();
}
So if there is one Bar over a certain Width the spacing will be adjusted and the chart is drawn smaller.
This does not change the size of the container but keeps the bars beneath a certain size and your pointPadding and groupPadding will not be affected.
You will have to adjust the calculation of the spacingTop depending on your data structure and the size of your axis titles.

Resources