53 lines
1.1 KiB
Vala
53 lines
1.1 KiB
Vala
namespace StudySystemClient {
|
|
public class IterableBox<T> : Gtk.Box {
|
|
private List<T> elements;
|
|
|
|
public IterableBox(Gtk.Orientation orientation, int spacing) {
|
|
this.orientation = orientation;
|
|
this.spacing = spacing;
|
|
elements = new List<T>();
|
|
}
|
|
|
|
public new void append(T element) {
|
|
elements.append(element);
|
|
base.append(element as Gtk.Widget);
|
|
}
|
|
|
|
public new void remove(T element) {
|
|
elements.remove(element);
|
|
base.remove(element as Gtk.Widget);
|
|
}
|
|
|
|
public Iterator<Type, T> iterator() {
|
|
return new Iterator<Type, T>(elements);
|
|
}
|
|
|
|
public void sort(CompareDataFunc<T> comparison) {
|
|
elements.sort_with_data(comparison);
|
|
foreach (var element in elements)
|
|
reorder_child_after(element as Gtk.Widget, null);
|
|
}
|
|
|
|
public class Iterator<Type, T> {
|
|
private unowned List<T> head;
|
|
private unowned T value;
|
|
|
|
public Iterator(List<T> elements) {
|
|
head = elements;
|
|
}
|
|
|
|
public bool next() {
|
|
if (head.is_empty())
|
|
return false;
|
|
value = head.data;
|
|
head = head.next;
|
|
return true;
|
|
}
|
|
|
|
public unowned T get() {
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
}
|