0

ImGui 中的颜色选择器适用于浮点向量。

bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);

但是我将颜色数据存储在无符号整数中。

我怎样才能让 ColorPicker3ImU32改为处理值?

请注意,ImGUI 是即时模式 API,因此它会更改您下面的值,这意味着转换步骤不容易引入。

4

1 回答 1

1

包起来?

bool ColorPicker3U32(const char* label, ImU32* color, ImGUIColorEditFlags flags = 0) {
   float col[3];
   col[0] = (float)((*color >>   ) & 0xFF) / 255.0f;
   col[1] = (float)((*color >> 8 ) & 0xFF) / 255.0f;
   col[2] = (float)((*color >> 16) & 0xFF) / 255.0f; 

   bool result = ColorPicker3(label, col, flags);

   *color = ((ImU32)(col[0] * 255.0f)      ) |
            ((ImU32)(col[1] * 255.0f) <<  8) |
            ((ImU32)(col[2] * 255.0f) << 16);

   return result;
}

或类似的东西。

于 2021-01-17T02:22:43.833 回答