Correcty align text with image in constraintlayout in Jetpack Compose - android-constraintlayout

this is my code:
#Composable
fun ShowSplashHeader() {
ConstraintLayout() {
val (logo, text1, text2) = createRefs()
Image(
painter = painterResource(id = R.drawable.logo),
contentDescription = null,
modifier = Modifier.constrainAs(logo) {
top.linkTo(parent.top, margin = 32.dp)
start.linkTo(parent.start, margin = 16.dp)
}
.size(45.dp)
)
Text(
"First line text",
style = MaterialTheme.typography.h6,
color = colorResource(R.color.green_light),
modifier = Modifier.constrainAs(text1) {
top.linkTo(logo.top, margin = 0.dp)
start.linkTo(logo.end, margin = 4.dp)
}
)
Text(
"Second line text",
style = MaterialTheme.typography.h6,
color = colorResource(R.color.green_light),
modifier = Modifier.constrainAs(text2) {
start.linkTo(text1.start)
bottom.linkTo(logo.bottom, margin = 0.dp)
}
)
}
}
I am getting this:
I need to set the first line with the top alignment with the image and the second line with the bottom alignment. It is obvious that constraints are correctly set and that the Text should not have inner padding but I don't know how to fix it.
Can anyone help? Thanks in advance!

Related

PdfSharp Charts - Remove Border and Background

I'm using PdfSharp Charts and the chart container have a blue border and a gradient background. I looked for the property that sets those options but no success. I can change multiple things in the chart itself, but not for the container.
How can I remove the border and the background?
Thanks!
Again, I looked for the properties of the chart container but no success.
Here is the code I have so far:
public static Chart ColumnChart(PdfChartValues pdfChartValues)
{
Chart chart = new Chart(ChartType.Column2D);
chart.Font.Size = 7;
chart.PlotArea.FillFormat.Color = XColors.White;
chart.Legend.Docking = DockingType.Bottom;
XSeries xSeries = chart.XValues.AddXSeries();
xSeries.Add(pdfChartValues.XSeriesText);
Series series;
foreach (var item in pdfChartValues.ChartSeriesValues)
{
series = chart.SeriesCollection.AddSeries();
series.Name = item.SeriesName;
series.Add(item.SeriesValues);
series.FillFormat.Color = XColor.FromArgb(item.RedValue, item.GreenValue, item.BlueValue); // Bar color
}
chart.XAxis.HasMajorGridlines = false;
chart.XAxis.MajorTickMark = TickMarkType.None;
chart.XAxis.Title.Caption = pdfChartValues.TitleCaption;
chart.YAxis.MajorTickMark = TickMarkType.None;
chart.YAxis.MajorTick = pdfChartValues.YAxisMajorTick;
chart.YAxis.HasMajorGridlines = true;
chart.YAxis.MajorGridlines.LineFormat.Color = XColors.LightGray;
chart.PlotArea.LineFormat.Color = XColors.LightGray;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;
chart.DataLabel.Type = DataLabelType.Value;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
chart.DataLabel.Format = pdfChartValues.SetMoneyFormat ? "$0" : "##,#";
return chart;
}
It seems the colours are hard-coded in ChartFrame.cs.
They cannot yet be set using properties.
Take the PDFsharp source code, change the colours there, and compile.

How to properly display floating Buttons on top of BottomNavigationView?

