Skip to content

Property background_tight not working for bitmap_label.Label #207

Closed
@SamantazFox

Description

@SamantazFox

While trying to figure out the problem with the width/height properties, I also noticed that the background_tight parameter had no effect on bitmap_label.Label.

I haven't had the time to diagnose the issue much further, unfortunately.


Relevant code

import board
import terminalio
import displayio
import adafruit_ili9341
from adafruit_display_text import bitmap_label, label
from adafruit_display_shapes.line import Line

from time import sleep



displayio.release_displays()
display_bus = displayio.FourWire(
	board.SPI(), command=board.D10, reset=board.D11, chip_select=board.D12
)

display = adafruit_ili9341.ILI9341(display_bus, width=240, height=320, rotation=270)


grid = displayio.Group()
for x in range(0, 240, 10): grid.append(Line(x, 0, x, 320, color=0x404040))
for y in range(0, 320, 10): grid.append(Line(0, y, 240, y, color=0x404040))


test_grp = displayio.Group(scale=3)


def add_bb_visualizer(group, txt_area):
	if txt_area._base_alignment:
		y_off = 0
	else:
		y_off = txt_area.height // 2

	x1 = txt_area.x
	y1 = txt_area.y + y_off
	x2 = x1 + txt_area.width
	y2 = y1 - txt_area.height

	# Bounding box
	group.append(Line(x1, y1,  x2, y1, color=0x00FFFF))
	group.append(Line(x2, y1,  x2, y2, color=0xFFFF00))
	group.append(Line(x2, y2,  x1, y2, color=0xFF00FF))
	group.append(Line(x1, y2,  x1, y1, color=0x00FF00))

	# Cross for anchor point
	x0 = txt_area.x
	y0 = txt_area.y
	group.append(Line(x0-2, y0-2,  x0+2, y0+2, color=0xFF0000))
	group.append(Line(x0-2, y0+2,  x0+2, y0-2, color=0xFF0000))


common_kwargs = {
	'text': 'Hello `y',
	'color': 0xFFFFFF,
	'background_color': 0x123456,
	'base_alignment': False,
	# 'background_tight': True,
	# 'anchor_point': (0,0),
	# 'anchored_position': (0,0),

	# All padding directions are broken
	#'padding_top': 5,
	#'padding_right': 5,
	#'padding_bottom': 5,
	'padding_left': 5
}


# Regular label
text_area1a = label.Label(terminalio.FONT, x = 20, y = 15, background_tight=False, **common_kwargs)
test_grp.append(text_area1a)
add_bb_visualizer(test_grp, text_area1a)

text_area1b = label.Label(terminalio.FONT, x = 20, y = 40, background_tight=True, **common_kwargs)
test_grp.append(text_area1b)
add_bb_visualizer(test_grp, text_area1b)



# Bitmap label
text_area2a = bitmap_label.Label(terminalio.FONT, x = 20, y = 65, background_tight=False, **common_kwargs)
test_grp.append(text_area2a)
add_bb_visualizer(test_grp, text_area2a)

text_area2b = bitmap_label.Label(terminalio.FONT, x = 20, y = 90, background_tight=True, **common_kwargs)
test_grp.append(text_area2b)
add_bb_visualizer(test_grp, text_area2b)



root_grp = displayio.Group()
root_grp.append(grid)
root_grp.append(test_grp)

display.root_group = root_grp

while True:
	pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions