buttons multiple

228 views
Skip to first unread message

Thiemo Melhorn

unread,
Jan 17, 2023, 8:00:52 AM1/17/23
to DroidScript
how to use buttons multiple times for e.g. a dialog?

Right2TheV0id

unread,
Jan 17, 2023, 9:07:31 AM1/17/23
to DroidScript
All buttons are usable multiple times.
First you create your button object with app.CreateButton or app.AddButton, then you attach the OnTouch callback to it using btn.SetOnTouch.
Then, every time you touch your button, the OnTouch callback is executed.
What is your issue?

Thiemo Melhorn

unread,
Jan 17, 2023, 9:56:02 AM1/17/23
to DroidScript
I meant how to simplify it. I already have a routine for this (see below) but somehow it seems that it is not made for dialogs

function newButton(lay,text) {
    var but = app.AddButton(lay,text,-1,-1,"fontawesome")
    but.SetStyle(transparent,transparent, 0, null, 0, 0)
    but.SetTextColor(clrTxt)
    but.Animate( "FadeIn" )
    return but
}

Right2TheV0id

unread,
Jan 17, 2023, 10:08:53 AM1/17/23
to DroidScript
Your code creates general purpose buttons, you can do wathever you want with them.
There is nothing about "dialog" on the code you showed, so I'm still confused.

Thiemo Melhorn

unread,
Jan 17, 2023, 10:37:07 AM1/17/23
to DroidScript
Ok! I'll try to explain it to you. I have a dialog and would like the 'OK' button in the tab control to always look the same. How do I get that?

Right2TheV0id

unread,
Jan 17, 2023, 12:07:02 PM1/17/23
to DroidScript
All the buttons created with your function "newButton(lay,text)" should looks the same, what is your issue?

Thiemo Melhorn

unread,
Jan 17, 2023, 12:24:16 PM1/17/23
to DroidScript
The problem is that this is not true for dialogs but only for the other buttons outside the dialog.

Right2TheV0id

unread,
Jan 17, 2023, 12:26:47 PM1/17/23
to DroidScript
Can you provide a snippet showing it?

Thiemo Melhorn

unread,
Jan 17, 2023, 12:58:59 PM1/17/23
to DroidScript
photo_2023-01-17_18-53-22.jpg
photo_2023-01-17_18-53-49.jpg

photo_2023-01-17_18-53-38.jpg

Right2TheV0id

unread,
Jan 17, 2023, 1:28:20 PM1/17/23
to DroidScript
The code you presented doesn't use the "newButton" function you provided earlier.
Message has been deleted

Thiemo Melhorn

unread,
Jan 17, 2023, 1:50:39 PM1/17/23
to DroidScript
I have successfully added but not achieved the desired goal.

My goal is that the button in the dialog is always at the same position or at the end of the layout and that the dialog becomes a bit smaller.

Thiemo Melhorn

unread,
Jan 17, 2023, 2:28:45 PM1/17/23
to DroidScript
Is it enough if I copy or modify the code?

Димыч Вакулин

unread,
Jan 17, 2023, 3:31:03 PM1/17/23
to DroidScript
You should place the "OK" button not in tabs.getLayout containers, but place the general "OK" button after the tabs object itself. You will have to handle events depending on the current index of the tab, keeping track of changes in tabs.SetOnChange

вторник, 17 января 2023 г. в 22:28:45 UTC+3, Thiemo Melhorn:

Thiemo Melhorn

unread,
Jan 17, 2023, 9:39:56 PM1/17/23
to DroidScript
I suspect why it can't really position itself or 'style' the button is probably also somewhere in this code but my attempts to do it myself didn't work (really).

