3 ms·
Jetpack Compose on Android has an API exactly like you describe, but I've never heard it described as an immediate-mode GUI. Is it one, or is there something el
by lolinder 5y ago
Jetpack Compose on Android has an API exactly like you describe, but I've never heard it described as an immediate-mode GUI. Is it one, or is there something else that makes a GUI toolkit immediate-mode?
- modeless 5y agoJetpack Compose is very interesting, but I don't think it's exactly what I described. It explicitly retains a lot of state including a widget tree and event handlers. Although the state is opaque because there is no DOM-like API to inspect it, the user is still required to reason about the retained state and know exactly when and which parts should be invalidated. It provides a lot of "convenience" features for the user to annotate and wrap state which is expected to change so that invalidation can happen semi-automatically. But that results in a lot of rules you must follow which can't be automatically checked or enforced, which ends up being rather complex I think: https://developer.android.com/jetpack/compose/state https://developer.android.com/jetpack/compose/state and https://developer.android.com/jetpack/compose/side-effects https://developer.android.com/jetpack/compose/side-effects Here's a checkbox in Jetpack Compose with the required state annotation and event handling stuff, which if forgotten or done incorrectly will make the checkbox silently malfunction: val checkedState = remember { mutableStateOf(true) } Checkbox( checked = checkedState.value, onCheckedChange = { checkedState.value = it } ) And here's a checkbox in Dear Imgui which just uses a plain bool and no event handlers (also note that this includes a clickable text label which would require additional event handlers with Compose): static bool foo = true; // could be any bool in the application, nothing special about this one ImGui::Checkbox("Foo enabled", &foo) Here's a great example of how the retained state in Jetpack Compose can confuse people: https://stackoverflow.com/questions/70040541/jetpack-compose-checkbox-not-showing-changed-state https://stackoverflow.com/questions/70040541/jetpack-compose...