Skip to content

Commit

Permalink
Remove small checkboxes in favor of whole-pair-check
Browse files Browse the repository at this point in the history
(as suggested by Georg in #6)
  • Loading branch information
frankrolf committed Apr 7, 2019
1 parent 244844e commit 6e74b8e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 44 deletions.
40 changes: 7 additions & 33 deletions Kern-A-Lytics.roboFontExt/lib/kernGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ def __init__(self, fonts):
self.min_unit_width = 150
self.p_point_size = 100

# by default, all checkboxes are unchecked
self.checked = [0 for i in range(len(self.fonts))]

self.min_w_width = len(self.fonts) * self.min_unit_width
# cmb_kern_dict is an ordered dict
self.cmb_kern_dict = kerningHelper.get_combined_kern_dict(fonts)
Expand Down Expand Up @@ -295,25 +292,6 @@ def __init__(self, fonts):
pair_preview
)

# checkboxes
for i, f in enumerate(self.fonts):
cb_x = self.padding + graph_margin + i * self.step_dist
cb_control = vanilla.CheckBox(
(
cb_x - 6,
pp_origin_y + self.p_point_size + self.padding * 2,
22, 22),
'',
value=False,
sizeStyle='regular',
callback=self.checkbox_callback
)

setattr(
self.w,
'checkbox_{}'.format(i),
cb_control)

# pop-up button for list filtering
list_width = self.w_width - self.button_width - self.padding * 3

Expand Down Expand Up @@ -453,19 +431,13 @@ def resize_callback(self, sender):
for i, number in enumerate(self.label_values):
text_box = getattr(
self.w, 'textbox_{}'.format(i))
check_box = getattr(
self.w, 'checkbox_{}'.format(i))
tb_x = self.padding + graph_margin + i * self.step_dist
text_box.setPosSize(
(
tb_x - self.tb_width / 2, self.tb_y,
self.tb_width, self.tb_height))

cb_x = self.padding + graph_margin + i * self.step_dist
check_box.setPosSize(
(
cb_x - 6, pp_origin_y + self.p_point_size + self.padding,
22, 22))

pair_preview = getattr(
self.w.pairPreview, 'pair_{}'.format(i))
Expand Down Expand Up @@ -510,11 +482,13 @@ def list_callback(self, sender):
self.w.pairPreview, 'pair_{}'.format(f_index))
pair_obj.setGlyphData_kerning(repr_glyphs, kern_value)

def checkbox_callback(self, sender):
for i, _ in enumerate(self.fonts):
cb_obj = getattr(
self.w, 'checkbox_{}'.format(i))
self.checked[i] = cb_obj.get()
@property
def checked(self):
checked = []
for f_index, _ in enumerate(self.fonts):
pair_obj = getattr(self.w.pairPreview, 'pair_{}'.format(f_index))
checked.append(pair_obj.checked)
return checked

def update_stack(self, pair, value_list):
self.values = value_list
Expand Down
36 changes: 25 additions & 11 deletions Kern-A-Lytics.roboFontExt/lib/pairView.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def init(self):
self = super(PairView, self).init()
self._glyphData = []
self._kern_value = 0
self._inset = 0

self._inset = 10
self.checked = False
return self

def setGlyphData_kerning_(self, glyph_list, kerning):
Expand All @@ -34,12 +34,17 @@ def setKerning_(self, kerning):

def drawRect_(self, rect):
# draw here!

if self.delegate.checked:
AppKit.NSColor.selectedControlColor().set()
selectionPath = AppKit.NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(AppKit.NSInsetRect(rect, 2, 2), 4, 4)
AppKit.NSColor.selectedControlColor().colorWithAlphaComponent_(0.1).set()
selectionPath.fill()
AppKit.NSColor.selectedControlColor().set()
selectionPath.stroke()

frame_width, frame_height = self.frame().size
w, h = [i - 2 * self._inset for i in self.frame().size]
drawBot.fill(None)
drawBot.rect(self._inset, self._inset, w, h)
drawBot.stroke(0)
drawBot.strokeWidth(1)

glyph_pair = self._glyphData
glyph_l, glyph_r = glyph_pair
Expand All @@ -54,27 +59,36 @@ def drawRect_(self, rect):
drawBot.fill(1, 0.3, 0.75)
else:
drawBot.fill(0, 0.8, 0)
# drawBot.fill(0.4, 1, 0.8)
drawBot.rect(
0 - abs(self._kern_value) / 2, 0,
abs(self._kern_value), h * 1 / scale_factor)

drawBot.rect( # bottom rectangle
0 - abs(self._kern_value) / 2, self._inset / scale_factor,
abs(self._kern_value), 2 * self._inset / scale_factor
)
drawBot.rect( # top rectangle
0 - abs(self._kern_value) / 2, (h - self._inset) / scale_factor,
abs(self._kern_value), 2 * self._inset / scale_factor)
drawBot.translate(0, upm / 3)
drawBot.translate(-glyph_l.width - self._kern_value / 2, 0)

for glyph in glyph_pair:
path = glyph.getRepresentation('defconAppKit.NSBezierPath')

drawBot.stroke(None)
# drawBot.fill(0, 1, 0)
drawBot.fill(0)
drawBot.drawPath(path)
drawBot.translate(glyph.width + self._kern_value, 0)

def mouseUp_(self, event):
self.delegate.checked = not self.delegate.checked
self.setNeedsDisplay_(True)

class DrawPair(vanilla.Group):

nsViewClass = PairView
def __init__(self, posSize):
self._setupView(self.nsViewClass, posSize)
self.getNSView().delegate = self
self.checked = False

def setGlyphData_kerning(self, glyph, kerning):
self.getNSView().setGlyphData_kerning_(glyph, kerning)
Expand Down

0 comments on commit 6e74b8e

Please sign in to comment.