Re: Close button in GtkNotebook

2017-05-29 Thread Stefan Salewski
On Sun, 2017-05-28 at 16:08 -0300, Augusto Fraga Giachero wrote:
> I've been playing with Glade and GtkNotebook for while, and I
> couldn't
> figure a way to enable the close button on the tabs

I guess what you want is what gedit does with the tabs?

The gedit code has been modified a few times in the last years, I am
currently using code from GTK 3.20 in my Nim editor. See

# from 3.20 gedit-documents-panel.c


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Recoloring of symbolic icons

2017-05-29 Thread Arnaud
Dear Gtk+,

just following up with myself. I struggled and struggled, until finally
giving up on recoloring images using the 'color' CSS property. This
attribute seems to be ignored in most cases, so I guess it's just not
supposed to be used the way I wanted to use it.

In the end, the only case where I managed to re-color my icons using the
CSS property 'color' is when I loaded them using
'gtk_image_new_from_icon_name()' with png files. Later on I switched to
'gtk_image_new_from_resource()', and I lost the re-coloring forever.

My solution right now is to color my icons manually, and therefore have
different set of files for different colors. It work just as good, but
it's less elegant.

It's still unclear to me if I was abusing the 'color' attribute (so it's
OK that I failed to use it), or if I was using it in a legitimate way
(and therefore, why so much pain ?).

Cheers guy, have a nice day !

Arnaud


On 05/23/2017 09:32 AM, El Boulangero wrote:
> Hi Gtk+,
>
> Short story:
>
> In my application, I have use custom symbolic icons, and I want to
> recolor them with the css.
>
> What I observe right now is that, as long as my icons are loaded from a
> svg file, they are not recolored and remain grey. However, if I render
> my icons to png with 'gtk-encode-symbolic-svg', these png files are
> loaded instead, and recolored.
>
> I'm wondering if this behavior is expected, as I couldn't find any
> information on that matter.
>
> 
>
> Long story:
>
> I'm building an application in which I have dice buttons. Depending if
> the button is clicked or not, I want to change the color of the
> background of the dices, and also the color of the dots on the dices.
>
> I'm trying to implement that by using symbolic icons. I have svg dice
> icons, and typically a dot looks like that in the svg file:
>
>  style="display:inline;fill:#bebebe;fill-opacity:1;stroke:none"/>
>
> My icon is named 'dice-1-symbolic.svg', I load it with a call like this one:
>
> Gtk.Image.new_from_icon_name('dice-1-symbolic', size)
>
> I have a css that looks like that for my dicebutton.
>
> .dicebutton {
>   color: #ff;
>   background-color: #6199ff; }
>
> The idea is to recolor the dices by changing the css attributes.
>
> - What works: recoloring the background (aka changing 'background-color').
> - What doesn't work: recoloring the icon (aka changing 'color' has no
> effect).
>
> I tried again and again, and what I observe at the moment is that:
> - as long as I use a svg file as the source, the icon is not recolored
> - if, however, I render my svg to png using 'gtk-encode-symbolic-svg',
> the png is picked up instead of the svg, and the icon is then recolored
> according to the CSS.
>
> That's a bit puzzling to me. Moreover, my naive understanding was that a
> SVG was trivial to recolor (since it's just about changing the colors
> definitions in the file), while PNG was harder to recolor, since it's
> binary data. So, I thought that SVG were recolored first, then rendered
> to PNG with the right color.
>
> But it looks like it doesn't work like that, especially since I
> discovered that the icon theme on my system is full of '.symbolic.png'
> files, which makes me wonder, what's the point with the svg files in the
> end ? Are they used at all by Gtk ?
>
> So, I'm wondering if anyone could enlighten me a bit about how gtk
> handles this re-coloring. I didn't find the right piece of information yet.
>
> In the end, should I always render my svg to png ? Or is there a way to
> have my svg recolorized by the css ?
>
> Any advice welcome !
>
> Cheers,
> Arnaud
>

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Close button in GtkNotebook

2017-05-29 Thread Augusto Fraga Giachero

Hi Eric,

I was doing something similar with what you have proposed, it works but 
the end result differs from what I've observed on other gnome 
applications (Nautilus, Gedit etc...). I want my application to be as 
consistent and theme agnostic as possible. But the central idea of your 
implementation is right, you need to encapsulate the button and the 
label inside a GtkBox.


Stefan Salewski  wrote:

The gedit code has been modified a few times in the last years, I am
currently using code from GTK 3.20 in my Nim editor. See

# from 3.20 gedit-documents-panel.c


I've looked in the Gedit source code, and this seems to me the best 
solution. For future reference the tab creation occurs in the 
'row_create' function, the relevant bits are here:

---
generic_row->close_button = GTK_WIDGET (g_object_new (GTK_TYPE_BUTTON,
  "relief", 
GTK_RELIEF_NONE,

"focus-on-click", FALSE,
  NULL));

context = gtk_widget_get_style_context (generic_row->close_button);
gtk_style_context_add_class (context, "flat");
gtk_style_context_add_class (context, "small-button");

icon = g_themed_icon_new_with_default_fallbacks 
("window-close-symbolic");


---

Would be great to if the Gtk documentation included it, something like 
'Gtk Best Practices', so we don't keep re-inventing the wheel.


Thanks!
Augusto Fraga Giachero
On 28-05-2017 20:32, cecas...@aol.com wrote:


Hi Augusto,

This doesn't use glade but it might help out. You can add a label and 
button to a box and add it to the notebook tab. In the button 
"clicked" callback you can us the notebook pointer if you need that 
variable. If you want to be able to really customize the look and size 
of the button you could replace it with a drawing area and draw your 
own button.


Eric

/*
   gcc -Wall notebook1.c -o notebook1 `pkg-config --cflags --libs 
gtk+-3.0`

   Tested with GTK3.18 on Ubuntu16.04
*/

#include

static void button_clicked(GtkWidget *button, GtkWidget *notebook)
  {
g_print("Clicked\n");
  }
int main(int argc, char *argv[])
  {
gtk_init (&argc, &argv);

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Notebook");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *label1=gtk_label_new("page1");
GtkWidget *label2=gtk_label_new("page2");
GtkWidget *nb_label1=gtk_label_new("tab1");
GtkWidget *nb_label2=gtk_label_new("tab2");

GtkWidget *x_label=gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(x_label), "foreground='red'>x");


GtkWidget *button=gtk_button_new();
gtk_container_add(GTK_CONTAINER(button), x_label);

GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_pack_start(GTK_BOX(box), nb_label2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
gtk_widget_show_all(box);

GtkWidget *notebook=gtk_notebook_new();
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), label1, nb_label1);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), label2, box);

g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), 
notebook);


gtk_container_add(GTK_CONTAINER(window), notebook);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list