Spec dpi aware font size in inches
parent
1e491fb1bb
commit
205bedce85
|
@ -114,7 +114,7 @@ class AxisLabel(pg.GraphicsObject):
|
|||
bg_color: str = 'bracket',
|
||||
fg_color: str = 'black',
|
||||
opacity: int = 0,
|
||||
font_size: Optional[int] = None,
|
||||
font_size_inches: Optional[float] = None,
|
||||
):
|
||||
super().__init__(parent)
|
||||
self.setFlag(self.ItemIgnoresTransformations)
|
||||
|
@ -126,12 +126,9 @@ class AxisLabel(pg.GraphicsObject):
|
|||
|
||||
self._txt_br: QtCore.QRect = None
|
||||
|
||||
self._dpifont = DpiAwareFont()
|
||||
self._dpifont = DpiAwareFont(size_in_inches=font_size_inches)
|
||||
self._dpifont.configure_to_dpi(_font._screen)
|
||||
|
||||
if font_size is not None:
|
||||
self._dpifont._set_qfont_px_size(font_size)
|
||||
|
||||
self.bg_color = pg.mkColor(hcolor(bg_color))
|
||||
self.fg_color = pg.mkColor(hcolor(fg_color))
|
||||
|
||||
|
|
|
@ -11,7 +11,11 @@ from PyQt5 import QtCore, QtGui
|
|||
from PyQt5.QtCore import QLineF, QPointF
|
||||
|
||||
# from .._profile import timeit
|
||||
from ._style import _xaxis_at, hcolor, _font
|
||||
from ._style import (
|
||||
_xaxis_at,
|
||||
hcolor,
|
||||
_font,
|
||||
)
|
||||
from ._axes import YAxisLabel, XAxisLabel, YSticky
|
||||
|
||||
|
||||
|
@ -759,10 +763,10 @@ class L1Labels:
|
|||
def __init__(
|
||||
self,
|
||||
chart: 'ChartPlotWidget', # noqa
|
||||
# level: float,
|
||||
digits: int = 2,
|
||||
font_size: int = 4,
|
||||
font_size_inches: float = 4 / 53.,
|
||||
) -> None:
|
||||
|
||||
self.chart = chart
|
||||
|
||||
self.bid_label = L1Label(
|
||||
|
@ -771,7 +775,7 @@ class L1Labels:
|
|||
# TODO: pass this from symbol data
|
||||
digits=digits,
|
||||
opacity=1,
|
||||
font_size=font_size,
|
||||
font_size_inches=font_size_inches,
|
||||
bg_color='papas_special',
|
||||
fg_color='bracket',
|
||||
orient_v='bottom',
|
||||
|
@ -784,7 +788,7 @@ class L1Labels:
|
|||
# TODO: pass this from symbol data
|
||||
digits=digits,
|
||||
opacity=1,
|
||||
font_size=font_size,
|
||||
font_size_inches=font_size_inches,
|
||||
bg_color='papas_special',
|
||||
fg_color='bracket',
|
||||
orient_v='top',
|
||||
|
@ -810,7 +814,10 @@ def level_line(
|
|||
chart: 'ChartPlogWidget', # noqa
|
||||
level: float,
|
||||
digits: int = 1,
|
||||
font_size: int = 4,
|
||||
|
||||
# size 4 font on 4k screen scaled down, so small-ish.
|
||||
font_size_inches: float = 4 / 53.,
|
||||
|
||||
**linelabelkwargs
|
||||
) -> LevelLine:
|
||||
"""Convenience routine to add a styled horizontal line to a plot.
|
||||
|
@ -822,7 +829,7 @@ def level_line(
|
|||
# TODO: pass this from symbol data
|
||||
digits=digits,
|
||||
opacity=1,
|
||||
font_size=font_size,
|
||||
font_size_inches=font_size_inches,
|
||||
# TODO: make this take the view's bg pen
|
||||
bg_color='papas_special',
|
||||
fg_color='default',
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""
|
||||
Qt UI styling.
|
||||
"""
|
||||
from typing import Optional
|
||||
|
||||
import pyqtgraph as pg
|
||||
from PyQt5 import QtCore, QtGui
|
||||
from qdarkstyle.palette import DarkPalette
|
||||
|
@ -11,17 +13,19 @@ log = get_logger(__name__)
|
|||
|
||||
# chart-wide font
|
||||
# font size 6px / 53 dpi (3x scaled down on 4k hidpi)
|
||||
_font_inches_we_like = 6 / 53 # px / (px / inch) = inch
|
||||
_default_font_inches_we_like = 6 / 53 # px / (px / inch) = inch
|
||||
_down_2_font_inches_we_like = 4 / 53
|
||||
|
||||
|
||||
class DpiAwareFont:
|
||||
def __init__(
|
||||
self,
|
||||
name: str = 'Hack',
|
||||
size_in_inches: Optional[float] = None,
|
||||
) -> None:
|
||||
self.name = name
|
||||
self._qfont = QtGui.QFont(name)
|
||||
self._iwl = _font_inches_we_like
|
||||
self._iwl = size_in_inches or _default_font_inches_we_like
|
||||
self._qfm = QtGui.QFontMetrics(self._qfont)
|
||||
self._physical_dpi = None
|
||||
self._screen = None
|
||||
|
@ -71,7 +75,8 @@ class DpiAwareFont:
|
|||
unscaled_br.height(),
|
||||
)
|
||||
|
||||
# use pixel size to be cross-resolution compatible?
|
||||
|
||||
# use inches size to be cross-resolution compatible?
|
||||
_font = DpiAwareFont()
|
||||
|
||||
# TODO: re-compute font size when main widget switches screens?
|
||||
|
|
Loading…
Reference in New Issue