]> git.tdb.fi Git - libs/gltk.git/commitdiff
Unify the behavior of value change signals
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Jun 2013 14:25:50 +0000 (17:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 27 Jun 2013 14:25:50 +0000 (17:25 +0300)
All widgets with such signals now emit them if the value is changed
programmatically, but only if it actually changed.

source/list.cpp
source/toggle.cpp

index b969ec038994bbe9d9609bf558b4d0b732e57ca4..296709ce4f300b773a2035acade69ae053268725 100644 (file)
@@ -117,7 +117,7 @@ void List::set_selected_index(int i)
                items[sel_index]->set_active(false);
        if(i<0)
                sel_index = -1;
-       else
+       else if(i!=sel_index)
        {
                sel_index = i;
                items[sel_index]->set_active(true);
index fe6518dda722b57fc6ffda3c2481d4e42ae63047..cb80880787e75162f3f03cc27cbe89444f17cf71 100644 (file)
@@ -48,6 +48,8 @@ void Toggle::exclude_siblings()
 
 void Toggle::set_value(bool v)
 {
+       bool old_value = value;
+
        value = v;
        if(value)
        {
@@ -57,6 +59,9 @@ void Toggle::set_value(bool v)
        }
        else
                clear_state(ACTIVE);
+
+       if(value!=old_value)
+               signal_toggled.emit(value);
 }
 
 void Toggle::rebuild_special(const Part &part)
@@ -76,10 +81,7 @@ void Toggle::button_release(int x, int y, unsigned btn)
        if(pressed && btn==1)
        {
                if(geom.is_inside_relative(x, y) && (!value || !exclusive))
-               {
                        set_value(!value);
-                       signal_toggled.emit(value);
-               }
 
                pressed = false;
        }