跳转至

SSkinColorRect 纯色皮肤

概述

SSkinColorRect 是 SOUI 中最简单且高效的皮肤类型,用于绘制纯色矩形区域。它支持边框、圆角等基本图形特性,是构建界面基础外观的重要组件。

类定义

``cpp class SOUI_EXP SSkinColorRect : public SSkinObjBase { protected: COLORREF m_crBorder; // 边框颜色 COLORREF m_crStates[4]; // 状态颜色 int m_nRadius; // 圆角半径 };

## 属性列表

| 属性名 | 类型 | 默认值 | 说明 |
|--------|------|--------|------|
| name | string | - | 皮肤名 |
| scale | float | - | 比例 |
| alpha | int | - | alpha |
| enableColorize | bool | - | enableColorize(是:1|否:0) |
| normal | color | - | normal |
| hover | color | - | hover |
| pushdown | color | - | pushdown |
| disable | color | - | disable |
| cornerRadius | int | - | 圆角 |
| cornerPercent | float | 0.6 | 圆角 百分比 |

## XML示例

``xml
<!-- 基本用法 -->
<colorrect name="white_bg" normal="#ffffff"/>

<!-- 带边框和圆角 -->
<colorrect name="button_bg" 
          normal="#f0f0f0"
          hover="#e0e0e0"
          pushdown="#d0d0d0"
          disable="#cccccc"
          cornerRadius="5"
          cornerPercent="0.6"/>

<!-- 多状态颜色 -->
<colorrect name="btn_multi" 
          normal="#ffffff"
          hover="#f0f0f0"
          pushdown="#e0e0e0"
          disable="#cccccc"
          cornerRadius="3"/>

<!-- 带透明度的纯色 -->
<colorrect name="semi_transparent" 
          normal="#ff0000"
          alpha="128"
          cornerRadius="10"/>

使用场景

1. 背景填充

  • 窗口背景
  • 面板背景
  • 卡片背景

2. 状态指示

  • 选中状态背景
  • 悬停状态高亮
  • 禁用状态背景

3. 装饰元素

  • 分隔线
  • 边框
  • 圆角矩形装饰

4. 按钮背景

  • 简单按钮
  • 状态按钮
  • 透明按钮

最佳实践

  1. 状态管理:合理设置 normalhoverpushdowndisable 四种状态颜色,提供清晰的视觉反馈
  2. 圆角设计:通过 cornerRadiuscornerPercent 属性创建美观的圆角效果
  3. 透明度控制:使用 alpha 属性控制透明度,实现半透明效果
  4. 性能优化:作为最轻量级的皮肤类型,适合大量使用且对性能有要求的场景

常见问题

Q: 圆角效果不明显怎么办?

A: 增大 cornerRadius 值或调整 cornerPercent 值,确保圆角半径相对于控件尺寸合适。

Q: 状态颜色切换不明显怎么办?

A: 调整不同状态的颜色值,确保 normalhoverpushdowndisable 之间有明显区别。

Q: 如何实现动态颜色变化?

A: 设置 enableColorize 为 1,然后通过代码动态设置颜色参数。

相关皮肤

相关链接