//Create dialog window.
    dlgSettings = app.CreateDialog( "Einstellungen" )
    
    //Create a layout for dialog.
    layDlg = app.CreateLayout("absolute")
    layDlg.SetSize( 1.0 );
    dlgSettings.AddLayout( layDlg )
    //Create tabs
    var tabs = app.CreateTabs( "Allgemein,Updates,Infos", 1.0, 1.0, "")
    layDlg.AddChild( tabs )
    //Add buttons to tabs.
    layDlgDesign = tabs.GetLayout( "Allgemein" )
    var txtColor = app.AddText( layDlgDesign,"Hintergrundfarbe auswählen")
    txtColor.SetMargins( 0, 0.01, 0, 0 )
    var pollux = app.AddLayout(layDlgDesign,"linear")   
    pollux.SetChildTextSize(12)
    item = app.LoadText( "item", "Schwarz" );
    clrBg = app.LoadText( "clrBg", "black" );
    clrTxt = app.LoadText( "clrTxt", "white" );
    var lstColors = app.AddSpinner( pollux,"Schwarz,Weiss,Blau" )
    lstColors.SelectItem( item )
    lstColors.SetOnChange( lstColors_OnTouch )
    
    var text = "Startseite festlegen";
    txt.SetMargins( 0, 0.03, 0, 0 )
    txt = app.CreateText( text )
    layDlgDesign.AddChild( txt )
    var castor = app.CreateLayout(layDlgDesign,"linear")
        var home = app.AddTextEdit(layDlgDesign,defaultUrl,0.8,"Autosize")
        var save = newButton(layDlgDesign,"[fa-save]")
        save.SetOnTouch(function () {
        defaultUrl=home.GetText()
        app.SaveText("defaultUrl",defaultUrl)
        app.ShowPopup("Startseite geändert!")
    })

    var text = "Suchmaschinen auswählen";
    txt = app.CreateText( text)
    layDlgDesign.AddChild( txt )
    var data = "Google:[fa-google],Yahoo:[fa-yahoo],Bing:[fa-windows],Brave Search:[fa-bitcoin],Neeva:[fa-deafness]";
    lst = app.CreateList( data, 0.7, 0.4 );
    layDlgDesign.AddChild( lst )
    lst.SetOnTouch(function (title,body,icon,index) {
        if (title == "Google") searchUrl = "https://www.google.com/search?q="
        if (title == "Yahoo") searchUrl = "https://www.search.yahoo.com/search?q="
        if (title == "Bing") searchUrl = "https://www.bing.com/search?q="
        if (title == "Brave Search") searchUrl = "https://search.brave.com/search?q="
        if (title == "Neeva") searchUrl = "https://neeva.com/search?q="
        app.SaveText("searchUrl",searchUrl)
    })
    btnOk = app.AddButton( layDlgDesign, "Ok" )
    btnOk.SetMargins( 0, 0.01, 0, 0 )
    btnOk.SetOnTouch(function() {dlgSettings.Dismiss();})
    
    layDlgUpdate = tabs.GetLayout( "Updates" )
    var text = "Manuelles Update";
    txt.SetMargins( 0, 0.03, 0, 0 )
    txt = app.CreateText( text)
    layDlgUpdate.AddChild( txt )
    btnUpdates = app.CreateButton( "Überprüfen von Updates" );
    btnUpdates.SetMargins( 0, 0.01, 0, 0 )
    btnUpdates.SetOnTouch( btnUpdates_OnTouch );
    layDlgUpdate.AddChild( btnUpdates );
    btnOk = app.AddButton( layDlgUpdate, "Ok")
    btnOk.SetMargins( 0, 0.03, 0, 0 )
    btnOk.SetOnTouch(function() {dlgSettings.Dismiss();})
    
    layDlgSpeech = tabs.GetLayout( "Infos" )
    webDlgSpeech = app.CreateWebView(1, 0.9);
    webDlgSpeech.LoadUrl();

Димыч Вакулин

unread,
Jan 17, 2023, 10:53:03 PM1/17/23
to DroidScript
As far as I understand, try to place the "Ok" button at the very bottom, regardless of the size of the contents of the tabs. I have sketched a schematic example, now I will try to attach the Spk from the phone.

среда, 18 января 2023 г. в 05:39:56 UTC+3, Thiemo Melhorn:
example.spk

Thiemo Melhorn

unread,
Jan 18, 2023, 1:57:35 AM1/18/23
to DroidScript
Ich habe den Code mit meinen Controls vereint bekommen aber leider wird das Tabcontrol im Vollbild angezeigt sowie teilweise abgeschnitten (siehe Screenshot).

