martedì 20 dicembre 2016

Modificare il widget segmented control

Il widget segmented control non è altro che un controllo che permette di selezionare una o più scelte da un elenco orizzontale:
Possiamo sfruttarlo per creare un sistema di votazione con le stelle, per fare questo vi basta creare un segmented control, chiamarlo giudizio e poi digitare i seguenti comandi nel message box:

set the itemcount of widget "giudizio" to 5
set multiplehilites of widget "giudizio" to true
set the itemstyle of widget "giudizio" to "icons"
set the itemicons of   widget "giudizio" to "star,star,star,star,star"   
set the hiliteditemicons of   widget "giudizio" to "star,star,star,star,star"

Potreste farloanche dal pannello proprietà, ma così è più semplice spiegare quali proprietà modificare. Otterrete quindi questo:
Poi mettete questo codice nello script widget:

local srating
on hiliteChanged
   -- Find the rightmost item that changed. This is
   -- the segment that the user clicked
   put the hilitedItems of me into tHilited #esempio 1,2,3
   repeat with tSegment = 5 down to 1
      if tSegment is among the items of tHilited then
         if tSegment > sRating then
            put tSegment into sRating
            exit repeat
         end if
      else
         if tSegment <= sRating then
            put tSegment into sRating
            exit repeat
         end if
      end if   
   end repeat
   
   -- Highlight all the segments up to and
   -- including the one that was clicked
   repeat with tSegment = 1 to sRating
      put tSegment & comma after tNewHilite
   end repeat
   -- Remove trailing comma
   delete char -1 of tNewHilite
   set the hilitedItems of me to tNewHilite
end hiliteChanged

e avrete il controllo per le votazioni cercato:

Questo è solo un esempio delle possibilità che offre questo widget.

Nessun commento:

Posta un commento