自绘制HT For Web ComboBox下拉框组件

HT for

首先我们先来目睹下效果:

HT for Web

那么接下来就开始具体的方案介绍,废话不多说,上代码:

function createGradientComboBox(dataModel){var sm = dataModel.sm(),gradientComboBox = new ht.widget.ComboBox(),gradients = ['linear.southwest','linear.southeast','linear.northwest','linear.northeast','linear.north','linear.south','linear.west','linear.east','radial.center','radial.southwest','radial.southeast','radial.northwest','radial.northeast','radial.north','radial.south','radial.west','radial.east','spread.horizontal','spread.vertical','spread.diagonal','spread.antidiagonal','spread.north','spread.south','spread.west','spread.east'],gradientImages = [],indent = gradientComboBox.getIndent(),height = 18,padding = 2;gradients.forEach(function (gradient) {gradientImages[gradient] = {width: indent,height: height,comps: [{type: 'rect',rect: [padding, padding, indent – 2 * padding, height – 2 * padding],background: 'red',gradient: gradient,gradientColor: 'white'}]};});gradientComboBox.setValues(gradients);gradientComboBox.setValue('linear.southwest');gradientComboBox.setWidth(90);gradientComboBox.setDropDownWidth(140);gradientComboBox.drawValue = function(g, value, selected, x, y, w, h){var self = this,indent = self.getIndent(),label = self.toLabel(value),icon = gradientImages[value];if(icon){ht.Default.drawCenterImage(g, icon, x+indent/2, y+h/2);x += indent;}if(label){ht.Default.drawText(g, label, self.getLabelFont(value, selected), self.getLabelColor(value, selected), x, y, 0, h);}};gradientComboBox.onValueChanged = function(oldValue, newValue){onComboBoxValueChanged(dataModel, oldValue, newValue, 'shape.gradient', this);};return gradientComboBox;}

这是背景渐变效果列表的具体构建代码,我来描述下具体的设计思路:

将HT

HT for Web

function onComboBoxValueChanged(dataModel, oldValue, newValue, style, scope){var sm = dataModel.sm();if(sm.size() === 0){dataModel.each(function(data){data.setStyle(style, newValue);}, scope);}else{sm.each(function(data){data.setStyle(style, newValue);}, scope);}}

代码很简单,,做的事情也很简单,接下来我们就来分析下代码的具体实现:

, newValue, styleselectionModel sm;

到此自绘制HT

发光并非太阳的专利,你也可以发光

自绘制HT For Web ComboBox下拉框组件

相关文章:

你感兴趣的文章:

标签云: