ImU32 上的 ImGui ColorPicker

问题描述

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

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

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

如何让 ColorPicker3 处理 ImU32 值?

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

解决方法

包起来?

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;
}

或类似的东西。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...