How to bind GtkColorButton's rgba with its string presentation?

How to bind GtkColorButton’s rgba with its string presentation?

the value generated by GdkRGBA.to_string();

Just using the transform function to do that, here is the example code:

private void bind_setting_values()
{
    var app_setting = ServiceHelper.setting();
    var bind_flags = BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL;

    app_setting.datagrid.bind_property("color_bg_dark", this.btn_color_back_dark, "rgba", bind_flags, this.string_to_rgba, this.rgba_to_string);
    app_setting.datagrid.bind_property("color_bg_light", this.btn_color_back_light, "rgba", bind_flags, this.string_to_rgba, this.rgba_to_string);
    app_setting.datagrid.bind_property("color_bg_dirty", this.btn_color_back_dirty, "rgba", bind_flags, this.string_to_rgba, this.rgba_to_string);
}


private bool rgba_to_string(Binding binding, Value from_value, ref Value to_value)
{
    if (from_value.holds(typeof(Gdk.RGBA))) {
        Gdk.RGBA* rgba = (Gdk.RGBA*)from_value.get_boxed();
        to_value.set_string(rgba->to_string());
    } else {
        to_value.set_string("");
    }
    return true;
}

private bool string_to_rgba(Binding binding, Value from_value, ref Value to_value)
{
    Gdk.RGBA rgba = new Gdk.RGBA();
    if (from_value.holds(typeof(string))) {
        rgba.parse(from_value.get_string());
    }
    to_value.set_boxed(&rgba);

    return true;
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.