/*
Creating some Markdown by highlighting text and pressing a button
Could in theory be useful for Discord if completed
I wrote this tiny app while waiting for my wife
to have some scans at hospital
It has no refinement at all
The sizes of everything are only designed to fit phone and I just use the bottom of an oversized scroller as a swipe handle
It works for me although it does not save me much time
I anyone feels like expanding it (and probably fixing) it is very welcome to
In case it's not obvious, it's a native app
*/
var testText = "Hello folks and what about the workers"
function OnStart()
{
lay = app.CreateLayout("linear", "Center, FillXY")
txe = app.AddTextEdit( lay,testText,0.9,0.5 )
txe.SetBackColor( "#44000044" )
app.AddLayout(lay)
scrol = app.AddScroller( lay,1,0.15 )
lay2 = app.CreateLayout( "Linear","Left,horizontal")
scrol.SetBackColor( "#44004400" )
scrol.AddChild( lay2 )
makeButton("big header%# % #")
makeButton("medium header%## % ##")
makeButton("small header%### % ###")
makeButton("italic%*%*")
makeButton("bold%**%**")
makeButton("bold+italic%***%***")
makeButton("underline%__%__")
makeButton("underline+italic%__*%*__ ")
makeButton("underline+bold+italic%__***%***__")
makeButton("strikethough%~~%~~")
}
function makeButton( obj )
{
var detail = obj.split("%")
var lab= detail[0],
pre=detail[1],
post=detail[2]
//alert(lab)
var btn = app.CreateButton( lab )
btn.data.pre = pre
btn.data.post= post
lay2.AddChild( btn )
btn.SetOnTouch( btn_OnTouch )
}
function btn_OnTouch(btn)
{
var dat = (app.eventSource).data
var txtin = txe.GetSelectedText()
var start= txe.GetSelectionStart()
var end = txe.GetSelectionEnd()
outp = dat.pre + txtin +
dat.post txe.ReplaceText( outp,start,end )
}