Skip to content

Commit

Permalink
Allow scaling the font-size used in the generated css
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleroy committed May 29, 2023
1 parent f4ed60f commit d0da26c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Debugger.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Sets the entire scale of the UI, defaults to font_size
"ui_scale": null,

// Change at your own risk it may break the interface. Restart required to take effect
"font_face": "Monospace",
// Only change this if your font size does not match the panel size (overlapping text, panels not lining up, etc)
"internal_font_scale": 1,

// Which external terminal should be used when an adapter requests an external terminal
// "platform" (default) uses Terminal on MacOS, CMD (Not tested) on Windows, (Unimplemented) on Linux
Expand Down
1 change: 1 addition & 0 deletions modules/output_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, debugger: Debugger, panel_name: str, name: str|None = None, s
def update_settings(self):
# these settings control the size of the ui calculated in ui/layout
settings = self.view.settings()
settings['internal_font_scale'] = Settings.internal_font_scale
if Settings.ui_scale:
settings['font_size'] = Settings.ui_scale
else:
Expand Down
13 changes: 5 additions & 8 deletions modules/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ class Settings:
description='Open the debugger automatically when a project that is set up for debugging'
)

ui_scale = Setting['int|None'] (
ui_scale = Setting['float|None'] (
key='ui_scale',
default=None,
description='Sets the entire scale of the UI, defaults to font_size'
)

font_face = Setting[str] (
key='font_face',
default='Monospace',
description='''
Change at your own risk it may break the interface. Restart required to take effect
'''
internal_font_scale = Setting[float] (
key='internal_font_scale',
default=1,
description='Only change this if your font size does not match the panel size (overlapping text, panels not lining up, etc)'
)

external_terminal = Setting[str] (
Expand Down Expand Up @@ -117,7 +115,6 @@ class Settings:
'''
)


installed_packages = Setting['list[str]'] (
key='installed_packages',
default=[],
Expand Down
5 changes: 3 additions & 2 deletions modules/ui/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ def update(self) -> None:

settings = self.view.settings()
font_size = settings.get('font_size') or 1

internal_font_scale = settings.get('internal_font_scale') or 1
width, height = self.view.viewport_extent()
em_width = self.view.em_width() or 1

# check if anything has changed so we can avoid invalidating the layout
all = (background, font_size, em_width, width, height)
all = (background, font_size, internal_font_scale, em_width, width, height)
if self._all == all:

# only invalidate the layout after the user has stopped changing the layout to avoid redrawing while they are changing stuff
Expand All @@ -263,6 +263,7 @@ def update(self) -> None:

self._all = all

self.internal_font_scale = internal_font_scale
self.font_size = font_size
self._width = width / em_width
self._height = height / em_width
Expand Down
6 changes: 3 additions & 3 deletions modules/ui/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def invalidate():

@staticmethod
def generate(layout: Layout):
key = f'{layout.em_width}-{layout.font_size}'
key = f'{layout.em_width}-{layout.font_size}-{layout.internal_font_scale}'
if c := css._cached_css.get(key):
return c

Expand All @@ -95,9 +95,9 @@ def generate(layout: Layout):
# Change the font-size back since we changed the font-size in the html tag for the rem units
# I have no idea why windows/linux needs pt instead of px to get the font-size correct...
if sublime.platform() == 'osx':
css_list.append(f'body {{ font-size: {layout.font_size}px; }}')
css_list.append(f'body {{ font-size: {layout.font_size * layout.internal_font_scale}px; }}')
else:
css_list.append(f'body {{ font-size: {layout.font_size}pt; }}')
css_list.append(f'body {{ font-size: {layout.font_size * layout.internal_font_scale}pt; }}')

for c in css.instances:
css_list.append('#{}{{'.format(c.id))
Expand Down

0 comments on commit d0da26c

Please sign in to comment.