Skip to content

Commit

Permalink
added glyphs to the menubutton, changed the menubutton style in the a…
Browse files Browse the repository at this point in the history
…pptemplate based on the bar size
  • Loading branch information
ceccopierangiolieugenio committed Feb 27, 2024
1 parent 9f5f1d5 commit d4246c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
18 changes: 1 addition & 17 deletions TermTk/TTkCore/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def drawTableLine(self, pos, items, sizes, colors, alignments ):
color = colors[i]
align = alignments[i]
if w > 0:
self.drawTTkString(pos=(x,y), text=txt, width=w, color=color, alignment=align)
self.drawText(pos=(x,y), text=txt, width=w, color=color, alignment=align)
x += w + 1

def drawChar(self, pos, char, color=TTkColor.RST):
Expand Down Expand Up @@ -590,22 +590,6 @@ def drawMenuBarBg(self, pos, size, color=TTkColor.RST ):
mb = TTkCfg.theme.menuBar
self.drawText(pos=pos, text=f"{mb[3]}{mb[1]*(size-2)}{mb[4]}", color=color)

def drawMenuBarButton(self, width, text, pos=(0,0), border=True, submenu=False, shortcuts=[], color=TTkColor.RST, borderColor=TTkColor.RST, shortcutColor=TTkColor.UNDERLINE ):
mb = TTkCfg.theme.menuBar
x,y = pos
if border:
self.drawText(pos=(x,y), color=borderColor ,text=mb[2])
self.drawText(pos=(x+1+len(text),y), color=borderColor ,text=mb[0])
self.drawText(pos=(x+1,y), color=color ,text=text)
off = 1
else:
self.drawText(pos=(x,y), width=width, color=color ,text=text)
if submenu:
self._set(y,x+width-1, mb[5], color)
off = 0
for i in shortcuts:
self._set(y,x+i+off, text.charAt(i), shortcutColor)

def execPaint(self, winw, winh):
pass

Expand Down
22 changes: 15 additions & 7 deletions TermTk/TTkWidgets/apptemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,28 @@ def _setGeometries(_loc, _p, _x,_y,_w,_h,_bbar):
if _bbar:
off = 0
mbl[_loc] = None
if _bbar[1]: # Fixed
styleToMerge = {'default':{'glyphs':('├','─','┤','┄','┄','▶')}}
else:
styleToMerge = {'default':{'glyphs':('╞','═','╡','┄','┄','▶')}}
else:
off = 1
mbl[_loc] = {'pos':(_x,_y-1+off),'text':f"┄{'─'*(_w-2)}┄"}
styleToMerge = {'default':{'glyphs':('├','─','┤','┄','┄','▶')}}
for m in _mb._menus(TTkK.LEFT_ALIGN): m.mergeStyle(styleToMerge)
for m in _mb._menus(TTkK.RIGHT_ALIGN): m.mergeStyle(styleToMerge)
for m in _mb._menus(TTkK.CENTER_ALIGN): m.mergeStyle(styleToMerge)
off = 0 if _bbar else 1
_mb.setGeometry(_x+1,_y-1+off,_w-2,1)
_p.setGeometry(_x,_y+off,_w,_h-off)

