Repository navigation
v0.1.1
Builds on v0.1.0.
This release changes how Button looks by default. No API is removed and existing code compiles unchanged, but every Button with a visible background now reacts to the pointer. See Migration below.
Button gives hover and press feedback by default
Button used to be a pure alias for a left-to-right element. A button showed no reaction to the pointer unless every call site wrote its own CC_Hovered(...) ? A : B color swap, and nothing covered the held-down look.
Button now lowers its background alpha from the pointer state:
| Pointer state | Background alpha |
|---|---|
| Not over the button | As declared |
| Over the button | Declared alpha x CC_BUTTON_HOVER_ALPHA (default 0.85f) |
| Over the button, left button held | Declared alpha x CC_BUTTON_PRESS_ALPHA (default 0.70f) |
if (CC_Clicked("Save")) save_file();
Button("Save",
.layout = { .padding = PadAll(12) },
.backgroundColor = Color(40, 100, 200, 255),
.cornerRadius = RadiusAll(8)) {
Text("Save", .textColor = Color(255, 255, 255, 255), .fontSize = 16);
}Only the alpha channel changes, so the button blends toward whatever is drawn behind it. Text, border and layout are untouched. CC_Hovered and CC_Clicked behave as before.
Tuning
Both factors are #ifndef-guarded macros. Define them before including ccompose.h, or pass them to the compiler:
-DCC_BUTTON_HOVER_ALPHA=0.9f -DCC_BUTTON_PRESS_ALPHA=0.8f
The values are compile-time and apply to every button. The library and your code must be compiled with the same values.
Also new
CC_Scope CC_OpenButton(CC_String id, CC_ElementDeclaration decl)is the runtime hook theButtonmacro expands into. You do not normally call it directly.- The feedback works on a
Buttonwith an empty id as well. examples/demo.cdrops its manual hover swaps on the primary, secondary and notification buttons.
Migration
-
To keep an element with no injected behavior, replace
Button("id", ...)withRow("id", ...). The arguments are the same,Rowhas the expansionButtonused to have, andCC_Hovered/CC_Clickedwork on any element id. -
If a
Buttonalready swaps colors on hover, the default now stacks on top: the swapped color is drawn at 85% alpha. Delete the manual swap, or switch that element toRow. -
Transparent buttons are unaffected. A background with alpha 0 has nothing to scale, so a ghost button still needs its own swap:
.backgroundColor = CC_Hovered("Ghost") ? COLOR_HOVER : COLOR_TRANSPARENT
Known limits
- A press that starts outside a button and is dragged onto it shows the pressed look, because Clay does not record where a press started.
- The change between states is instant. There is no fade.
Other changes
PROJECT_VERSIONinCMakeLists.txtis now0.1.1.- New headless test
ccompose_button_testcovers idle, hovered, pressed, pointer down elsewhere, a hoveredRow, and a hovered transparent button. - Wiki updated: the
Interactionpage documents the default feedback, the two factors, and theRowopt-out.
Verification
All 7 CI checks pass on Linux (gcc + clang), macOS, Windows (MSVC), and Emscripten, plus clang-format and cppcheck. Headless ctest suite: 4/4 pass.
Consuming via FetchContent
include(FetchContent)
FetchContent_Declare(ccompose
GIT_REPOSITORY https://github.com/rizukirr/ccompose.git
GIT_TAG v0.1.1
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(ccompose)
target_link_libraries(your_target PRIVATE ccompose)