Reduce the surface of the Renderer APIs#1110
Merged
Merged
Conversation
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
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
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
RendererAPIs inicedto simplify the process of implementing new renderers.iced_graphicsalready offers a small set ofBackendtraits to implement renderers, but it is considerably opinionated as it forces their implementors to deal with aPrimitivetree.The changes here aim to move most of the logic from
iced_graphicstoiced_nativeby:Renderertraits,Primitivetrees,Unified
RenderertraitsInstead of defining a
Renderertrait for each widget,iced_nativenow defines only 4 mainRenderertraits. Specifically:Rendererexposes methods to draw simple geometric shapes (just rectangles, for now!), as well as methods for layering and applying affine transformations.text::Rendererexposes methods to draw, measure, and hit-test text primitives.image::Rendererexposes methods to measure and draw raster graphics.svg::Rendererexposes 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::drawiniced_native, instead of depending oniced_graphics.Hidden
PrimitivetreesThe
Primitivetree 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, usingPrimitiveshould not be enforced.Therefore, instead of outputting a
Primitiveas a result,Widget::drawexpects you to record the draw commands directly into therendererargument, using the Painter's algorithm.Internally, the
renderercan choose to represent these drawing operations as it pleases.iced_graphicsmay even be able to drop thePrimitivetree altogether and generate the layers to be uploaded to the GPU directly during the recording of the draw operations!Decoupled
mouse::InteractionUntil now,
Widget::drawexpected us to produce amouse::Interactiontogether 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
WidgetandOverlaytraits now feature a dedicatedmouse_interactionmethod.Hardcoded
StyleSheetGiven that each widget now does not provide its own
Renderertrait, the style of a widget is no longer defined through an assocciated type. As a consequence, we can directly depend oniced_styleand hardcode theStyleSheettrait for each widget.Furthermore, we can actually leverage lifetimes! Effectively, this means that now it is possible to borrow any
Applicationstate in anyStyleSheetimplementor!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! 🎉