_setGeometries( TTkAppTemplate.MAIN , pm, bm+sl+bl , bm+sh+bh+st+bt , newszw , newszh , bt | ( bh and pt==None ) | ( bm and ph==pt==None))
if pl: _setGeometries(TTkAppTemplate.LEFT , pl, bm , bm+sh+bh , sl , h-sh-bh-sf-bf , bh | ( bm and ph==None))
if pr: _setGeometries(TTkAppTemplate.RIGHT , pr, bm+sl+bl+newszw+br , bm+sh+bh , sr , h-sh-bh-sf-bf , bh | ( bm and ph==None))
if ph: _setGeometries(TTkAppTemplate.HEADER , ph, bm , bm , w , sh , bm)
if pt: _setGeometries(TTkAppTemplate.TOP , pt, bm+sl+bl , bm+sh+bh , newszw , st , bh | ( bm and ph==None))
if pb: _setGeometries(TTkAppTemplate.BOTTOM , pb, bm+sl+bl , bm+sh+bh+st+bt+newszh+bb , newszw , sb , bb)
if pf: _setGeometries(TTkAppTemplate.FOOTER , pf, bm , bm+sh+bh+st+bt+newszh+bb+sb+bf , w , sf , bf)
_setGeometries( TTkAppTemplate.MAIN , pm, bm+sl+bl , bm+sh+bh+st+bt , newszw , newszh , (bt and (1,ft)) or (pt==None and (bh and (1,fh))) or (ph==pt==None and (bm and (1, 1))))
if pl: _setGeometries(TTkAppTemplate.LEFT , pl, bm , bm+sh+bh , sl , h-sh-bh-sf-bf , (bh and (1,fh)) or (ph==None and (bm and (1, 1))))
if pr: _setGeometries(TTkAppTemplate.RIGHT , pr, bm+sl+bl+newszw+br , bm+sh+bh , sr , h-sh-bh-sf-bf , (bh and (1,fh)) or (ph==None and (bm and (1, 1))))
if ph: _setGeometries(TTkAppTemplate.HEADER , ph, bm , bm , w , sh , (bm and (1, 1)))
if pt: _setGeometries(TTkAppTemplate.TOP , pt, bm+sl+bl , bm+sh+bh , newszw , st , (bh and (1,fh)) or (ph==None and (bm and (1, 1))))
if pb: _setGeometries(TTkAppTemplate.BOTTOM , pb, bm+sl+bl , bm+sh+bh+st+bt+newszh+bb , newszw , sb , (bb and (1,fb)))
if pf: _setGeometries(TTkAppTemplate.FOOTER , pf, bm , bm+sh+bh+st+bt+newszh+bb+sb+bf , w , sf , (bf and (1,ff)))

# Define Splitter geometries
w,h = self.size()
Expand Down
26 changes: 13 additions & 13 deletions TermTk/TTkWidgets/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@

class TTkMenuBarButton(TTkMenuButton):
classStyle = TTkMenuButton.classStyle | {
'default': TTkMenuButton.classStyle['default'] | {'borderColor':TTkColor.RST, 'shortcutColor': TTkColor.fg("#dddddd") + TTkColor.UNDERLINE},
'clicked': TTkMenuButton.classStyle['clicked'] | {'color': TTkColor.fg("#ffff88")},
'default': TTkMenuButton.classStyle['default'] |
{'borderColor':TTkColor.RST, 'shortcutColor': TTkColor.fg("#dddddd") + TTkColor.UNDERLINE,
'glyphs':('├','─','┤','┄','┄','▶')},
'clicked': TTkMenuButton.classStyle['clicked'] |
{'color': TTkColor.fg("#ffff88")},
}

__slots__=('_shortcut')
Expand All @@ -60,23 +63,20 @@ def setCheckable(self, ch):
def paintEvent(self, canvas):
style = self.currentStyle()
borderColor = style['borderColor']
glyphs = style['glyphs']
textColor = style['color']
scColor = style['shortcutColor']
if self._checkable:
text = ('▣ ' if self._checked else '□ ') + self.text()
width = self.width()+2
else:
text = self.text()
width = self.width()
canvas.drawMenuBarButton(
pos=(0,0),text=text,
width=width,
shortcuts=self._shortcut,
border=True,
submenu=len(self._submenu)>0,
color=textColor,
borderColor=borderColor,
shortcutColor=scColor )

canvas.drawText(pos=(0,0), color=borderColor ,text=glyphs[2])
canvas.drawText(pos=(1+text.termWidth(),0), color=borderColor ,text=glyphs[0])
canvas.drawText(pos=(1,0), color=textColor ,text=text)

for sc in self._shortcut:
canvas.drawChar(pos=(0,sc+1), char=text.charAt(sc), color=scColor)

class TTkMenuBarLayout(TTkHBoxLayout):
'''TTkMenuBarLayout'''
Expand Down

0 comments on commit d4246c5

Please sign in to comment.