Selectable id ?

Former Member
Former Member
Hi,

got a problem , maybe anyone can help.

I defined a simple selectable area using

<selectable x="100" y="center" width="100" height="100">
<state id="stateDefault" color="Gfx.COLOR_BLACK" />
</selectable>

and i implemented the relative method in delegate

function onSelectable(selectEvent)
{
}

it works properly but How can I identify the selectable area? from the selectEvent I can get the instance and last state but the identifier inherited from Drawable obj is null...any help ?

thanks for the help.

Marco
  • You need to set the id attribute for the selectable. Unfortunately, I haven't been able to find a way to do this while using a selectable element in the xml. I'll take a peek at the resource compiler and talk to the team in the morning.

    I'm not exactly sure what you're trying to achieve, but are you sure that using a Ui.Selectable is what you want to do? Could you more easily get what you want by creating your own class derived from Ui.Selectable, or maybe by using Ui.Button?

    Travis
  • Former Member
    Former Member
    Hi travis,

    thanks for reply.
    I know I have to set the attribute identifier but i guess it's not possible via xml. what I thought is to set something like this
    <param name="identifier">

    that should add an element to param list in constructor of selectable.
    The point is that a selectable inherits from a drawable but has not id element in constructor list(why?): doing as above maybe will pass the list as it is int the base class. We should see how the compiler generates classes.
    My goal is to have a selectable zone , more or less like a button. I'm pretty confident I can do without using resource compiler... but it is really useful and i would like to use it.
    BTW if there is no solution i'll switch coding by my self.

    MArco
  • Former Member
    Former Member
    not working the param trick...
    if you have any tip :)

    Marco
  • Former Member
    Former Member
    Since nobody replied I give u my solution , maybe could help anyone.

    created a custom class and passed parameters .

    using Toybox.WatchUi as Ui;
    class CustomSelectable extends Ui.Selectable {
    function initialize(params) {
    Selectable.initialize(params);
    }
    }

    <drawable id="NameIdentifier" class="CustomSelectable">
    <param name="x">0</param>
    <param name="y">0</param>
    <param name="width">100</param>
    <param name="height">100</param>
    <param name="stateDefault">Gfx.COLOR_BLACK</param>
    </drawable>


    just my 2 cents

    MArco
  • I know I have to set the attribute identifier but i guess it's not possible via xml. what I thought is to set something like this

    Exactly. As I mentioned, I'm not seeing a way to specify the identifier attribute for selectables. I'm betting this is a bug, but I haven't had a chance to verify. AFAICT, the compiler should allow the identifier attribute (or a <param name="identifier" ...> element) and it should place it into the dict that is passed to the Selectable that the resource compiler instantiates.


    My goal is to have a selectable zone , more or less like a button. I'm pretty confident I can do without using resource compiler... but it is really useful and i would like to use it.

    Then it seems like you want a button.

    Since nobody replied I give u my solution , maybe could help anyone. created a custom class and passed parameters.

    Yes. This is the other option that I suggested. It really does seem that you want a button. If that is the case, then the actual solution should be to use a button. That said, this workaround should not be necessary. I'll file a ticket to get this looked at.

    Travis

  • Hi travis,
    My goal is to have a selectable zone , more or less like a button. I'm pretty confident I can do without using resource compiler... but it is really useful and i would like to use it.
    MArco


    I'm a bit old school on this (I did it before selectables), but on touch devices, I know the bounds of a "button" I draw and look for a tap inside that area and just act on that.

  • Former Member
    Former Member
    yes it is a button but with a drawable list element instead of bitmap , if it is possibile to handle like that I'll change it.