In search of tutorial

Hello everyone,

I’m searching for a recent tutorial (GTK3 or GTK4) about how to create a new widget from scratch. I have found one but it’s for GTK2 and I have a hard time migrating it to GTK3.

The widget I have in mind is one capable to parse and render a Markdown document directly without converting it to HTML. For those who don’t know what a Markdown document is I recommend Markdown Guide website.

Thanks in advance

I’m also interested to know if a tutorial exists.

Creating a custom widget with GTK 3 is hard in my opinion, because some virtual functions to override are not super well documented.

For GTK 4 I think the reference manual is much better, but the way to create a custom widget is also totally different compared to GTK 3.

For a newly-written app, it’s strongly recommended to use GTK 4, especially with custom widgets.

Implementing a widget in GTK3 is vastly different from implementing a widget in GTK4.

For GTK3, there’s a short tutorial on the GNOME wiki. For GTK4 there are various examples in the GTK reference and the GTK demo application that is provided by GTK itself.

That’s not a great plan, because Markdown can embed HTML, which means you’ll need to render it to HTML anyway.

If you’re using a subset of Markdown, you don’t really need to implement a widget: you can use GtkTextView, parse the Markdown, and generate text tags.

Thanks Emmanuele,

The search engine I’m using didn’t pickup the link you provided, strange. Anyway it is very helpful.

About the Markdown widget, I have search about using a GtkTextView widget as a base for that but I didn’t find a way to have a table drawn with cell border and background color for the header cells unlike the example below :

Header Title
Cell 1 Cell 2
Cell 3 Cell 4

Also about the embed HTML tags inside a Markdown document you just need to mimic what a HTML renderer is doing inside your renderer. Which is not complicated at all and I have a working prototype written in PureBasic.

As being said in another post, Purebasic came with a Gadgets Library that doesn’t allow window management. Gadgets are created with a fixed sizes and positions. This work fine when the scale of the desktop is at 100%. If it is set to higher or lower value or just change the font size you end up with overlapping gadgets problem.

So now the challenge I’m facing now is rebuilding all of my apps using GTK3 (for the moment) directly instead of the supplied PureBasic Gadget library. Almost all of apps uses Markdown documents for the help files so the creation of a Markdown Widget make a lot of sense at least to me. So I’m going to give it a serious try anyway.

Thanks again.

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