A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.
Apex is just a simple proof of concept to demonstrate how easily you can build your own UI Toolkit from scratch. This code base is most likely full of bugs and design mistakes but it should help you understand the basics of a UI Toolkit. It is meant as a learning and demonstration tool only.
Tested only in an emulator and only on API level 31.
Widgets are called elements and are all instances of the Element
class. Apex elements are not
intended to be subclassed, instead you build widgets by adding components to an element. Each
component has a single responsibility: layout, rendering, input event, or whatever else you want.
Components can be anything, and in the current codebase some are classes, some are interfaces, some
are enums.
For instance a Button
is an Element
with the following components:
ButtonModel
(text, click listener, etc.), the public API of a buttonRenderComponent
, to render the buttonLayoutComponent
, to compute its own size and position the textMotionInputComponent
, to react the touch events and handle clicksInternalState
, to track the pressed state of the buttonApex also offers Provider
instances, which are roughly equivalent to Jetpack Compose's composition
locals. They give access to global data throughout the tree: Resources
, display density, the
current theme, etc. Any Element
can inject new providers or override existing providers by using
the ProviderComponent
component. MainActivity
shows an example of using a ThemeProvider
to
modify the current theme.
If you'd like to play with this codebase a bit, here are a few things you could try:
MotionInputComponent
from Button
and make it a generic, reusable API so you can
perform clicks on the Image
widget in MainActivity
as wellRectF
and SizeF
instances, among
other things)Canvas
, Bitmap
, etc.)
and use your own abstractions. For rendering, use skiko
Not super exciting, but here it is:
See LICENSE.