-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reduce the surface of the Renderer
APIs
#1110
Merged
Merged
Conversation
This file contains 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
Rendering the scroller is still WIP
... which allows overriding the rendered value.
... when no titlebar is present.
This keeps the order of the arguments consistent with `draw`.
Thanks to @tarkah for pointing this out!
This was referenced Nov 17, 2021
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR reduces the surface of the
Renderer
APIs iniced
to simplify the process of implementing new renderers.iced_graphics
already offers a small set ofBackend
traits to implement renderers, but it is considerably opinionated as it forces their implementors to deal with aPrimitive
tree.The changes here aim to move most of the logic from
iced_graphics
toiced_native
by:Renderer
traits,Primitive
trees,Unified
Renderer
traitsInstead of defining a
Renderer
trait for each widget,iced_native
now defines only 4 mainRenderer
traits. Specifically:Renderer
exposes methods to draw simple geometric shapes (just rectangles, for now!), as well as methods for layering and applying affine transformations.text::Renderer
exposes methods to draw, measure, and hit-test text primitives.image::Renderer
exposes methods to measure and draw raster graphics.svg::Renderer
exposes methods to measure and draw vector graphics.As a result, we can implement the drawing logic of the built-in widgets directly in the implementation of
Widget::draw
iniced_native
, instead of depending oniced_graphics
.Hidden
Primitive
treesThe
Primitive
tree was initially introduced to allow for easy composition of rendering primitives. However, some renderer implementation may choose to use a different data structure to represent composable drawing operations and, as such, usingPrimitive
should not be enforced.Therefore, instead of outputting a
Primitive
as a result,Widget::draw
expects you to record the draw commands directly into therenderer
argument, using the Painter's algorithm.Internally, the
renderer
can choose to represent these drawing operations as it pleases.iced_graphics
may even be able to drop thePrimitive
tree altogether and generate the layers to be uploaded to the GPU directly during the recording of the draw operations!Decoupled
mouse::Interaction
Until now,
Widget::draw
expected us to produce amouse::Interaction
together with the widgetPrimitive
. This was not only cumbersome but also incorrectly architected, since the mouse interaction has nothing to do with the drawing operations (see #377 (review)).Therefore, the
Widget
andOverlay
traits now feature a dedicatedmouse_interaction
method.Hardcoded
StyleSheet
Given that each widget now does not provide its own
Renderer
trait, the style of a widget is no longer defined through an assocciated type. As a consequence, we can directly depend oniced_style
and hardcode theStyleSheet
trait for each widget.Furthermore, we can actually leverage lifetimes! Effectively, this means that now it is possible to borrow any
Application
state in anyStyleSheet
implementor!Together, these changes remove a bunch of unnecessary indirection in
iced_native
, simplify the overall codebase, and allow for more freedom to implement custom renderers while reducing their API surface at the same time! 🎉