-
Notifications
You must be signed in to change notification settings - Fork 16
Divider lines for GirdLayout #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
""" | ||
Illustrate how to use divider lines with GridLayout | ||
""" | ||
import board | ||
import displayio | ||
import terminalio | ||
from adafruit_display_text import label | ||
from adafruit_displayio_layout.layouts.grid_layout import GridLayout | ||
|
||
# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.) | ||
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) | ||
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus | ||
display = board.DISPLAY | ||
|
||
# Make the display context | ||
main_group = displayio.Group() | ||
display.show(main_group) | ||
|
||
layout = GridLayout( | ||
x=10, | ||
y=10, | ||
width=200, | ||
height=100, | ||
grid_size=(2, 2), | ||
cell_padding=8, | ||
divider_lines=True, # divider lines around every cell | ||
) | ||
_labels = [] | ||
|
||
_labels.append( | ||
label.Label( | ||
terminalio.FONT, scale=2, x=0, y=0, text="Hello", background_color=0x770077 | ||
) | ||
) | ||
layout.add_content(_labels[0], grid_position=(0, 0), cell_size=(1, 1)) | ||
_labels.append( | ||
label.Label( | ||
terminalio.FONT, scale=2, x=0, y=0, text="World", background_color=0x007700 | ||
) | ||
) | ||
layout.add_content(_labels[1], grid_position=(1, 0), cell_size=(1, 1)) | ||
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Hello")) | ||
layout.add_content(_labels[2], grid_position=(0, 1), cell_size=(1, 1)) | ||
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Grid")) | ||
layout.add_content(_labels[3], grid_position=(1, 1), cell_size=(1, 1)) | ||
|
||
main_group.append(layout) | ||
|
||
other_layout = GridLayout( | ||
x=10, | ||
y=120, | ||
width=140, | ||
height=80, | ||
grid_size=(2, 3), | ||
cell_padding=4, | ||
divider_lines=True, | ||
h_divider_line_rows=(1, 2), # Lines before rows 1 and 2 | ||
v_divider_line_cols=(), # No vertical divider lines | ||
) | ||
|
||
other_layout.add_content( | ||
label.Label(terminalio.FONT, text="0x0"), grid_position=(0, 0), cell_size=(1, 1) | ||
) | ||
other_layout.add_content( | ||
label.Label(terminalio.FONT, text="0x1"), grid_position=(0, 1), cell_size=(1, 1) | ||
) | ||
other_layout.add_content( | ||
label.Label(terminalio.FONT, text="0x2"), grid_position=(0, 2), cell_size=(1, 1) | ||
) | ||
|
||
other_layout.add_content( | ||
label.Label(terminalio.FONT, text="1x0"), grid_position=(1, 0), cell_size=(1, 1) | ||
) | ||
other_layout.add_content( | ||
label.Label(terminalio.FONT, text="1x1"), grid_position=(1, 1), cell_size=(1, 1) | ||
) | ||
other_layout.add_content( | ||
label.Label(terminalio.FONT, text="1x2"), grid_position=(1, 2), cell_size=(1, 1) | ||
) | ||
|
||
main_group.append(other_layout) | ||
|
||
while True: | ||
pass |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be required if you specify
h_divider_lines_rows
. Can you clarify the reasoning behind this? I'm wondering if it should default to none, instead of defaulting to having lines.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to break the API down into two main use cases, the simplest being on/off for divider lines to get drawn at all. The user can enable them by passing
divider_lines=True
in the constructor. This will cause it to draw all available lines around every cell.The second and slightly more advanced use case is the user wants to specify which cells and in which orientation to draw lines some of the lines. In this case with the current API the passes
divider_lines=True
and then passes the desired configurations with theh_divider_line_rows
andv_divider_line_cols
arguments. If either of those arguments is omitted then it reverts to the standarddivider_lines=True
behavior which is to draw all available lines. So currently passing the empty tuple is necessary in order to specify that it should not draw any lines for the given orientation.Maybe it would be simpler if the user passes either
h_divider_line_rows
orv_divider_line_cols
then they do not need to also passdivider_lines=True
I think that would allow the logic to work opposite how it does currently. It could start from drawing no lines, and only draw the ones specified byh_divider_line_rows
andv_divider_line_cols
sincedivider_lines=True
would not be passed it would not draw all available lines if either of those is omitted.I can look into this further and work on those changes tonight.
It seems I may have unintentionally changed the positioning behavior with this PR as well. I noticed just now that running the example in the MacroPad repo results in the labels getting shifted further down than they should be and causing the bottom row to get drawn half way off of the screen. I will try to resolve this issue when I work on it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the shift and forgot to mention it! I didn't even think about the fact that it was an inadvertent change. Indeed, I had to alter my y position by 7 pixels to get everything back in position.