Improved text handling
This change allows for more precise control over the position of text labels
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							5b88d8a880
						
					
				
				
					commit
					dcbed64aa9
				
			@@ -10,8 +10,6 @@ from kmk.extensions import Extension
 | 
				
			|||||||
from kmk.handlers.stock import passthrough as handler_passthrough
 | 
					from kmk.handlers.stock import passthrough as handler_passthrough
 | 
				
			||||||
from kmk.keys import make_key
 | 
					from kmk.keys import make_key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DISPLAY_OFFSET = 4  # Used to calculate a new zero level since SSD1306 is clipped.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class OledEntryType:
 | 
					class OledEntryType:
 | 
				
			||||||
    TXT = 0
 | 
					    TXT = 0
 | 
				
			||||||
@@ -27,13 +25,15 @@ class OledData:
 | 
				
			|||||||
            self.data = entries
 | 
					            self.data = entries
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def oled_text_entry(x=0, y=0, text='', layer=None):
 | 
					    def oled_text_entry(x=0, y=0, x_anchor=0.0, y_anchor=0.0, text='', layer=None):
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            0: text,
 | 
					            0: text,
 | 
				
			||||||
            1: x,
 | 
					            1: x,
 | 
				
			||||||
            2: y,
 | 
					            2: y,
 | 
				
			||||||
            3: layer,
 | 
					            3: layer,
 | 
				
			||||||
            4: OledEntryType.TXT,
 | 
					            4: OledEntryType.TXT,
 | 
				
			||||||
 | 
					            5: x_anchor,
 | 
				
			||||||
 | 
					            6: y_anchor,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
@@ -88,8 +88,8 @@ class Oled(Extension):
 | 
				
			|||||||
                            terminalio.FONT,
 | 
					                            terminalio.FONT,
 | 
				
			||||||
                            text=view[0],
 | 
					                            text=view[0],
 | 
				
			||||||
                            color=0xFFFFFF,
 | 
					                            color=0xFFFFFF,
 | 
				
			||||||
                            x=view[1],
 | 
					                            anchor_point=(view[5],view[6]),
 | 
				
			||||||
                            y=view[2] + DISPLAY_OFFSET,
 | 
					                            anchored_position = (view[1],view[2]),
 | 
				
			||||||
                        )
 | 
					                        )
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                elif view[4] == OledEntryType.IMG:
 | 
					                elif view[4] == OledEntryType.IMG:
 | 
				
			||||||
@@ -98,7 +98,7 @@ class Oled(Extension):
 | 
				
			|||||||
                            view[0],
 | 
					                            view[0],
 | 
				
			||||||
                            pixel_shader=view[0].pixel_shader,
 | 
					                            pixel_shader=view[0].pixel_shader,
 | 
				
			||||||
                            x=view[1],
 | 
					                            x=view[1],
 | 
				
			||||||
                            y=view[2] + DISPLAY_OFFSET,
 | 
					                            y=view[2],
 | 
				
			||||||
                        )
 | 
					                        )
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
        gc.collect()
 | 
					        gc.collect()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user