Sign up

GTK Notebook Tab Visibility?

Hi Mike,

I'm messing around with the Notebook widget and there doesn't seem to be a way to see the tabs as tabs. The tab text and the blue 'selected' indicator show up, but the actual graphic treatment of tabs doesn't.

I've seen this in the PyGTK demo, but isn't it possible in GtkD? I checked the demo you wrote for the package and it's graphically the same as what I'm getting. Here's the PyGTK demo I'm referring to (you'll have to scroll to the bottom to see the screenshots).

Re: GTK Notebook Tab Visibility?

On 05-09-2019 14:43, Ron Tarrant wrote:

Hi Mike,

I'm messing around with the Notebook widget and there doesn't seem to be a way to see the tabs as tabs. The tab text and the blue 'selected' indicator show up, but the actual graphic treatment of tabs doesn't.

I've seen this in the PyGTK demo, but isn't it possible in GtkD? I checked the demo you wrote for the package and it's graphically the same as what I'm getting. Here's the PyGTK demo I'm referring to (you'll have to scroll to the bottom to see the screenshots).

How the tabs are rendered depends on the gtk theme that is used, at
least with the default adwita theme you don't get the traditional tabs
but only the texts and a blue selected indicator.

Re: GTK Notebook Tab Visibility?

On Thu, 5 Sep 2019 20:17:13 +0200, Mike Wey wrote:

How the tabs are rendered depends on the gtk theme that is used, at
least with the default adwita theme you don't get the traditional tabs
but only the texts and a blue selected indicator.

Thanks, Mike.

My first move from here would normally have been to use this bit of code to use CSS for colouring the tab (once I tracked down the CSS name for tabs):

class CSS
{
	import gdk.Display;
	import gdk.Screen;
	import gtk.StyleContext;
	import gtk.CssProvider;
	
	string cssPath = "./css/button_label.css";

	this()
	{
		CssProvider provider = new CssProvider();
		provider.loadFromPath(cssPath);
		
		Display display = Display.getDefault();
		Screen screen = display.getDefaultScreen();
		StyleContext.addProviderForScreen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

	} // this()

} // CSS

However, I'm also working towards making all examples GTK4 compliant which means not using the GdkScreen since its use is about to be deprecated. I know there's an alternative method using addProvider(), pretty much the same thing as above, but on a widget-by-widget basis instead of application wide. I've been looking for an example of how to use addProvider(), but I'm not finding anything.

I've got this so far, but there's no association between the provider and the widget:

class CSSButton : Button
{
	CSS css;
	
	this(string textLabel, string cssName)
	{
		super(textLabel);
		setName(cssName);
		css = new CSS(); // enable CSS
		// ??????

	} // this()
	
} // class CSSButton


class CSS
{
	import gtk.StyleContext;
	import gtk.CssProvider;
	
	string cssPath = "./css/button_label.css";

	this()
	{
		CssProvider provider = new CssProvider();
		StyleContext styleContext = new StyleContext();
		provider.loadFromPath(cssPath);
		
		styleContext.addProvider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

	} // this()

} // CSS

Questions:

  1. Do you know how to set up this association?
  2. Do you know the CSS name for the tab? Is it as simple as 'tab'?

Re: GTK Notebook Tab Visibility?

On 05-09-2019 21:52, Ron Tarrant wrote:

Questions:
1. Do you know how to set up this association?
2. Do you know the CSS name for the tab? Is it as simple as 'tab'?

  1. If the widget is a container use the foreach_ function to
    recursively set the association.

  2. Yes it is simply named tab.

Re: GTK Notebook Tab Visibility?

On Thu, 5 Sep 2019 23:01:31 +0200, Mike Wey wrote:

  1. If the widget is a container use the foreach_ function to

recursively set the association.

Thanks, but I don't know which function to use to set the association. When using addProviderForScreen(), the association isn't actually set by a function, it's simply implied by instantiating the CSS object in the TestRigWindow class like this:

class TestRigWindow : MainWindow
{
	string windowTitle = "CSS & Button Labels";
	AppBox appBox;
	CSS css;
	
	this()
	{
		super(windowTitle);
		addOnDestroy(&quitApp);
		
		css = new CSS(); // enable CSS
		
		appBox = new AppBox();
		add(appBox);
		
		showAll();

	} // this() CONSTRUCTOR
	
		
	void quitApp(Widget widget)
	{
		writeln("Bye.");
		Main.quit();
		
	} // quitApp()

} // class myAppWindow

For whatever reason, that's enough to make it work when using addProviderForScreen(), but addProvider() seems to need something else. That's why I'm thinking there must be a function that makes the association.

I looked through the Widget class and found a getStyleContext() function, but no setStyleContext() which struck me as odd. The only place such a function exists is in the NumerableIcon class and I don't see any relationship between that and a common Widget.

Suggestions?

Re: GTK Notebook Tab Visibility?

On Fri, 06 Sep 2019 00:12:48 GMT, Ron Tarrant wrote:

Thanks, but I don't know which function to use to set the association. When using addProviderForScreen(), the association isn't actually set by a function, it's simply implied

I was looking at it from the wrong angle. This works:

class CSSLabel : Label
{
	string cssPath = "./css/button_label.css";
	StyleContext styleContext;
	CssProvider provider;
	
	this(string textLabel, string cssName)
	{
		super(textLabel);
		
		// css stuff
		setName(cssName);
		provider = new CssProvider();
		provider.loadFromPath(cssPath);
		styleContext = getStyleContext();
		styleContext.addProvider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
		
	} // this()

I just wasn't going far enough. I'll come up with a more OOP-like version before I take this to the blog. Thanks, Mike.