[ghex] gtkhex/common-ui: Refactor some CSS code.
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] gtkhex/common-ui: Refactor some CSS code.
- Date: Fri, 10 Dec 2021 02:44:39 +0000 (UTC)
commit 35fae86111fea43ed9f445fb79fa3075149bb4ad
Author: Logan Rathbone <poprocks gmail com>
Date: Thu Dec 9 21:41:28 2021 -0500
gtkhex/common-ui: Refactor some CSS code.
Fixes recent regression of font size not working from settings.
Also took the liberty to tweak the default appearance of the widget a
little bit.
Will need to turn some attention to layout manager since it's not
handling padding (especially w/ ASCII widget) very gracefully.
src/common-macros.h | 3 +++
src/common-ui.c | 20 +++++++++++---------
src/ghex.css | 27 ++++++++++++++++++++-------
src/gtkhex.c | 35 ++++++++++++++++++++---------------
4 files changed, 54 insertions(+), 31 deletions(-)
---
diff --git a/src/common-macros.h b/src/common-macros.h
index 1d9f34d..923f0c3 100644
--- a/src/common-macros.h
+++ b/src/common-macros.h
@@ -27,6 +27,9 @@
X = GTK_WIDGET(gtk_builder_get_object (builder, #X)); \
g_assert (GTK_IS_WIDGET (X));
+/* Note - only use this macro for application-specific (as opposed to theme/
+ * widget-specific) operations.
+ */
#define APPLY_PROVIDER_TO(PROVIDER, WIDGET)
\
{
\
GtkStyleContext *_context;
\
diff --git a/src/common-ui.c b/src/common-ui.c
index 11666cc..41146b3 100644
--- a/src/common-ui.c
+++ b/src/common-ui.c
@@ -42,12 +42,18 @@
* credit where credit is due!
*/
static char *
-pango_font_description_to_css (PangoFontDescription *desc)
+pango_font_description_to_css (PangoFontDescription *desc,
+ const char *selector)
{
GString *s;
PangoFontMask set;
+ char *tmp;
- s = g_string_new ("* { ");
+ g_assert (selector);
+
+ tmp = g_strdup_printf ("%s { ", selector);
+ s = g_string_new (tmp);
+ g_free (tmp);
set = pango_font_description_get_set_fields (desc);
if (set & PANGO_FONT_MASK_FAMILY)
@@ -172,27 +178,23 @@ set_css_provider_font_from_settings (void)
char *css_str;
desc = pango_font_description_from_string (def_font_name);
- css_str = pango_font_description_to_css (desc);
+ css_str = pango_font_description_to_css (desc, ".hex");
gtk_css_provider_load_from_data (provider,
css_str, -1);
+ g_free (css_str);
}
void
common_set_gtkhex_font_from_settings (GtkHex *gh)
{
- GtkStyleContext *context;
-
g_return_if_fail (GTK_IS_HEX(gh));
g_return_if_fail (GTK_IS_STYLE_PROVIDER(provider));
- /* Get context for the requested GtkHex widget. */
- context = gtk_widget_get_style_context (GTK_WIDGET(gh));
-
/* Ensure global provider and settings are in sync font-wise. */
set_css_provider_font_from_settings ();
- gtk_style_context_add_provider (context,
+ gtk_style_context_add_provider_for_display (gdk_display_get_default (),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
}
diff --git a/src/ghex.css b/src/ghex.css
index 526d9ab..eb68bb5 100644
--- a/src/ghex.css
+++ b/src/ghex.css
@@ -1,23 +1,36 @@
-hex {
+.hex {
font-family: Monospace;
font-size: 12pt;
- padding-left: 12px;
- padding-right: 12px;
+ font-feature-settings: "tnum";
+ color: @theme_fg_color;
+ background-color: @theme_bg_color;
}
-.view:link {
+.hex:selected {
+ color: @theme_selected_fg_color;
+ background-color: @theme_selected_bg_color;
+}
+
+.hex:link {
background-color: alpha(red, 0.5);
}
-.view:checked {
+.hex:checked {
color: @theme_bg_color;
background-color: alpha(@theme_fg_color, 0.9);
}
-#offsets {
+.hex #offsets {
background-color: shade(@theme_bg_color, 0.95);
+ padding-left: 8px;
+ border-right: solid @borders 2px;
}
-#hex-display {
+.hex #hex-display {
border-right: dotted 2px @borders;
+ padding-left: 8px;
+}
+
+.hex #ascii-display {
+ padding-left: 8px;
}
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 8d6a1f1..4a2a037 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -2286,7 +2286,7 @@ gtk_hex_class_init (GtkHexClass *klass)
/* CSS name */
- gtk_widget_class_set_css_name (widget_class, "hex");
+ gtk_widget_class_set_css_name (widget_class, "hexwidget");
/* SIGNALS */
@@ -2488,13 +2488,15 @@ gtk_hex_init (GtkHex *gh)
context = gtk_widget_get_style_context (GTK_WIDGET (widget));
+ /* Add common custom `.hex` style class */
+ gtk_style_context_add_class (context, "hex");
+
gh->provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (GTK_CSS_PROVIDER (gh->provider),
RESOURCE_BASE_PATH "/css/ghex.css");
- gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (gh->provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (gh->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME);
/* Setup offsets widget. */
@@ -2512,8 +2514,15 @@ gtk_hex_init (GtkHex *gh)
gh,
NULL); /* GDestroyNotify destroy); */
+ context = gtk_widget_get_style_context (GTK_WIDGET (gh->offsets));
+
+ gtk_style_context_add_class (context, "hex");
+
+ gtk_style_context_add_provider (context,
+ GTK_STYLE_PROVIDER (gh->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME);
+
gtk_widget_set_name (gh->offsets, "offsets");
- APPLY_PROVIDER_TO (gh->provider, gh->offsets);
/* hide it by default. */
gtk_widget_hide (gh->offsets);
@@ -2537,12 +2546,10 @@ gtk_hex_init (GtkHex *gh)
context = gtk_widget_get_style_context (GTK_WIDGET (gh->xdisp));
- /* Add view class so we get certain theme colours for free. */
- gtk_style_context_add_class (context, "view");
+ gtk_style_context_add_class (context, "hex");
- gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (gh->provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (gh->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME);
gtk_widget_set_name (gh->xdisp, "hex-display");
@@ -2562,12 +2569,10 @@ gtk_hex_init (GtkHex *gh)
gh,
NULL); /* GDestroyNotify destroy); */
- /* Rinse and repeat as above for ascii widget / context / view. */
context = gtk_widget_get_style_context (GTK_WIDGET (gh->adisp));
- gtk_style_context_add_class (context, "view");
- gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (gh->provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ gtk_style_context_add_class (context, "hex");
+ gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (gh->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME);
gtk_widget_set_name (gh->adisp, "ascii-display");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]