Skip to content

v0.1.1

Choose a tag to compare

@rizukirr rizukirr released this 05 Oct 10:59
5993698

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 the Button macro expands into. You do not normally call it directly.
  • The feedback works on a Button with an empty id as well.
  • examples/demo.c drops its manual hover swaps on the primary, secondary and notification buttons.

Migration

  • To keep an element with no injected behavior, replace Button("id", ...) with Row("id", ...). The arguments are the same, Row has the expansion Button used to have, and CC_Hovered / CC_Clicked work on any element id.

  • If a Button already 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 to Row.

  • 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_VERSION in CMakeLists.txt is now 0.1.1.
  • New headless test ccompose_button_test covers idle, hovered, pressed, pointer down elsewhere, a hovered Row, and a hovered transparent button.
  • Wiki updated: the Interaction page documents the default feedback, the two factors, and the Row opt-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)

Full changelog

v0.1.0...v0.1.1