fluix 0.1.20

A comprehensive UI component library for GPUI 0.2 - Modern, performant, and type-safe
Documentation
# Select Component Improvements

## ✅ 已实现的改进

### 1. 变体系统 (Variant System)

添加了 `SelectVariant` 枚举,支持不同的视觉样式:

```rust
pub enum SelectVariant {
    Default,    // 默认样式(有边框和背景)
    Ghost,      // 无边框,透明背景
    Outline,    // 仅边框,透明背景
}
```

#### 使用方法

```rust
// 默认变体
Select::new(cx)
    .variant(SelectVariant::Default)
    .options(vec![...])

// Ghost 变体(无边框,透明背景)
Select::new(cx)
    .variant(SelectVariant::Ghost)
    .options(vec![...])

// Outline 变体(仅边框,透明背景)
Select::new(cx)
    .variant(SelectVariant::Outline)
    .options(vec![...])
```

### 2. 下拉方向控制 (Dropdown Direction)

添加了 `DropdownDirection` 枚举,支持向上或向下展开:

```rust
pub enum DropdownDirection {
    Down,   // 向下展开(默认)
    Up,     // 向上展开
    Auto,   // 自动检测(未来实现)
}
```

#### 使用方法

```rust
// 向下展开(默认)
Select::new(cx)
    .dropdown_direction(DropdownDirection::Down)
    .options(vec![...])

// 向上展开
Select::new(cx)
    .dropdown_direction(DropdownDirection::Up)
    .options(vec![...])
```

### 2.5. 下拉宽度控制 (Dropdown Width) ⭐ NEW

添加了 `DropdownWidth` 枚举,支持自定义下拉菜单宽度:

```rust
pub enum DropdownWidth {
    MatchTrigger,      // 匹配触发器宽度(默认)
    Fixed(Pixels),     // 固定宽度
    MinWidth(Pixels),  // 最小宽度
    MaxWidth(Pixels),  // 最大宽度
}
```

#### 使用方法

```rust
// 匹配触发器宽度(默认)
Select::new(cx)
    .options(vec![...])

// 固定宽度
Select::new(cx)
    .fixed_width(px(120.))
    .options(vec![...])

// 最小宽度
Select::new(cx)
    .min_width(px(300.))
    .options(vec![...])

// 最大宽度
Select::new(cx)
    .max_width(px(200.))
    .options(vec![...])

// 组合使用:窄宽度 + 紧凑 + 右对齐
Select::new(cx)
    .fixed_width(px(100.))
    .compact()
    .align_right()
    .options(vec![...])
```

### 2.6. 下拉对齐控制 (Dropdown Alignment)

添加了 `DropdownAlignment` 枚举,支持左对齐、右对齐、居中对齐:

```rust
pub enum DropdownAlignment {
    Left,    // 左对齐(默认)
    Right,   // 右对齐
    Center,  // 居中对齐
}
```

#### 使用方法

```rust
// 左对齐(默认)
Select::new(cx)
    .align_left()
    .options(vec![...])

// 右对齐
Select::new(cx)
    .align_right()
    .options(vec![...])

// 居中对齐
Select::new(cx)
    .align_center()
    .options(vec![...])

// 组合使用:右对齐 + 向上展开
Select::new(cx)
    .align_right()
    .dropdown_direction(DropdownDirection::Up)
    .options(vec![...])
```

### 3. 便捷方法 (Convenience Methods)

添加了快捷方法,简化常见用例:

```rust
// 移除边框
Select::new(cx)
    .no_border()
    .options(vec![...])

// 移除阴影
Select::new(cx)
    .no_shadow()
    .options(vec![...])

// 透明背景
Select::new(cx)
    .transparent()
    .options(vec![...])

// 清爽样式(无边框、无阴影、透明背景)
Select::new(cx)
    .clean()
    .options(vec![...])

// 紧凑间距(NEW!)
Select::new(cx)
    .compact()
    .options(vec![...])

// 自定义边框颜色
Select::new(cx)
    .border_color(rgb(0x999999))
    .options(vec![...])
```

## 🎯 完整示例

### 示例 1: Ghost 变体(适用于嵌入式场景)

```rust
Select::new(cx)
    .placeholder("选择选项")
    .variant(SelectVariant::Ghost)
    .text_color(rgb(0x999999))
    .size(ComponentSize::Small)
    .options(vec![
        SelectOption::new("1", "选项 1"),
        SelectOption::new("2", "选项 2"),
    ])
```

### 示例 2: 向上展开的下拉菜单

```rust
Select::new(cx)
    .placeholder("选择选项")
    .dropdown_direction(DropdownDirection::Up)
    .options(vec![
        SelectOption::new("1", "选项 1"),
        SelectOption::new("2", "选项 2"),
    ])
```

### 示例 3: 完全自定义

```rust
Select::new(cx)
    .placeholder("自定义 Select")
    .variant(SelectVariant::Outline)
    .size(ComponentSize::Small)
    .font_size(px(12.))
    .bg_color(rgb(0xF9FAFB))
    .text_color(rgb(0x666666))
    .border_color(rgb(0xD1D5DB))
    .dropdown_direction(DropdownDirection::Up)
    .options(vec![...])
```

## 📊 API 参考

### 新增方法

