Hi,
I’ve made a widget to display some information from my app backend systems. Presently the data is stacked on the left hand side like so:
Title
subtitle
data1
data2
data3
data4
I’d like to add another range of data but have spent the day fiddling with horizontal and vertical stacks without much success… What I’m trying to achieve, in a medium sized widget, is:
The bottom rows should be 50/50 split. I’ve tried to get cells to behave like this but just no luck! What am I doing wrong?
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: magic;
let items = await loadItems("<my data source>")
// if (config.runsInWidget) {
let widget = createWidget(items)
Script.setWidget(widget)
Script.complete()
// }
function createWidget(data) {
let w = new ListWidget()
w.backgroundColor = new Color("#1e1f21")
let textColor = new Color("#45a0f8")
let titleStack = w.addStack()
let titleCount = data.Total
let titleText = titleStack.addText('EmergencyLocate - ' + titleCount)
titleText.font = Font.boldSystemFont(24)
titleText.textColor = textColor
w.addSpacer()
let header = w.addStack()
let row = w.addStack()
row.backgroundColor = Color.white()
row.centerAlignContent()
let dataTable = new UITable()
let trow = new UITableRow()
dataTable.addRow(trow)
let leftCell = UITableCell.text('LEFt Cell')
leftCell.font = Font.boldSystemFont(14)
leftCell.textColor = textColor
leftCell.leftAligned()
leftCell.widthWeight = 4
trow.addCell(leftCell)
// left.backgroundColor = Color.red()
// left.addSpacer(4)
// left.leftAligned()
// left.bottomAlignContent()
// left.layoutVertically()
// let right = trow.addCell()
// right.rightAligned()
// right.backgroundColor = Color.blue()
// right.bottomAlignContent()
// right.layoutVertically()
//Subtitle
let subTitleText = header.addText('Past 24hrs')
subTitleText.font = Font.boldSystemFont(14)
subTitleText.textColor = textColor
let w3wEntry = (data.Xw3wEntry) ? data.Xw3wEntry : '0';
let SMS999 = (data.X999Find) ? data.X999Find : '0';
let apiFind = (data.XapiFind) ? data.XapiFind : '0';
let DirResp = (data.X999Direct) ? data.X999Direct : '0';
let w3wEntryStr = w.addText('Conversion Tool: ' + w3wEntry)
w3wEntryStr.font = Font.boldSystemFont(10)
w3wEntryStr.textColor = Color.white()
let SMS999Str = w.addText('Find By SMS: ' + SMS999)
SMS999Str.font = Font.boldSystemFont(10)
SMS999Str.textColor = Color.white()
let apiFindStr = w.addText('Find By API: ' + apiFind)
apiFindStr.font = Font.boldSystemFont(10)
apiFindStr.textColor = Color.white()
let DirRespStr = w.addText('Deployments: ' + DirResp)
DirRespStr.font = Font.boldSystemFont(10)
DirRespStr.textColor = Color.white()
return w
}
async function loadItems(Theurl) {
let url = Theurl
let req = new Request(url)
let json = await req.loadJSON()
return (json)
}