Jump to content

UniColorComboBox


Recommended Posts

  • 1 month later...
On 10/3/2021 at 11:43 PM, Sherzod said:

Limitations:

procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);
begin
  FormatSettings.DecimalSeparator := '.';
end;

Removing this dependency:

initialization
  UniAddCSSLibrary('build/packages/ux/classic/classic/resources/ux-all.css', False, [upoFolderJS, upoPlatformDesktop]);
  UniAddJSLibrary('build/packages/ux/classic/ux.js', False, [upoFolderJS, upoPlatformDesktop]);
  UniAddJSLibrary('xx.js', False, [upoFolderFiles]);  //<-------------

xx.js:

Ext.ux.colorpick.ColorUtils.parseColor = function(d, g) {
    if (!d) {
        return null
    }
    var e = this,
        f = e.colorMap[d],
        b, c, h;
    if (f) {
        c = {
            r: f[0],
            g: f[1],
            b: f[2],
            a: 1
        }
    } else if (d === 'transparent') {
        c = {
            r: 0,
            g: 0,
            b: 0,
            a: 0
        }
    } else {
        b = e.hexRe.exec(d);
        if (b) {
            b = b[1];
            switch (b.length) {
                default:
                    return null;
                case 3:
                    c = {
                        r: parseInt(b[0] + b[0], 16),
                        g: parseInt(b[1] + b[1], 16),
                        b: parseInt(b[2] + b[2], 16),
                        a: 1
                    };
                    break;
                case 6:
                case 8:
                    c = {
                        r: parseInt(b.substr(0, 2), 16),
                        g: parseInt(b.substr(2, 2), 16),
                        b: parseInt(b.substr(4, 2), 16),
                        a: parseInt(b.substr(6, 2) || 'ff', 16) / 255
                    };
                    break;
            }
        } else {
            b = e.rgbaRe.exec(d);
            if (b) {
                c = {
                    r: parseFloat(b[1]),
                    g: parseFloat(b[2]),
                    b: parseFloat(b[3]),
                    a: parseFloat(b[4])
                }
            } else {
                b = e.rgbaAltRe.exec(d);
                if (b) {
                    c = e.parseColor(b[1]);
                    c.a = parseFloat(b[2]);
                    return c
                }
                b = e.rgbRe.exec(d);
                if (b) {
                    c = {
                        r: parseFloat(b[1]),
                        g: parseFloat(b[2]),
                        b: parseFloat(b[3]),
                        a: 1
                    }
                } else {
                    return null
                }
            }
        }
    }
    if (g) {
        //c.a = Ext.util.Format.number(c.a, g);
        c.a = c.a.toFixed(2);
    }
    h = this.rgb2hsv(c.r, c.g, c.b);
    return Ext.apply(c, h)
}

I think this is enough and it won't affect other parts of the framework that use this method.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

procedure LoadColorpickExt;
begin
  UniAddCSSLibrary('build/packages/ux/classic/classic/resources/ux-all.css', False, [upoFolderJS, upoPlatformDesktop]);
  UniAddJSLibrary('build/packages/ux/classic/ux.js', False, [upoFolderJS, upoPlatformDesktop]);
  UniAddJSLibrary('colorpickext.js', False, [upoFolderFiles]);
end;


initialization
  RegisterServerModuleClass(TUniServerModule);
  LoadColorpickExt;

Screenshot_19.jpg

Link to comment
Share on other sites

2 hours ago, x11 said:
UniAddJSLibrary('colorpickext.js', False, [upoFolderFiles]);

Sorry, it seems I forgot to include upoPlatformDesktop as well:

UniAddJSLibrary('colorpickext.js', False, [upoFolderFiles, upoPlatformDesktop]);

And just in case, I changed the script colorpickext.js (added Ext.onReady😞

Ext.onReady(function() {
    Ext.ux.colorpick.ColorUtils.parseColor = function(d, g) {
        if (!d) {
            return null
        }
        var e = this,
            f = e.colorMap[d],
            b, c, h;
        if (f) {
            c = {
                r: f[0],
                g: f[1],
                b: f[2],
                a: 1
            }
        } else if (d === 'transparent') {
            c = {
                r: 0,
                g: 0,
                b: 0,
                a: 0
            }
        } else {
            b = e.hexRe.exec(d);
            if (b) {
                b = b[1];
                switch (b.length) {
                    default:
                        return null;
                    case 3:
                        c = {
                            r: parseInt(b[0] + b[0], 16),
                            g: parseInt(b[1] + b[1], 16),
                            b: parseInt(b[2] + b[2], 16),
                            a: 1
                        };
                        break;
                    case 6:
                    case 8:
                        c = {
                            r: parseInt(b.substr(0, 2), 16),
                            g: parseInt(b.substr(2, 2), 16),
                            b: parseInt(b.substr(4, 2), 16),
                            a: parseInt(b.substr(6, 2) || 'ff', 16) / 255
                        };
                        break;
                }
            } else {
                b = e.rgbaRe.exec(d);
                if (b) {
                    c = {
                        r: parseFloat(b[1]),
                        g: parseFloat(b[2]),
                        b: parseFloat(b[3]),
                        a: parseFloat(b[4])
                    }
                } else {
                    b = e.rgbaAltRe.exec(d);
                    if (b) {
                        c = e.parseColor(b[1]);
                        c.a = parseFloat(b[2]);
                        return c
                    }
                    b = e.rgbRe.exec(d);
                    if (b) {
                        c = {
                            r: parseFloat(b[1]),
                            g: parseFloat(b[2]),
                            b: parseFloat(b[3]),
                            a: 1
                        }
                    } else {
                        return null
                    }
                }
            }
        }
        if (g) {
            //c.a = Ext.util.Format.number(c.a, g);
            c.a = c.a.toFixed(2);
        }
        h = this.rgb2hsv(c.r, c.g, c.b);
        return Ext.apply(c, h)
    }
})

 

  • Thanks 1
Link to comment
Share on other sites

  • 4 weeks later...

Hi @Sherzod,

i got error when compile this line,

procedure TUniColorComboBox.LoadCompleted;
begin
  inherited;

  SetDomStyleCSSProperty('z-index', '10', '.x-colorpicker-field-swatch');
  SetDomStyleCSSProperty('left', '2px', '.x-colorpicker-field-swatch');
  SetDomStyleCSSProperty('width', FColorWidth, '.x-colorpicker-field-swatch');

  --> JSAddElEvent('click', 'swatchEl', ['this'], 'this.component.onTriggerClick()', nil, JSControl);
.
.
.
end;

No error when i change with this : 

JSAddElEvent('click', 'swatchEl', ['this'], 'this.component.onTriggerClick()');

may i change it like that?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...