GTK3 - CSS - C Language ( Tutorial-04 - Working with CSS )

preview_player
Показать описание
This is an Extension tutorial, because I forgot some important things which you need them when you are working with CSS. -=========================================================================-
I am a GTK fan and of course I do this videos for fun.
I thought that if I share my knowledge with others could help them to join in the GTK world.

All my Videos are based on my own understanding and mistakes could take place anytime.
Leave a comment with mistakes you may find.

Please Subscribe and Share my Channel.
Рекомендации по теме
Комментарии
Автор

Found a good topic for another Gtk3 CSS video.. Find a way to modify the font size(in a running Gtk3 app) with the Ctrl key held down and moving the mouse wheel.

Here's my attempt. Yeah that's right! You have to use styles and providers to modify the font size of a running app... There must be an easier way!


#! /usr/bin/env perl

use 5.26.1;

use local::lib;

use warnings;
use strict;
use utf8;
use constant MAX_FONT_SIZE => 200;
use constant MIN_FONT_SIZE => 12;

use Glib qw(TRUE FALSE);
use Gtk3 qw(init);

my $str = "label {font-size: ".MIN_FONT_SIZE."px;}";

sub getWheel {
my ($object, $event, $sp) = @_;
my ($ctrl, $mod) = @{$event->state};
my ($style, $provider) = @{$sp};

state $font_size = MIN_FONT_SIZE;

if ($ctrl eq q<control-mask> && $mod eq q<mod2-mask>) {
if ($event->direction eq q<up>) {
if ($font_size < MAX_FONT_SIZE) {
$font_size += 4;
$str = "label {font-size: ${font_size}px;}";
$provider->load_from_data ($str, length($str));
$style->add_provider($provider, 600);
}
}elsif ($event->direction eq q<down>){
if ($font_size > MIN_FONT_SIZE) {
$font_size -= 4;
$str = "label {font-size: ${font_size}px;}";
$provider->load_from_data ($str, length($str));
$style->add_provider($provider, 600);
}
}
}

FALSE;
}


my $window =
my $label = Gtk3::Label->new(q<Hello>);
my $provider = Gtk3::CssProvider->new();

$provider->load_from_data ($str, length($str));
my $style = $label->get_style_context();
$style->add_provider($provider, 600);



=> sub{Gtk3->main_quit; FALSE});
=> \&getWheel, [$style, $provider]);

$window->set_default_size(500, 300);

$window->add($label);

$window->show_all();

Gtk3->main;


Stack OverFlow member posted a better solution using Pango!

gerardgauthier
Автор

Got it working and I think I understand the basics of the CssProvider and company thanks to Gtk Inspector and Perli11doc(I use Perl and Gtk3. You think the docs are bad for C, just try Perl's Gtk3 docs). I was basically trying to make a textview screen for viewing Perl help files.. Here's a the preliminary hard-coded example of what I wanted.


help.css

text {
background-color: rgb(0, 0, 0);
color: rgb(0, 255, 0);
}

textview {
font-size: 40px;
}


Perl file

#! /usr/bin/env perl

use local::lib;

use warnings;
use strict;
use utf8;

use Glib qw(TRUE FALSE);
use Gtk3 qw(init);

sub killKey {
my ($object, $event) = @_;
my $c = chr ($event->keyval);
if ($c eq 'q') {
Gtk3->main_quit;
}
}

my $window =
my $scrWin = Gtk3::ScrolledWindow->new();
my $tView = Gtk3::TextView->new();
my $provider = Gtk3::CssProvider->new();



my $style = $tView->get_style_context();
$style->add_provider($provider, 600);

my $str = `perldoc -T -t -f split 2>&1`;

my $buffer = $tView->get_buffer();
$buffer->set_text($str);
my $strIter = $buffer->get_start_iter();

$tView->set_editable(FALSE);

$scrWin->add($tView);



=> sub{Gtk3->main_quit; FALSE});
=> \&killKey);

$window->set_title(q<Function Help>);

$window->set_default_size(500, 300);
$window->set_border_width(0);
$window->fullscreen;

$window->add($scrWin);

$window->show_all();

Gtk3->main;

gerardgauthier
Автор

gtk_style_context_add_class apart from circle, what more shapes are there?

CodeCristo
Автор

How a software engineer handles a simple concept like an object's colors and fonts.
1. Create six layers of stupid abstractions that deprecate the last six layers of stupid abstractions that were created to solve the same problem.
2. Provide little to no documentation on how the six new abstractions work and provide zero examples on how to use the new abstractions.
3. Walk away from the new abstractions and start searching for another, latest fad, to catch your interest and start from 1 again.
That, in a nutshell, describes the sad state of software affairs.


If you do have to mess with Gtk3 and CSS then investigate -> gtk inspector. It will save you hours of frustration.

gerardgauthier
join shbcf.ru