On Fri, 19 Oct 2018 15:28:56 GMT, aedt wrote:
On Thu, 18 Oct 2018 19:46:43 +0200, Mike Wey wrote:
On 10/18/18 9:37 AM, aedt wrote:
Okay, I have this ListStore called StorageLS that is supposed to have columns for name, capacity, usage and a GtkProgressBar that visualizes the space usage. Now I want to create a ListStore but the
gtkc.gobjectypes: GType
enum does not seem to have anything for it. I'm stuck.... Code ...
How should I proceed?
Most classes have a
getType
function to get their GType, so for the
GType of a gtk.ProgressBar you would use:ProgressBar.getType()
.You can also look at
gtk.CellRendererProgress
if you want to display a
progress bar in a tree or list.Thanks that worked but now I'm stuck with another problem. How can I construct a TreeViewColumn that renders a CellRendererProgress? I can't find a proper constructor for it. Here's what I got
public enum Columns { id, deviceName, capacityGB, usedGB, usageBar } class StorageLS : ListStore { public: this() { // uint id, in string deviceName, double capacityGB, double usedGB // construct a ListStore with corresponding GTypes // note that the last item in the array is for a derived item, usageBar super([GType.UINT, GType.STRING, GType.DOUBLE, GType.DOUBLE, (new ProgressBar()).getType()]); } void addStorage(uint id, in string deviceName, double capacityGB, double usedGB) { TreeIter iter = this.createIter(); // base ListStore.createIter() this.setValue(iter, Columns.id, id); // base ListStore.setValue() this.setValue(iter, Columns.deviceName, deviceName); this.setValue(iter, Columns.capacityGB, capacityGB); this.setValue(iter, Columns.usedGB, usedGB); this.setValue(iter, Columns.usageBar, () { auto pb = new ProgressBar(); pb.setFraction(usedGB / capacityGB); return pb; }()); } } class StorageTV : TreeView { import gtk.TreeViewColumn : TreeViewColumn; private: TreeViewColumn idCol, deviceNameCol, capacityGBCol, usedGBCol, usageBarCol; public: this(ref StorageLS storageListModel) { populate(storageListModel); } this() { } public void populate(ref StorageLS storageListModel) { import gtk.CellRendererText : CellRendererText; import gtk.CellRendererProgress : CellRendererProgress; idCol = new TreeViewColumn("ID", new CellRendererText(), "text", Columns.id); deviceNameCol = new TreeViewColumn("Device", new CellRendererText(), "text", Columns.deviceName); capacityGBCol = new TreeViewColumn("Capacity (GB)", new CellRendererText(), "text", Columns.capacityGB); usedGBCol = new TreeViewColumn("Used space (GB)", new CellRendererText(), "text", Columns.usedGB); usageBarCol = new TreeViewColumn("Usage", crp, "what goes here? And how am I supposed to know?", Columns.usageBar); this.appendColumn(idCol); this.appendColumn(deviceNameCol); this.appendColumn(capacityGBCol); this.appendColumn(usedGBCol); this.appendColumn(usageBarCol); this.setModel(storageListModel); }
I forgot
auto crp = new CellRendererProgress();