Class: DFCUI::ColorPicker

Inherits:
Object show all

Overview

ColorPicker 为 DFC 统一的颜色选择器

颜色值的格式为:16 进制,6 个字符,html 颜色格式。例:ffffff, ffcc00

Examples:

color_picker = DFCUI::ColorPicker.new("ffffff")
color_picker.event {|cp, event, value|
	case event
	when :confirm
		puts "confirm = #{value}"
		cp.close
	when :change
		puts "change = #{value}"
	when :cancel
		puts 'cancel'
		cp.close
	when :close
		puts 'close'
	end
}
color_picker.show
# color_picker.show_modal # 和 dialog 的 show_modal 用法一样

Instance Method Summary # collapse

Constructor Details

#initialize(hex_color = nil) ⇒ ColorPicker

初始化

Examples:

color_picker = DFCUI::ColorPicker.new("ffffff")

Parameters:

  • hex_color (String) (defaults to: nil)

    选中的颜色值,默认为 ffcc00

Version:

  • 2.1.2

Instance Method Details

#closeNil

关闭颜色选择器

Examples:

color_picker.close

Returns:

  • (Nil)

Version:

  • 2.1.2

#dialogUI::WebDialog, Nil

返回颜色选择器的 UI::WebDialog 对象

Examples:

color_picker.dialog.set_position(200, 200)

Returns:

  • (UI::WebDialog, Nil)

Version:

  • 2.1.2

#event {|color_picker, event, value| ... } ⇒ Nil

颜色选择器的事件处理

一共有以下 4 个事件,事件参数类型为 Symbol

:confirm -> 确定按钮

:change -> 用户切换颜色

:cancel -> 取消按钮

:close -> 窗口关闭事件

Examples:

color_picker.event {|cp, event, value|
	case event
	when :confirm
		puts "confirm = #{value}"
		cp.close
	when :change
		puts "change = #{value}"
	when :cancel
		puts 'cancel'
		cp.close
	when :close
		puts 'close'
	end
}

Yields:

  • (color_picker, event, value)

Yield Parameters:

  • color_picker (ColorPicker)

    ColorPicker 实例

  • event (Symbol)

    事件

  • value (String, Nil)

    颜色值

Returns:

  • (Nil)

Version:

  • 2.1.2

#show(x = nil, y = nil) ⇒ Nil

常规显示颜色选择器

Examples:

color_picker.show

Parameters:

  • x (Integer) (defaults to: nil)

    距离屏幕左边像素,默认使用最后一次显示的位置

  • y (Integer) (defaults to: nil)

    距离屏幕顶边像素,默认使用最后一次显示的位置

Returns:

  • (Nil)

Version:

  • 2.1.2

#show_modal(x = nil, y = nil) ⇒ Nil

模态显示颜色选择器,窗口关闭前无法执行其他操作

Examples:

color_picker.show_modal

Parameters:

  • x (Integer) (defaults to: nil)

    距离屏幕左边像素,默认使用最后一次显示的位置

  • y (Integer) (defaults to: nil)

    距离屏幕顶边像素,默认使用最后一次显示的位置

Returns:

  • (Nil)

Version:

  • 2.1.2