omz / Pythonista-Issues

Issue tracker for Pythonista (iOS)
169 stars 14 forks source link

Inconsistent color parsing, invalid RGBA values #523

Open zrzka opened 6 years ago

zrzka commented 6 years ago

System Information

Working device

User has no issue on iOS 9.3.5, iPad Mini, Pythonista 3.2.

Issues

Related issues

Probably relates to https://github.com/omz/Pythonista-Issues/issues/374 where you did mention that color parsing is kind of incosistent in the Pythonista.

Also maybe there's difference in how UIColor handles negative values when you do call colorWithRed:green:blue:alpha between iOS 9 and iOS11? Guessing.

Description

See this thread. 7points user somehow managed to create tint_color in .pyui file with following values:

Green is negative, blue is negative.

Inspector in the UI designer shows this color as fffffffb

I would expect ff0000ff.

15853f1d-b727-4a34-8fa6-cd0f6ab0c23c

Alert view shows this color as fffffffa

I would expect ff0000ff, or at least ff0000 (see 3).

77a0ed25-37a9-420a-9536-51496082ed52

Alert view doesn't accept color with alpha channel

Only six 0-9a-f's can be used. Seventh and eight (alpha channel) are ignored.

I would expect that alpha channel is accepted as well.

Designer shows correct color

Looks like that designer really parses it as ff0000ff.

2e6274f2-ccd8-420c-a4a7-7f96a19bead0

Running script

But when you run it, it shows default color.

e7a09a5b-58a0-4aaf-aaa8-d7557560e8f2

Sample files

tint.py:

import ui

v = ui.load_view()
v.present('sheet')

tint.pyui:

[
  {
    "nodes" : [
      {
        "nodes" : [

        ],
        "frame" : "{{60, 106}, {120, 29}}",
        "class" : "SegmentedControl",
        "attributes" : {
          "flex" : "LR",
          "segments" : "Hello|World",
          "frame" : "{{60, 106}, {120, 29}}",
          "tint_color" : "RGBA(1.000000,-0.021739,-0.021739,1.000000)",
          "uuid" : "B7DD73C0-65AF-42DE-B501-6403EC9466B7",
          "class" : "SegmentedControl",
          "name" : "segmentedcontrol1"
        },
        "selected" : false
      }
    ],
    "frame" : "{{0, 0}, {240, 240}}",
    "class" : "View",
    "attributes" : {
      "enabled" : true,
      "background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)",
      "tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)",
      "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)",
      "flex" : ""
    },
    "selected" : false
  }
]
zrzka commented 6 years ago

Glad we have all these simulators ...

UIColor *color = [UIColor colorWithRed:1.000000 green:-0.021739 blue:-0.021739 alpha:1.000000];

CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
[color getRed:&red green:&green blue:&blue alpha:&alpha];

NSLog(@"R %f G %f B %f A %f", red, green, blue, alpha);
NSLog(@"%@", color);

iOS 9.3

R 1.000000 G 0.000000 B 0.000000 A 1.000000
UIDeviceRGBColorSpace 1 0 0 1

iOS 11.2

R 1.000000 G -0.021739 B -0.021739 A 1.000000
UIExtendedSRGBColorSpace 1 -0.021739 -0.021739 1

It seems that iOS 9.3 clamps color components values. And maybe it's not related at all.

zrzka commented 6 years ago

Despite the fact that the different iOS versions handles this color differently, when I try to tint button with this particular color in simulator / device, it works. So the problem is elsewhere.

zrzka commented 6 years ago

7points user forum follow up

I think I have found the reason for the bug: the color picker of the ui-Designer. When sliding over the colors, the hex value sometimes jumps from 6 digits to eight digits. Since 8-digit values ​​are wrong for ipad pro edition 2015, they will be ignored.