[geany/geany] e42a96: Merge pull request #1738 from b4n/symbols-margin-auto-width

Colomban Wendling git-noreply at xxxxx
Sun Oct 25 17:01:38 UTC 2020


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sun, 25 Oct 2020 17:01:38 UTC
Commit:      e42a963d6b4f1b2ef2063e59fc4139a250dfe709
             https://github.com/geany/geany/commit/e42a963d6b4f1b2ef2063e59fc4139a250dfe709

Log Message:
-----------
Merge pull request #1738 from b4n/symbols-margin-auto-width

Size symbols and fold margins proportional to line height

Replaces #2140.


Modified Paths:
--------------
    data/filedefs/filetypes.common
    src/editor.c
    src/highlighting.c
    src/sciwrappers.c
    src/sciwrappers.h

Modified: data/filedefs/filetypes.common
3 lines changed, 0 insertions(+), 3 deletions(-)
===================================================================
@@ -19,9 +19,6 @@ margin_linenumber=margin_line_number
 margin_folding=margin_folding
 fold_symbol_highlight=fold_symbol_highlight
 
-# width of the folding margin on the right of the line numbers
-folding_margin_width=12
-
 # background colour of the current line, only the second and third argument is interpreted
 # use the third argument to enable or disable the highlighting of the current line (has to be true/false)
 current_line=current_line


Modified: src/editor.c
15 lines changed, 13 insertions(+), 2 deletions(-)
===================================================================
@@ -1065,6 +1065,15 @@ void editor_sci_notify_cb(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gint sc
 }
 
 
+/* recalculate margins width */
+static void update_margins(ScintillaObject *sci)
+{
+	sci_set_line_numbers(sci, editor_prefs.show_linenumber_margin);
+	sci_set_symbol_margin(sci, editor_prefs.show_markers_margin);
+	sci_set_folding_margin_visible(sci, editor_prefs.folding);
+}
+
+
 static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *editor,
 								 SCNotification *nt, G_GNUC_UNUSED gpointer data)
 {
@@ -1185,8 +1194,7 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *edi
 			break;
 
 		case SCN_ZOOM:
-			/* recalculate line margin width */
-			sci_set_line_numbers(sci, editor_prefs.show_linenumber_margin);
+			update_margins(sci);
 			break;
 	}
 	/* we always return FALSE here to let plugins handle the event too */
@@ -4608,6 +4616,7 @@ void editor_set_font(GeanyEditor *editor, const gchar *font)
 
 	g_free(font_name);
 
+	update_margins(editor->sci);
 	/* zoom to 100% to prevent confusion */
 	sci_zoom_off(editor->sci);
 }
@@ -5189,6 +5198,8 @@ void editor_apply_update_prefs(GeanyEditor *editor)
 	sci_set_symbol_margin(sci, editor_prefs.show_markers_margin);
 	sci_set_line_numbers(sci, editor_prefs.show_linenumber_margin);
 
+	sci_set_folding_margin_visible(sci, editor_prefs.folding);
+
 	/* virtual space */
 	SSM(sci, SCI_SETVIRTUALSPACEOPTIONS, editor_prefs.show_virtual_space, 0);
 


Modified: src/highlighting.c
21 lines changed, 0 insertions(+), 21 deletions(-)
===================================================================
@@ -96,7 +96,6 @@ enum	/* Geany common styling */
 	GCS_LINE_HEIGHT,
 	GCS_CALLTIPS,
 	GCS_INDICATOR_ERROR,
-	GCS_FOLDING_MARGIN_WIDTH,
 	GCS_MAX
 };
 
@@ -565,8 +564,6 @@ static void styleset_common_init(GKeyFile *config, GKeyFile *config_home)
 		1, 1, &common_style_set.fold_marker, &common_style_set.fold_lines);
 	get_keyfile_ints(config, config_home, "styling", "folding_horiz_line",
 		2, 0, &common_style_set.fold_draw_line, NULL);
