elementary / switchboard-plug-keyboard

Switchboard Keyboard Plug
GNU General Public License v2.0
28 stars 22 forks source link

Use get_row_at_index #493

Closed danirabbit closed 8 months ago

danirabbit commented 8 months ago

Can't use get_children in GTK4, so use get_row_at_index where it makes sense. Use remove instead of destroy to avoid an infinite loop in GTK 4 where widgets are destroyed but not removed

danirabbit commented 8 months ago

@jeremypw ah I didn't realize this list didn't reflect the same number of items in the list. We can use observe children in GTK 4, but docs say it's expensive. So I'm avoiding the list here unless we need it

jeremypw commented 8 months ago

@danirabbit You could try:

        int index = 0;
        while (list.get_row_at_index (index) != null) { index++; }
        unowned var first_child = (DisplayRow) list.get_row_at_index (0);
        unowned var last_child = first_child;
        if (index > 1) {
             last_child = (DisplayRow) list.get_row_at_index (index - 1);
        }

        first_child.up_button.sensitive = false;
        last_child.down_button.sensitive = false;
danirabbit commented 8 months ago

@jeremypw ah yeah you're smart. It's probably plenty cheap enough to just iterate every time for a list that's probably pretty short

jeremypw commented 8 months ago

Yes. Tbh observe_children () is probably not that expensive for short lists. But we can go with this for now.