Wrap text in status bar

This commit is contained in:
Ian Jauslin 2021-10-16 02:46:06 -04:00
parent 99ad0407b8
commit 360ce780ae
4 changed files with 25 additions and 7 deletions

View File

@ -15,9 +15,11 @@ class Command_prompt(Label):
# insert mode
self.insert=False
# width of a letter
self.char_width=9
# cursor position
self.cursor=0
self.cursor_width=9
# the text, with no color information
self.raw_text=""
@ -41,7 +43,7 @@ class Command_prompt(Label):
Rectangle(pos=self.pos,size=self.size)
# cursor
Color(1,1,1)
Rectangle(pos=(self.pos[0]+self.cursor*self.cursor_width,self.pos[1]),size=(self.cursor_width,self.height))
Rectangle(pos=(self.pos[0]+self.cursor*self.char_width,self.pos[1]),size=(self.char_width,self.height))
# make text under cursor black
if self.cursor<len(self.raw_text):
@ -247,7 +249,8 @@ class Command_prompt(Label):
return paths[0][end:]
else:
# display in status bar
self.app.status_bar.text=""
self.app.status_bar.raw_text=""
for path in paths:
self.app.status_bar.text+="\""+path+"\" "
self.app.status_bar.raw_text+="\""+path+"\" "
self.app.status_bar.draw()
return common_substr(paths)[end:]

View File

@ -266,7 +266,7 @@ class Cross_painter(Widget):
self.canvas.clear()
self.draw()
# report position in status bar
self.app.status_bar.set_position(" {:05.2f} , {:05.2f}".format(self.selected.pos.x,self.selected.pos.y))
self.app.status_bar.set_text(" {:05.2f} , {:05.2f}".format(self.selected.pos.x,self.selected.pos.y))
# find the cross at position pos

1
jam.kv
View File

@ -13,6 +13,7 @@
markup: True
color: (0,0,0,1)
font_name: "RobotoMono-Regular"
font_size: "15px"
<Command_prompt>:

View File

@ -8,8 +8,22 @@ class Status_bar(Label):
# app is used to share information between widgets
self.app=app
# width of a character
self.char_width=9
# unformatted text
self.raw_text=""
# init Label
super(Status_bar,self).__init__(**kwargs)
def set_position(self,string):
self.text=escape_markup(string)
def set_text(self,string):
self.raw_text=string
self.draw()
def draw(self):
# do not wrap
if len(self.raw_text)<self.width/self.char_width:
self.text=self.raw_text
else:
self.text=self.raw_text[:int(self.width/self.char_width)]