Closed qbazd closed 6 years ago
A gobject.Value constructor supporting RGBA is currently missing.
For now you can use this workaround:
auto color = new RGBA(1.0,1.0,1.0,1.0);
auto val = new Value();
val.init(RGBA.getType());
val.setPointer(color.getRGBAStruct());
store.setValue( it, COLUMN_COLOR, val);
Thank you for response.
Solution you gave, generated asserition:
val.setPointer(color.getRGBAStruct());
GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed
But... (I am new in GTKD, so be patient, as I've learned more about GTK itself), color can be set with attributes (https://developer.gnome.org/gtk3/stable/GtkCellRendererText.html):
String version works,
paramsStore = new TreeStore( [GType.STRING, GType.STRING]);
...
column1.addAttribute(cell_text1, "background", 1);
I still can't get it working with Gdk.RGBA or Gdk.Color.
Storing color as text isn't the most optimal solution, but works.
Hope it saves someone some time.
Reopened, as i defiantly want to add a gobject.Value constructor that accepts things like a RGBA color.
Sounds fair. I also had doubts about closing the issue. As solution didn't solve the root of problem.
While playing around with Gst_mediaplayer, trying to make it play RTSP stream. NO SUCCESS what so ever with creating working pipe.
Found same problems in other places. Is it the problem that some classes do not derive from ObjectG? For example gstreamer/Caps.d.
GstCaps is not derived from GObject on the C side, so it's correct that it also isn't on the D side of things.
I still possibly misusing it or something else?
paramsStore = new TreeStore( [GType.STRING,GType.STRING,GType.STRING,GType.STRING,RGBA.getType()] );
//...
auto color = new RGBA(1.0,1.0,1.0,1.0);
paramsStore.setValue( it, Columns.COLOR, color);
gives compile error:
../../../GtkD/generated/gtkd/gobject/Value.d(97,9): Error: undefined identifier Type, did you mean enum GType?
../../../GtkD/generated/gtkd/gtk/TreeStore.d(140,13): Error: template instance `gobject.Value.Value.__ctor!(RGBA)` error instantiating
source/parameterstreeview.d(140,27): instantiated from here: setValue!(RGBA)
and this:
paramsStore = new TreeStore( [GType.STRING,GType.STRING,GType.STRING,GType.STRING,RGBA] );
//...
auto color = new RGBA(1.0,1.0,1.0,1.0);
paramsStore.setValue( it, Columns.COLOR, color);
../../../GtkD/generated/gtkd/gobject/Value.d(97,9): Error: undefined identifier Type, did you mean enum GType?
../../../GtkD/generated/gtkd/gtk/TreeStore.d(140,13): Error: template instance `gobject.Value.Value.__ctor!(RGBA)` error instantiating
source/parameterstreeview.d(136,27): instantiated from here: setValue!(RGBA)
source/parameterstreeview.d(144,89): Error: type RGBA has no value
I seem to have messed up the imports before committing, should be fixed now.
Compiles, but no color change and some info from GTK:
code:
paramsStore = new TreeStore( [GType.STRING,GType.STRING,GType.STRING,GType.STRING, RGBA.getType()] );
// without getType(), I get " Error: type RGBA has no value"
TreeViewColumn column = new TreeViewColumn();
column.setTitle( "Name" );
appendColumn(column);
CellRendererText cell_text = new CellRendererText();
column.addAttribute(cell_text1, "foreground-rgba", Columns.COLOR);
//...
auto color = new RGBA(1.0,1.0,1.0,1.0);
paramsStore.setValue( it, Columns.COLOR, color);
and I got in runtime:
Gtk-CRITICAL **: gtk_cell_area_attribute_connect: assertion 'gtk_cell_area_has_renderer (area, renderer)' failed
Still color by string is the only way.
It works for me.
Did you add the CellRendererText to the column?
column.packStart(cell_text, 0 );
I assume the cell_text1
vs cell_text
is a typo/copy and paste error.
Yes it's a copy/paste error. I think I'll prepare some stripped example.
My fault.
Indeed there was an error with renderer names.
I've modified example DemoMultiCellRenderer, to support color text in column with RGBA. I could make separate example or make the pull request with above modification. What is preferred?
The modified demo whould be fine.
I am trying to add background color attribute to cell of TreeStore.
Attempt1
Error produced while compilation:
Attempt2
Error produced while compilation:
There is example of storing PixBuf in Gtkd in TreeStore and its OK. https://github.com/Racinettee/corald/blob/master/source/coral/component/FileTree.d
Am I missing something about storing Gdk.RGBA in TreeStore?
All the best Jakub Zdroik