After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 747121 - gtklabel.c: add note about set-markup property in gtk_set_markup()
gtklabel.c: add note about set-markup property in gtk_set_markup()
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Documentation
3.15.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-03-31 15:34 UTC by Bastian Ilsø
Modified: 2015-04-06 02:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patchv1: add note concerning set-markup in gtk_set_markup (763 bytes, patch)
2015-03-31 15:34 UTC, Bastian Ilsø
none Details | Review
note about that gtk_set_markup turns set-markup to true (778 bytes, patch)
2015-03-31 15:58 UTC, Bastian Ilsø
none Details | Review
add a note explaining under what conditions, gtk_label_set_markup() automatically sets set-markup to true. (1.03 KB, patch)
2015-03-31 22:50 UTC, Bastian Ilsø
none Details | Review
add a note explaining under what conditions, gtk_label_set_use_markup() automatically sets use-markup to true. (1.03 KB, patch)
2015-04-01 11:56 UTC, Bastian Ilsø
none Details | Review
Note the side effects of GtkLabel text setters (3.49 KB, patch)
2015-04-04 12:57 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
Note the side effects of GtkLabel text setters / v2 (3.67 KB, patch)
2015-04-04 13:01 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review

Description Bastian Ilsø 2015-03-31 15:34:35 UTC
Created attachment 300673 [details] [review]
patchv1: add note concerning set-markup in gtk_set_markup

It would be convenient if the documentation for gtk_set_markup() mentions that it needs the set-markup property to be true for your GtkLabel, before gtk_set_markup() produce any visible results.

can i use '@set-markup' to create a link to the set-markup property in the document?
Comment 1 Emmanuele Bassi (:ebassi) 2015-03-31 15:43:18 UTC
Review of attachment 300673 [details] [review]:

::: gtk/gtklabel.c
@@ +2718,3 @@
  * g_free (markup);
  * ]|
+ * Note that the markup is not applied to the text unless the @set-markup property

You should leave an empty line between the ]| and the next paragraph.

Also, that's not how property linking works.

To link to a GObject property, use the #TypeName:property-name syntax.

The text is also misleading: using gtk_label_set_markup() will set the GtkLabel:use-markup property as a side effect.
Comment 2 Bastian Ilsø 2015-03-31 15:58:47 UTC
Created attachment 300675 [details] [review]
note about that gtk_set_markup turns set-markup to true

Interesting.

My background is that I used gtk_set_markup in a Javascript program, but in there, gtk_set_markup does not do anything unless you explicitly make sure 'set-markup' should be true.

I could mention that in gtklabel.c too, but I assume this gtk+ API documentation is C specific or?
Comment 3 Emmanuele Bassi (:ebassi) 2015-03-31 16:09:36 UTC
I assume 'gtk_set_markup' is really 'gtk_label_set_markup'.

I just tested with GJS, and this:

```
  const Gtk = imports.gi.Gtk;

  Gtk.init(null);

  let w = new Gtk.Window();
  w.set_default_size(200, 200);
  w.connect('destroy', function() { Gtk.main_quit(); });

  let l = new Gtk.Label();
  l.set_markup('<b>Foo</b> and <i>bar</i>');
  w.add(l);

  w.show_all();

  Gtk.main();
```

generates the expected result: http://i.imgur.com/hgMH4cJ.png

If you're setting the label with markup with properties, you will need:

```
  let l = new Gtk.Label({ label: '<b>foo</b> and <i>bar</i>', use_markup: true });
```

Because GtkLabel does not have a property that sets both the label and the use-markup properties at the same time.
Comment 4 Bastian Ilsø 2015-03-31 16:42:08 UTC
my case bug 745743 in which I had to explicitly do 'this._label.set_use_markup(true)' in order to get the markup visible.

https://bugzilla.gnome.org/show_bug.cgi?id=745743#c10

https://bugzilla.gnome.org/attachment.cgi?id=300671&action=diff

but I guess this was some special case or?
Comment 5 Emmanuele Bassi (:ebassi) 2015-03-31 16:53:52 UTC
It's not a special case. Like I said above: GtkLabel does not have a property that sets both the label and the use-markup properties at the same time. If you use the 'label' property directly, you'll also need to set the 'use-markup' property.