2023_01_18_07.53.43.jpg

Димыч Вакулин

unread,
Jan 18, 2023, 3:08:46 AM1/18/23
to DroidScript
Can you create an Spk and upload it here?

среда, 18 января 2023 г. в 09:57:35 UTC+3, Thiemo Melhorn:
Message has been deleted

Димыч Вакулин

unread,
Jan 18, 2023, 4:46:03 AM1/18/23
to DroidScript
What immediately caught my eye:
layDlg.setSize( 0.85, 0.85);
And then:
tabs = app.CreateTabs( "Allgemein,Updates,Infos", 0.95, 0.8, "VCenter,Fade" )
As you can see, tabs with a width of 0.95 will not fit in a layDlg with a width of 0.85.
Next. If you create var txtColor = app.addText( tabCtrl,"Hintergrundfarbe auswählen") thus, you will no longer be able to make txtColor.setMargins( 0, 0.01, 0, 0 )
You need a classic
txt = app.CreateText(...)
txt.SetMargins(...)
tabCtrl.AddChild( txt )

среда, 18 января 2023 г. в 11:23:00 UTC+3, Thiemo Melhorn:
Message has been deleted

Right2TheV0id

unread,
Jan 18, 2023, 10:09:55 AM1/18/23
to DroidScript
Good advices, but I'm not ok with app.AddText preventing to use txt.SetMargins.
You made me doubt so I tried it (I attached a quick demo).
I can confirm that SetMargins works with CreateText and AddText.
Test txt.SetMargins.spk

Димыч Вакулин

unread,
Jan 18, 2023, 11:07:03 AM1/18/23
to DroidScript
I didn't put it quite right. In your case, txtColor.setMargins(...) forces to ignore tabCtrl.SetChildMargins(...).
Find the line "//Uncomment the line below and see the changes" in the attached spk.

среда, 18 января 2023 г. в 18:09:55 UTC+3, Right2TheV0id:
Testbrowser_margins.spk

Thiemo Melhorn

unread,
Jan 18, 2023, 12:28:26 PM1/18/23
to DroidScript
Somehow I can't get this to work. Even if I recreate the dialog and add my stuff, it's either not displayed at all or cut off.

Thiemo Melhorn

unread,
Jan 18, 2023, 12:30:29 PM1/18/23
to DroidScript
2023_01_18_18.25.23.jpg

Димыч Вакулин

unread,
Jan 18, 2023, 8:06:35 PM1/18/23
to DroidScript
It's hard for me to assume something without seeing the code. Here is a template where there is no unnecessary clutter of code, it may be easier for you to practice.

среда, 18 января 2023 г. в 20:30:29 UTC+3, Thiemo Melhorn:
2023_01_18_18.25.23.jpg
tabs_demo.spk

Thiemo Melhorn

unread,
Jan 18, 2023, 10:31:11 PM1/18/23
to DroidScript
I have already tried to add the things but somehow and something I must have done that the error is triggered (see SPK file).


Testbrowser_Copy.spk

Димыч Вакулин

unread,
Jan 19, 2023, 4:01:57 AM1/19/23
to DroidScript
1) var layBill = tabs.GetLayout( "Updates" ) // "Update" -> "Updates"

2) function btn0_OnTouch()
{
    dialog.Show() //"dlg.Show" -> "dialog.Show"
}

четверг, 19 января 2023 г. в 06:31:11 UTC+3, Thiemo Melhorn:
Testbrowser_Copy_1.spk
Message has been deleted

Thiemo Melhorn

unread,
Jan 19, 2023, 4:19:35 AM1/19/23
to DroidScript
Dankeschön für die Hilfe. 

Alan Hendry

unread,
Jan 23, 2023, 6:19:33 PM1/23/23
to DroidScript
Hi, 
I think this needs one button in one dialog to close that dialog,
and a second button in a second dialog to close the second dialog.
  • So it's kinda hard to make one object do it, otherwise I'd cr3ate button once, then add it into the 2 dialogs.
But you should be able to shorten your code with a function to create the button, add to dialog, style, and setontouch after using the function.

Regards, ah
Reply all
Reply to author
Forward
0 new messages