-	get_keyfile_ints(config, config_home, "styling", "folding_margin_width",
-		1, 0, &common_style_set.styling[GCS_FOLDING_MARGIN_WIDTH].background, NULL);
 	get_keyfile_ints(config, config_home, "styling", "caret_width",
 		1, 0, &common_style_set.styling[GCS_CARET].background, NULL); /* caret.foreground used earlier */
 	get_keyfile_int(config, config_home, "styling", "line_wrap_visuals",
@@ -808,22 +805,6 @@ static void styleset_common(ScintillaObject *sci, guint ft_id)
 }
 
 
-/* folding margin visibility */
-static void set_folding_margin_visible(ScintillaObject *sci, gboolean set)
-{
-	if (set)
-	{
-		SSM(sci, SCI_SETMARGINWIDTHN, 2, common_style_set.styling[GCS_FOLDING_MARGIN_WIDTH].background);
-		SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
-	}
-	else
-	{
-		SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
-		SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
-	}
-}
-
-
 /* Merge & assign global typedefs and user secondary keywords.
  * keyword_idx is used for both style_sets[].keywords and scintilla keyword style number */
 static void merge_type_keywords(ScintillaObject *sci, guint ft_id, guint keyword_idx)
@@ -899,8 +880,6 @@ static void styleset_from_mapping(ScintillaObject *sci, guint ft_id, guint lexer
 		}
 	}
 
-	set_folding_margin_visible(sci, editor_prefs.folding);
-
 	/* keywords */
 	foreach_range(i, n_keywords)
 	{


Modified: src/sciwrappers.c
39 lines changed, 38 insertions(+), 1 deletions(-)
===================================================================
@@ -144,12 +144,31 @@ void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const
 }
 
 
+/* compute margin width based on ratio of line height */
+static gint margin_width_from_line_height(ScintillaObject *sci, gdouble ratio, gint threshold)
+{
+	const gint line_height = SSM(sci, SCI_TEXTHEIGHT, 0, 0);
+	gint width;
+
+	width = line_height * ratio;
+	/* round down to an even size */
+	width = width - (width % 2);
+	/* if under threshold, just use the line height */
+	if (width < threshold)
+		width = MIN(threshold, line_height);
+
+	return width;
+}
+
+
 /* symbol margin visibility */
 void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
 {
 	if (set)
 	{
-		SSM(sci, SCI_SETMARGINWIDTHN, 1, 16);
+		const gint width = margin_width_from_line_height(sci, 0.88, 16);
+
+		SSM(sci, SCI_SETMARGINWIDTHN, 1, width);
 		SSM(sci, SCI_SETMARGINSENSITIVEN, 1, TRUE);
 	}
 	else
@@ -160,6 +179,24 @@ void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
 }
 
 
+/* folding margin visibility */
+void sci_set_folding_margin_visible(ScintillaObject *sci, gboolean set)
+{
+	if (set)
+	{
+		const gint width = margin_width_from_line_height(sci, 0.66, 12);
+
+		SSM(sci, SCI_SETMARGINWIDTHN, 2, width);
+		SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
+	}
+	else
+	{
+		SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
+		SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
+	}
+}
+
+
 /* end of lines */
 void sci_set_visible_eols(ScintillaObject *sci, gboolean set)
 {


Modified: src/sciwrappers.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -157,6 +157,7 @@ void 				sci_toggle_fold				(ScintillaObject *sci, gint line);
 gint				sci_get_fold_level			(ScintillaObject *sci, gint line);
 gint				sci_get_fold_parent			(ScintillaObject *sci, gint start_line);
 
+void 				sci_set_folding_margin_visible (ScintillaObject *sci, gboolean set);
 gboolean			sci_get_fold_expanded		(ScintillaObject *sci, gint line);
 
 void				sci_colourise				(ScintillaObject *sci, gint start, gint end);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list