| 方法 | 参数 | 描述 |
|------|------|------|
| `.variant()` | `SelectVariant` | 设置视觉变体 |
| `.dropdown_direction()` | `DropdownDirection` | 设置下拉方向 |
| `.dropdown_alignment()` | `DropdownAlignment` | 设置下拉对齐 ⭐ NEW |
| `.dropdown_width()` | `DropdownWidth` | 设置下拉宽度 ⭐ NEW |
| `.fixed_width()` | `Pixels` | 固定宽度(便捷方法) ⭐ NEW |
| `.min_width()` | `Pixels` | 最小宽度(便捷方法) ⭐ NEW |
| `.max_width()` | `Pixels` | 最大宽度(便捷方法) ⭐ NEW |
| `.align_left()` | - | 左对齐(便捷方法) |
| `.align_right()` | - | 右对齐(便捷方法) |
| `.align_center()` | - | 居中对齐(便捷方法) |
| `.border_color()` | `Rgba` | 设置边框颜色 |
| `.no_border()` | - | 移除边框(便捷方法) |
| `.no_shadow()` | - | 移除阴影(便捷方法) |
| `.transparent()` | - | 透明背景(便捷方法) |
| `.clean()` | - | 清爽样式:无边框、无阴影、透明(便捷方法) |
| `.compact()` | - | 紧凑间距(便捷方法) ⭐ NEW |

### 新增类型

```rust
// 视觉变体
pub enum SelectVariant {
    Default,    // 默认样式
    Ghost,      // 无边框,透明
    Outline,    // 仅边框
}

// 下拉方向
pub enum DropdownDirection {
    Down,   // 向下
    Up,     // 向上
    Auto,   // 自动(未来)
}
```

## 🎨 使用场景

### 场景 1: 嵌入式 Select(Settings 视图)

```rust
// Provider Select in Settings
Select::new(cx)
    .variant(SelectVariant::Ghost)
    .size(ComponentSize::Small)
    .text_color(rgb(0x999999))
    .options(providers)
```

**优点**:
- 无边框,融入背景
- 小尺寸,节省空间
- 自定义文字颜色,匹配设计

### 场景 2: 底部工具栏的 Select

```rust
// Select in bottom toolbar
Select::new(cx)
    .dropdown_direction(DropdownDirection::Up)
    .variant(SelectVariant::Outline)
    .options(options)
```

**优点**:
- 向上展开,避免被遮挡
- Outline 样式,清晰可见

### 场景 3: 表单中的 Select

```rust
// Select in form
Select::new(cx)
    .variant(SelectVariant::Default)
    .size(ComponentSize::Medium)
    .options(options)
```

**优点**:
- 默认样式,清晰明确
- 中等尺寸,易于点击

## 🔧 实现细节

### 变体实现

变体通过条件渲染实现:

```rust
.map(|this| match self.variant {
    SelectVariant::Default => {
        this.bg(self.custom_bg_color.unwrap_or(theme.colors.background))
    }
    SelectVariant::Ghost => {
        this.bg(self.custom_bg_color.unwrap_or(rgba(0x00000000)))
    }
    SelectVariant::Outline => {
        this.bg(self.custom_bg_color.unwrap_or(rgba(0x00000000)))
            .border_1()
            .border_color(self.custom_border_color.unwrap_or(theme.colors.border))
    }
})
```

### 下拉方向实现

通过改变绝对定位实现:

```rust
.map(|this| match self.dropdown_direction {
    DropdownDirection::Down | DropdownDirection::Auto => {
        this.top_full().mt_1()  // 在下方
    }
    DropdownDirection::Up => {
        this.bottom_full().mb_1()  // 在上方
    }
})
```

## 🚀 运行 Demo

```bash
cargo run --example select_variants_demo
```

Demo 展示了:
- ✅ 所有 3 种变体
- ✅ 向上和向下展开
- ✅ 便捷方法
- ✅ 自定义组合

## 📝 向后兼容性

所有新功能都是**完全向后兼容**的:

- ✅ 默认变体是 `SelectVariant::Default`
- ✅ 默认方向是 `DropdownDirection::Down`
- ✅ 现有代码无需修改

## 🎊 总结

### 新增功能

1. **变体系统** - Default, Ghost, Outline
2.**下拉方向** - Down, Up, Auto
3.**便捷方法** - no_border(), no_shadow(), transparent(), clean()
4.**边框颜色** - border_color()

### 使用场景

- ✅ 嵌入式 Select(Ghost 变体)
- ✅ 底部工具栏(向上展开)
- ✅ 表单(默认样式)
- ✅ 完全自定义

### 完整定制能力

现在 Select 组件支持:

| 属性 | 方法 | 版本 |
|------|------|------|
| 组件尺寸 | `.size()` | v0.1.0+ |
| 字体大小 | `.font_size()` | v0.1.8+ |
| 背景颜色 | `.bg_color()` | v0.1.9+ |
| 文字颜色 | `.text_color()` | v0.1.10+ |
| **视觉变体** | `.variant()` | **v0.1.11+**|
| **下拉方向** | `.dropdown_direction()` | **v0.1.11+**|
| **边框颜色** | `.border_color()` | **v0.1.11+**|
| **无边框** | `.no_border()` | **v0.1.11+**|
| **无阴影** | `.no_shadow()` | **v0.1.11+**|
| **透明背景** | `.transparent()` | **v0.1.11+**|
| **清爽样式** | `.clean()` | **v0.1.11+**|

**Fluix Select 现在是完全可定制的组件!** 🎨✨