Tweak breakpoints to ensure it conforms to the documented spec

ft.font-size^2
Gonçalo Silva 2019-04-17 01:03:37 +01:00
parent c9958b6c12
commit 8159ad9e25
2 changed files with 21 additions and 16 deletions

View File

@ -93,7 +93,6 @@ class MarkupHandler:
# Margin and indents
# A baseline margin is set to allow negative offsets for formatting headers, lists, etc
self.baseline_margin = 0
self.margins_indents = {}
self.update_margins_indents()
@ -283,14 +282,17 @@ class MarkupHandler:
else:
return self.margins_indents[level]
def get_margin_indent(self, margin_level, indent_level, char_width=None):
def get_margin_indent(self, margin_level, indent_level, baseline_margin=None, char_width=None):
if baseline_margin is None:
baseline_margin = self.text_view.get_left_margin()
if char_width is None:
char_width = helpers.get_char_width(self.text_view)
margin = max(self.baseline_margin + char_width * margin_level, 0)
margin = max(baseline_margin + char_width * margin_level, 0)
indent = char_width * indent_level
return margin, indent
def update_margins_indents(self):
baseline_margin = self.text_view.get_left_margin()
char_width = helpers.get_char_width(self.text_view)
# Adjust tab size, as character width can change
@ -298,14 +300,8 @@ class MarkupHandler:
tab_array.set_tab(0, Pango.TabAlign.LEFT, 4 * char_width)
self.text_view.set_tabs(tab_array)
# Adjust baseline margin, as character width can change
# Baseline needs to account for
self.baseline_margin = char_width * 10
self.text_view.set_left_margin(self.baseline_margin)
self.text_view.set_right_margin(self.baseline_margin)
# Adjust margins and indents, as character width can change
for level, tag in self.margins_indents.items():
margin, indent = self.get_margin_indent(*level, char_width)
margin, indent = self.get_margin_indent(*level, baseline_margin, char_width)
tag.set_property("left-margin", margin)
tag.set_property("indent", indent)

View File

@ -258,7 +258,7 @@ class Window(Gtk.ApplicationWindow):
self.text_view.set_hemingway_mode(state.get_boolean())
self.text_view.grab_focus()
def window_resize(self, window, _data=None):
def window_resize(self, window, event=None):
"""set paddings dependant of the window size
"""
@ -266,24 +266,33 @@ class Window(Gtk.ApplicationWindow):
# - The number of characters per line is adequate (http://webtypography.net/2.1.2)
# - The number of characters stays constant while resizing the window / font
# - There is enough text margin for MarkupBuffer to apply indents / negative margins
w_width = window.get_allocation().width
#
# TODO: Avoid hard-coding. Font size is clearer than unclear dimensions, but not ideal.
w_width = event.width if event else window.get_allocation().width
if w_width < 900:
width_request = 700 # ~66 characters
font_size = 14
self.get_style_context().add_class("small")
self.get_style_context().remove_class("large")
elif w_width < 1200:
width_request = 870 # ~66 characters
elif w_width < 1280:
font_size = 16
self.get_style_context().remove_class("small")
self.get_style_context().remove_class("large")
else:
width_request = 830 # ~66 characters
font_size = 18
self.get_style_context().remove_class("small")
self.get_style_context().add_class("large")
font_width = int(font_size * 1/1.6) # Ratio specific to Fira Mono
width = 67 * font_width - 1 # 66 characters
horizontal_margin = 8 * font_width # 8 characters
width_request = width + horizontal_margin * 2
if self.text_view.props.width_request != width_request:
self.text_view.props.width_request = width_request
self.text_view.set_left_margin(horizontal_margin)
self.text_view.set_right_margin(horizontal_margin)
self.scrolled_window.props.width_request = width_request
# TODO: refactorizable