From 764a829f3924d4c31bbdc56adf7bd76e30256a95 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 3 Sep 2025 12:22:05 +0200 Subject: [PATCH 1/2] Condense long branch names even when showing full names --- gitfourchette/graphview/commitlogdelegate.py | 5 ++++- gitfourchette/toolbox/fittedtext.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gitfourchette/graphview/commitlogdelegate.py b/gitfourchette/graphview/commitlogdelegate.py index eda845f2..c252411a 100644 --- a/gitfourchette/graphview/commitlogdelegate.py +++ b/gitfourchette/graphview/commitlogdelegate.py @@ -17,6 +17,7 @@ from gitfourchette.porcelain import * from gitfourchette.qt import * from gitfourchette.repomodel import UC_FAKEID, UC_FAKEREF, RepoModel +from gitfourchette.settings import GraphRefBoxWidth from gitfourchette.toolbox import * @@ -448,7 +449,9 @@ def _paintRefbox( maxWidth = settings.prefs.refBoxMaxWidth if text and maxWidth != 0: text, fittedFont, textWidth = FittedText.fit( - font, maxWidth, text, Qt.TextElideMode.ElideMiddle, limit=QFont.Stretch.Condensed) + font, maxWidth, text, Qt.TextElideMode.ElideMiddle, limit=QFont.Stretch.Condensed, + stretchMaxWidth=min(maxWidth, GraphRefBoxWidth.Standard), + ) else: textWidth = -rPadding # Negate rPadding diff --git a/gitfourchette/toolbox/fittedtext.py b/gitfourchette/toolbox/fittedtext.py index 0ba4fff6..3d2f670c 100644 --- a/gitfourchette/toolbox/fittedtext.py +++ b/gitfourchette/toolbox/fittedtext.py @@ -37,9 +37,13 @@ def fit( mode=Qt.TextElideMode.ElideRight, limit=defaultStretchLimit, bypassSetting=False, + # When set, stretch the text as though the max width were this value: + stretchMaxWidth: int | None = None, ) -> tuple[str, QFont, int]: metrics = QFontMetricsF(wideFont) width = ceil(metrics.horizontalAdvance(text)) + if stretchMaxWidth is None: + stretchMaxWidth = maxWidth if width < 1: return text, wideFont, 0 @@ -48,7 +52,7 @@ def fit( font = wideFont else: # Figure out upper bound for the stretch factor - baselineStretch = int(100 * maxWidth / width) + baselineStretch = int(100 * stretchMaxWidth / width) if baselineStretch >= 100: # No condensing needed - early out From 428e62adc194fab62a13deab3212cf1526454ffb Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 3 Sep 2025 12:40:48 +0200 Subject: [PATCH 2/2] Option to always use condensed fonts --- gitfourchette/settings.py | 9 ++++++++- gitfourchette/toolbox/fittedtext.py | 4 ++++ gitfourchette/trtables.py | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gitfourchette/settings.py b/gitfourchette/settings.py index bc66f3a5..432b14c1 100644 --- a/gitfourchette/settings.py +++ b/gitfourchette/settings.py @@ -63,6 +63,13 @@ class QtApiNames(enum.StrEnum): PyQt5 = "pyqt5" +class CondensedFonts(enum.Enum): + # For compatibility with old prefs.json files: + Never = False + Stretch = True + Always = "always" + + class LoggingLevel(enum.IntEnum): Benchmark = BENCHMARK_LOGGING_LEVEL Debug = logging.DEBUG @@ -135,7 +142,7 @@ class Prefs(PrefsFile): middleClickToStage : bool = False flattenLanes : bool = True animations : bool = True - condensedFonts : bool = True + condensedFonts : CondensedFonts = CondensedFonts.Stretch pygmentsPlugins : bool = False verbosity : LoggingLevel = LoggingLevel.Debug if APP_TESTMODE else LoggingLevel.Warning forceQtApi : QtApiNames = QtApiNames.Automatic diff --git a/gitfourchette/toolbox/fittedtext.py b/gitfourchette/toolbox/fittedtext.py index 3d2f670c..fcde45e2 100644 --- a/gitfourchette/toolbox/fittedtext.py +++ b/gitfourchette/toolbox/fittedtext.py @@ -7,6 +7,7 @@ from math import ceil from gitfourchette.qt import * +from gitfourchette.settings import CondensedFonts class FittedText: enable = True @@ -44,6 +45,9 @@ def fit( width = ceil(metrics.horizontalAdvance(text)) if stretchMaxWidth is None: stretchMaxWidth = maxWidth + if cls.enable == CondensedFonts.Always: + # Stretch as hard as we can -- as though there's no space + stretchMaxWidth = 0 if width < 1: return text, wideFont, 0 diff --git a/gitfourchette/trtables.py b/gitfourchette/trtables.py index 2e6df761..3c4dbc08 100644 --- a/gitfourchette/trtables.py +++ b/gitfourchette/trtables.py @@ -102,7 +102,7 @@ def _init_enums(): from gitfourchette.porcelain import FileMode, NameValidationError from gitfourchette.toolbox import toLengthVariants from gitfourchette.sidebar.sidebarmodel import SidebarItem - from gitfourchette.settings import GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort + from gitfourchette.settings import GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort, CondensedFonts from gitfourchette.toolbox import PatchPurpose, PathDisplayStyle, AuthorDisplayStyle NVERule = NameValidationError.Rule @@ -230,6 +230,12 @@ def _init_enums(): RefSort.AlphaAsc : _p("sort refs alphabetically, ascending", "Name, A-Z"), RefSort.AlphaDesc : _p("sort refs alphabetically, descending", "Name, Z-A"), RefSort.UseGlobalPref : "", + }, + + CondensedFonts: { + CondensedFonts.Never : _p("never use condensed fonts", "Never"), + CondensedFonts.Stretch : _p("shrink only long text using condensed fonts", "For long text"), + CondensedFonts.Always : _p("use condensed fonts whenever possible", "Always"), } }