Changeset 49

Show
Ignore:
Timestamp:
04/23/07 23:22:26 (1 year ago)
Author:
baxissimo
Message:

Fixed bug with RadioGroups?. They were failing to update their member buttons when the RadioGroup? was changed programattically via RadioGroup?.checked_item=x or RadioGroup?.value=x.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/luigi/gui.d

    r48 r49  
    19701970 
    19711971    int checked_item(int v) { 
     1972        writefln("checked item(%d), cur = %d", v, m_checkedItem); 
    19721973        if (v == m_checkedItem) { return m_checkedItem; } 
    19731974        m_checkedItem = v; 
     
    19881989    } 
    19891990 
     1991    private class _ButtonUpdater { 
     1992        int id; 
     1993        Button button; 
     1994        void update(int v) { 
     1995            if (id == v) { button.value=1; } 
     1996            else { button.value=0; } 
     1997        } 
     1998    } 
     1999 
    19902000    /** Have button b join this group, using value val */ 
    19912001    void add(Button b, int val) { 
    1992         m_obj2id[b] = val; 
     2002        // We observe the button's value 
    19932003        b.value_changed.connect( &_member_value_changed ); 
     2004        // The button value should also observe us 
     2005        auto bup = new _ButtonUpdater; 
     2006        bup.id = val; 
     2007        bup.button = b; 
     2008        m_obj2id[b] = bup; 
     2009        selection_changed ~= &bup.update; 
    19942010        // Leave this up to the user? 
    19952011        b.is_toggle = true; 
     
    20532069    Button[] opIndex(int v) { 
    20542070        Button [] ret; 
    2055         foreach(Button b, int val; m_obj2id) { 
    2056             if (v==val) ret ~= b; 
     2071        foreach(Button b, _ButtonUpdater val; m_obj2id) { 
     2072            if (v==val.id) ret ~= b; 
    20572073        } 
    20582074        return ret; 
     
    20632079     */ 
    20642080    int opIndex(Button b) { 
    2065         int *p = (b in m_obj2id); 
    2066         if (p) return *p
     2081        _ButtonUpdater *p = (b in m_obj2id); 
     2082        if (p) return p.id
    20672083        return int.min; 
    20682084    } 
     
    20742090        int minv = int.max; 
    20752091        foreach(v; m_obj2id.values) { 
    2076             if (v < minv) minv = v
     2092            if (v.id < minv) minv = v.id
    20772093        } 
    20782094        return minv; 
     
    20832099        int maxv = int.min; 
    20842100        foreach(v; m_obj2id.values) { 
    2085             if (v > maxv) maxv = v
     2101            if (v.id > maxv) maxv = v.id
    20862102        } 
    20872103        return maxv; 
     
    21262142private: 
    21272143    int m_checkedItem = int.min; 
    2128     int[Button] m_obj2id; 
     2144    _ButtonUpdater[Button] m_obj2id; 
    21292145} 
    21302146