command prompt: wrap text
This commit is contained in:
		| @@ -27,6 +27,9 @@ class Command_prompt(Label): | ||||
|         # array of command with arguments | ||||
|         self.argv=[] | ||||
|  | ||||
|         # display characters from window_offset onwards (for text wrapping) | ||||
|         self.window_offset=0 | ||||
|  | ||||
|         # init Label | ||||
|         super(Command_prompt,self).__init__(**kwargs) | ||||
|  | ||||
| @@ -37,19 +40,31 @@ class Command_prompt(Label): | ||||
|  | ||||
|  | ||||
|     def draw(self): | ||||
|         # wrap text | ||||
|         window_size=int(self.width/self.char_width) | ||||
|         if self.cursor>=self.window_offset+window_size: | ||||
|             self.window_offset=self.cursor-window_size+1 | ||||
|         elif self.cursor<self.window_offset: | ||||
|             self.window_offset=self.cursor | ||||
|         # do not stop right before ':' | ||||
|         if self.window_offset==1: | ||||
|             self.window_offset=0 | ||||
|  | ||||
|         with self.canvas.before: | ||||
|             # background | ||||
|             Color(0,0,0) | ||||
|             Rectangle(pos=self.pos,size=self.size) | ||||
|             # cursor | ||||
|             Color(1,1,1) | ||||
|             Rectangle(pos=(self.pos[0]+self.cursor*self.char_width,self.pos[1]),size=(self.char_width,self.height)) | ||||
|             # wrap cursor position | ||||
|             Rectangle(pos=(self.pos[0]+(self.cursor-self.window_offset)*self.char_width,self.pos[1]),size=(self.char_width,self.height)) | ||||
|  | ||||
|         # make text under cursor black | ||||
|         if self.cursor<len(self.raw_text): | ||||
|             self.text=self.raw_text[:self.cursor]+"[color=000]"+self.raw_text[self.cursor]+"[/color]"+self.raw_text[self.cursor+1:] | ||||
|         end=min(len(self.raw_text),self.window_offset+window_size) | ||||
|         if self.cursor<end: | ||||
|             self.text=self.raw_text[self.window_offset:self.cursor]+"[color=000]"+self.raw_text[self.cursor]+"[/color]"+self.raw_text[self.cursor+1:end] | ||||
|         else: | ||||
|             self.text=self.raw_text | ||||
|             self.text=self.raw_text[self.window_offset:end] | ||||
|  | ||||
|  | ||||
|     def on_key_down(self, keyboard, keycode, text, modifiers): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user