gtkd-developers / GtkD

GtkD is a D binding and OO wrapper of GTK+ originally created by Antonio Monteiro
http://gtkd.org
Other
322 stars 71 forks source link

Adding color attribute to cell/row of treestore #231

Closed qbazd closed 6 years ago

qbazd commented 6 years ago

I am trying to add background color attribute to cell of TreeStore.

//treestore init
  auto store = new TreeStore( [
        GType.STRING,
        RGBA.getType,
    ] );

Attempt1

//setvalue
store.setValue( it, COLUMN_COLOR, new RGBA(1.0,1.0,1.0,1.0));

Error produced while compilation:

../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gtk/TreeStore.d(146,13): Error: none of the overloads of __ctor are callable using argument types (RGBA), candidates are:
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(72,9):        gobject.Value.Value.this(GValue* gValue, bool ownedRef = false)
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(79,9):        gobject.Value.Value.this()
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(95,2):        gobject.Value.Value.this(string value)
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(85,2):        gobject.Value.Value.__ctor(GOBJECT)(GOBJECT obj) if (is(GOBJECT : ObjectG))
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(103,2):        gobject.Value.Value.__ctor(BOOL)(BOOL value) if (isBoolean!BOOL)
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(112,2):        gobject.Value.Value.__ctor(INT)(INT value) if (isIntegral!INT)
../../../.dub/packages/gtk-d-3.7.5/gtk-d/generated/gtkd/gobject/Value.d(145,2):        gobject.Value.Value.__ctor(FLOAT)(FLOAT value) if (isFloatingPoint!FLOAT)
DemoMultiCellRenderer.d(60,23): Error: template instance `gtk.TreeStore.TreeStore.setValue!(RGBA)` error instantiating
/usr/bin/dmd failed with exit code 1.

Attempt2

//setvalue failed
store.setValue( it, COLUMN_COLOR, GValue(new RGBA()));

Error produced while compilation:

DemoMultiCellRenderer.d(59,50): Error: cannot implicitly convert expression new RGBA(1.00000, 1.00000, 1.00000, 1.00000) of type gdk.RGBA.RGBA to GType
/usr/bin/dmd failed with exit code 1.

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

MikeWey commented 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);
qbazd commented 6 years ago

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.

MikeWey commented 6 years ago

Reopened, as i defiantly want to add a gobject.Value constructor that accepts things like a RGBA color.

qbazd commented 6 years ago

Sounds fair. I also had doubts about closing the issue. As solution didn't solve the root of problem.

qbazd commented 6 years ago

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.

MikeWey commented 6 years ago

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.

qbazd commented 6 years ago

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
MikeWey commented 6 years ago

I seem to have messed up the imports before committing, should be fixed now.

qbazd commented 6 years ago

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.

MikeWey commented 6 years ago

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.

qbazd commented 6 years ago

Yes it's a copy/paste error. I think I'll prepare some stripped example.

qbazd commented 6 years ago

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?

MikeWey commented 6 years ago

The modified demo whould be fine.