I want to display 2 "floating buttons" a bit on top of a BottomNavigationView if one of its menu is clicked.
Here's my attempt. Basically it uses an AlertDialog supplied with a LinearLayout (full code: https://github.com/anta40/ButtonAnimTest)
bottomNav.setOnItemSelectedListener { menu ->
when (menu.itemId){
R.id.game_menu -> {
val dialogBuilder = AlertDialog.Builder(this)
val customView = layoutInflater.inflate(R.layout.custom_alert_layout, null)
dialogBuilder.setView(customView)
dialogBuilder.setCancelable(true)
val btnYes = customView.findViewById<Button>(R.id.btn_dialog_yes)
val btnNo = customView.findViewById<Button>(R.id.btn_dialog_no)
/*
taken from https://stackoverflow.com/questions/9467026/changing-position-of-the-dialog-on-screen-android
*/
val alert = dialogBuilder.create()
val dialogWindow = alert.window
val layoutParams = dialogWindow!!.attributes
layoutParams.gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
layoutParams.flags = layoutParams.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv()
dialogWindow.attributes = layoutParams
dialogWindow.setBackgroundDrawable(ColorDrawable(android.graphics.Color.TRANSPARENT))
btnYes.setOnClickListener {
alert.dismiss()
}
btnNo.setOnClickListener {
alert.dismiss()
}
alert.show()
true
}
}
false
}
}
There are 2 problems:
The LinearLayout is displayed too high, aligned with the TitleBar. What I want is just a little bit on top of the BottomNavigationView, like 10dp or 20dp.
The screen is dimmed a bit. I don't want the brightness to be changed when those buttons appear.
How to fix these?

How to set reset zoom button and title to exactly center of the high charts

I am trying to set the reset zoom button and title to exactly the center of the high chart. Here the title is the selected time range of the chart portion. I need to set this as dynamically centered based on the screen resolution.
chart:{
zoomType:'x',
resetZoomButton:{
position:{
verticalAlign:'top'
},
relativeTo:'chart'
},
events:{
selection:function(event){
this.setTitle({{text:selectedChartPortion,useHtml:true}})
}
}
}
here text:selectedChartPortion is a span tag that has some style properties and the selected value.
Expected Chart outlook:
Can anyone help me to resolve it?
I think that this config should help you to achieve a wanted effect:
xAxis: {
events: {
afterSetExtremes() {
const chart = this.chart;
const resetZoomButton = chart.resetZoomButton;
const padding = 5;
if (resetZoomButton) {
chart.title.translate(-chart.title.getBBox().width / 2 - padding, 0)
resetZoomButton.translate(chart.plotWidth / 2 + resetZoomButton.getBBox().width / 2 + padding, 0)
} else {
chart.title.translate(chart.title.getBBox().width / 2 + chart.title.translateX, 0)
}
}
}
}
Demo: https://jsfiddle.net/BlackLabel/8yjd9orx/
API: https://api.highcharts.com/highcharts/chart.resetZoomButton.position.align
API: https://api.highcharts.com/highcharts/xAxis.events.afterSetExtremes

ScalaFX: how to wrap text in a TableCell

I want to show a list of key and values in a TreeTableView, and some of the values are a bit longer text which I want to wrap around and show completely.
I thought I use TextFieldTreeTableCell with wrapText and vgrow as follows:
val valCol = new TreeTableColumn[(String,String), String] {
text = "Header"
cellValueFactory = { p => StringProperty(p.value.value.value._2) }
cellFactory = { p => new TextFieldTreeTableCell[(String,String),String]() {
wrapText = true
vgrow = Priority.Always
} }
}
But the text is only shown in one line wiht ... at the end.
What am I missing?

Hide dropdown button

I'm creating a TextField as so:
iTextSharp.text.pdf.TextField fieldCombo = new iTextSharp.text.pdf.TextField(stamp.Writer, realArea, placeHolder);
fieldCombo.Choices = (new string[1] { "" }).Concat(attribute.Values.Select(x => x.Value.Code)).ToArray();
iTextSharp.text.Font bold = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 9f, iTextSharp.text.Font.BOLD);
fieldCombo.Font = bold.BaseFont;
fieldCombo.FieldName = Guid.NewGuid().ToSafeString();
fieldCombo.FontSize = 10f;
fieldCombo.TextColor = new iTextSharp.text.BaseColor(System.Drawing.Color.FromArgb(255, 6, 97, 50));
fieldCombo.Options = iTextSharp.text.pdf.BaseField.EDIT | iTextSharp.text.pdf.BaseField.VISIBLE_BUT_DOES_NOT_PRINT;
stamp.AddAnnotation(fieldCombo.GetComboField(), page + 1);
From the first time the field is focussed, a very generic grayish down arrow appears on the document, positioned next to my value. Even if the field is unfocussed, this arrow stay visible.
Can I get rid of this combo box button when printing the document?