If you want to document that, you'll need to change the documentation of the GtkLabel:label property, for instance to something like this:

```
The text of the label.

If the contents of the string use Pango markup, you will need to set the #GtkLabel:use-markup property to %TRUE in order for the label to use the markup attributes.
```
Comment 6 Bastian Ilsø 2015-03-31 22:50:12 UTC
Created attachment 300715 [details] [review]
add a note explaining under what conditions, gtk_label_set_markup() automatically sets set-markup to true.

From a user-of-documentation point of view, I would likely not have looked for
documentation of the GtkLabel:label property to change markup though. I'm suggesting to add this to gtk_set_use_markup() because that is the first encounter of the word 'markup' on the page for GtkListBox (and the first one I personally stumbled upon which sounded like it would solve all my problems without further work).

Attached suggestion is a small note, added to gtk_label_set_markup() documentation. I hope I explained the behavior of gtk_label_set_markup() correctly.
Comment 7 Matthias Clasen 2015-04-01 11:33:07 UTC
You had me confused here. The boolean property you're looking for is called "use-markup", not "set-markup"
Comment 8 Bastian Ilsø 2015-04-01 11:56:39 UTC
Created attachment 300733 [details] [review]
add a note explaining under what conditions, gtk_label_set_use_markup() automatically sets use-markup to true.

super sorry about that! use-markup property and gtk_label_set_use_markup(). yes.
Comment 9 Emmanuele Bassi (:ebassi) 2015-04-04 12:43:36 UTC
Review of attachment 300733 [details] [review]:

::: gtk/gtklabel.c
@@ +2719,3 @@
  * ]|
+ *
+ * When called, gtk_set_use_markup() will set the #GtkLabel:use-markup property

Wrong function name: it's gtk_label_set_markup().

@@ +2720,3 @@
+ *
+ * When called, gtk_set_use_markup() will set the #GtkLabel:use-markup property
+ * to true for the GtkLabel it takes as input. However, if the #GtkLabel

"true" should be "%TRUE".

Also, the wording is a bit awkward. I'd say:

This function will set the #GtkLabel:use-markup property to %TRUE as a side effect.

@@ +2721,3 @@
+ * When called, gtk_set_use_markup() will set the #GtkLabel:use-markup property
+ * to true for the GtkLabel it takes as input. However, if the #GtkLabel
+ * is constructed with properties, #GtkLabel:use-markup should be set when

The wording "is constructed with properties" does not really apply: if you use properties you can do that after construction.

I would say:

If you use the #GtkLabel:label property to set the contents of the label, you should also ensure that you set the #GtkLabel:use-markup accordingly.

I would also change the description of the "label" property, since we're linking to it inside this function. Right not, the description is taken from the GParamSpec, so you'd have to add a gtk-doc stanza, like this:

/**
 * GtkLabel:label:
 *
 * The contents of the label.
 *
 * If the string contains [Pango XML markup][PangoMarkupFormat], you will have
 * to set the #GtkLabel:use-markup property to %TRUE in order for the label to
 * display the markup attributes. See also gtk_label_set_markup() for a
 * convenience function setting both this property and #GtkLabel:use-markup
 * at the same time.
 */

This way we close the loop between properties and accessors.
Comment 10 Emmanuele Bassi (:ebassi) 2015-04-04 12:45:27 UTC
Review of attachment 300733 [details] [review]:

Additionally, the commit message is a bit awkwardly worded:

Something better would be:

  docs: Note that gtk_label_set_markup() sets use-markup

  Add a note explaining the side effects of gtk_label_set_markup().
Comment 11 Emmanuele Bassi (:ebassi) 2015-04-04 12:57:26 UTC
Created attachment 300942 [details] [review]
Note the side effects of GtkLabel text setters

This is a bit more comprehensive documentation patch that covers the side effects of set_markup() and set_text(), as well as the various properties.
Comment 12 Emmanuele Bassi (:ebassi) 2015-04-04 13:01:21 UTC
Created attachment 300944 [details] [review]
Note the side effects of GtkLabel text setters / v2

The "label" property should also mention "use-mnemonics"