Skip to content
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

Re-implements the Bubble widget. #7882

Merged
merged 4 commits into from May 30, 2022

Conversation

AnthonyZi
Copy link
Contributor

@AnthonyZi AnthonyZi commented May 17, 2022

This commit comprises three commits:

  • Re-implements the Bubble widge
  • Implements tests for the Bubble widget
  • Adapts existing code to Bubble changes

The old Bubble widget design was complicated and used a GridLayout with
multiple dummy widgets solely to get an arrow placed as desired.
Multiple magic numbers like 99 columns or 99 rows were undocumented
and unintuitive. Probably some of these numbers even add unnecessary
limitations to the Bubble widget.
The Bubble widget was fused with the 'BubbleContent' which by design
makes the Bubble widget feel very unflexible.
Sizing the Bubble according to the content was unintuitive if not even
unpossible for some cases and the arrow positioning was relying on magic
numbers as well. Lastly, the old implementation lacked test coverage
with very few tests that did not even cover the core logic of the
widget.

The new implementation reduces the core logic (formerly "on_arrow_pos",
~100 lines of code) to ~30 lines plus a well documented lookup structure
without magic but intuitive values. Furthermore, it adds proper inline
documentation for maintainers.

This PR also adds unit tests for the core logic of the Bubble widget.

Maintainer merge checklist

  • Title is descriptive/clear for inclusion in release notes.
  • Applied a Component: xxx label.
  • Applied the api-deprecation or api-break label.
  • Applied the release-highlight label to be highlighted in release notes.
  • Added to the milestone version it was merged into.
  • Unittests are included in PR.
  • Properly documented, including versionadded, versionchanged as needed.

The old Bubble widget design was complicated and used a GridLayout with
multiple dummy widgets solely to get an arrow placed as desired.
Multiple magic numbers like 99 columns or 99 rows were undocumented
and unintuitive. Probably some of these numbers even add unnecessary
limitations to the Bubble widget.
The Bubble widget was fused with the 'BubbleContent' which by design
makes the Bubble widget feel very unflexible.
Sizing the Bubble according to the content was unintuitive if not even
impossible for some cases and the arrow positioning was relying on magic
numbers as well. Lastly, the old implementation lacked test coverage
with very few tests that did not even cover the core logic of the
widget.

The new implementation reduces the core logic (formerly "on_arrow_pos",
~100 lines of code) to ~30 lines plus a well documented lookup structure
without magic but intuitive values. Furthermore, it adds proper inline
documentation for maintainers.

Furthermore, completely flexible arrow positioning was implemented and
allows free positioning of the arrow to all sides of the content by
selecting a (relative) position on the Bubble widget border.

The BubbleContent widget is a seperate styled BoxLayout and the code and
documentation makes clear that any other Widet or Layout can be placed as
content. The background_color, border and border_auto_scale properties
have been attached to the BubbleContent instead of the Bubble itself
which removes the unnecessary connections between the Bubble itself and it's
BubbleContent.

Properties, that refer to multiple dimensions are cleanly integrated
through ReferenceListProperties.

The rework of the Bubble widget fixes the issue kivy#4348 which had been
opened in 2016 and remained unsolved.

Minimal changes are necessary for existing applications using the Bubble
widget:
- A BubbleContent (can be any Layout or a single Widget) is added as only child
  to the Bubble (similarly to the ActionBar/ActionView widgets).
- The background_color, border and border_auto_scale properties have
  been removed from the Bubble as they belong to the BubbleContent

Signed-off-by: AnthonyZimmermann <anthony.zimmermann@protonmail.com>
Core functionality tests:
- Rendering
- Add/remove content
- Error handling if two child widgets are added to the Bubble
- Test BubbleContent, BubbleButton

Arrow positioning and Bubble sizing:
- parameterized tests for predefined arrow_pos arrow positioning (12
  tests)
- parameterized tests for flexible flex_arrow_pos arrow positioing (40
  tests)

Signed-off-by: AnthonyZimmermann <anthony.zimmermann@protonmail.com>
The textinput uses a Bubble for "cut", "copy", "paste" functionality.
Three example scripts and kv files contained the Bubble widget.

Signed-off-by: AnthonyZimmermann <anthony.zimmermann@protonmail.com>
@welcome
Copy link

welcome bot commented May 17, 2022

Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines.


def adjust_position(self):
if self.limit_to is not None and not self._temporarily_ignore_limits:
if self.limit_to is EventLoop.window:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part was mainly copied from the old implementation. I use the Bubble widget mainly in a Scatter Plane where this logic does somehow not really make sense. Maybe someone else can verify that this code still "usefull" in other use cases.

add = self_arrow_layout.add_widget
for widg in arrow_list:
add(widg)
if not (lim_x > self.x and lim_right < self.right):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapted this part a little to make it only "intelligent" if there is a possible better solution (widget is completely within the limits).

@akshayaurora akshayaurora added Component: core-widget properties, eventdispatcher, widget.py, animation Component: Widgets kivy/uix, style.kv Notes: API-deprecation API deprecated in the PR Notes: Release-highlight Highlight this PR in the release notes. and removed Component: core-widget properties, eventdispatcher, widget.py, animation labels May 18, 2022
@akshayaurora akshayaurora added this to the 2.2.0 milestone May 18, 2022
@AnthonyZi
Copy link
Contributor Author

Hey, this is my first PR here. I am wondering if there is something blocking the review process. Is someone/something waiting for me to take some action? Tanks in advance!

kivy/uix/bubble.py Show resolved Hide resolved
kivy/uix/bubble.py Show resolved Hide resolved
kivy/uix/bubble.py Show resolved Hide resolved
kivy/uix/bubble.py Show resolved Hide resolved
kivy/uix/bubble.py Show resolved Hide resolved
kivy/uix/bubble.py Show resolved Hide resolved
kivy/uix/bubble.py Show resolved Hide resolved
Updates documentation:
- Adds further documentation
- More details about 'versionadded' and 'versionchanged'

Little improvement/fix (found during update of the documentation):
- Update the arrow image size information on arrow_image change.
@akshayaurora akshayaurora merged commit 37292f0 into kivy:master May 30, 2022
@welcome
Copy link

welcome bot commented May 30, 2022

Congrats on merging your first pull request! 🎉🎉🎉

@akshayaurora
Copy link
Member

@AnthonyZi thanks 👍

@misl6 misl6 mentioned this pull request Jun 21, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Widgets kivy/uix, style.kv Notes: API-deprecation API deprecated in the PR Notes: Release-highlight Highlight this PR in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants