Eto label ignores text color and background in Rhino 7 - works in Rhino 6

Hi - I just noticed that Eto Forms text labels ignore text color and background color in Rhino 7. The UI looks fine in Rhino 6. I am on Windows and work on a compiled C# project.
Any idea what this could be about?

Colors are set in the constructor as follows:

var theLabel = new Label
{
Text = “-”,
Font = font,
TextColor = text_color,
TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Height = 45,
Width = 70,
BackgroundColor = Color.FromArgb(31, 107, 196, 80),
Wrap = WrapMode.None
};

Best,
Timur

2 Likes

@curtisw, any insight on this? The R7 Eto labels are rendering with a grey background, regardless of the BackgroundColor of the control (or its parent). Is this something that can be fixed?

Cheers,

Jon

Hey @sarg and @timkado,

This probably has something to do with the theming support for panels in Rhino 7.

@JohnM is there a way to disable theming of labels (or other controls) in v7 panels?

You can try using a Rhino.UI.Controls.StaticAlignedLabel control, it is essentially just a label that the default styling ignores. I don’t recall if I check for that in the panel styler. I have a trick for identifying things to ignore in the panel styler but it is not publicly exposed right now. I can make a public way to do it if it is an issue.

The default label style left justifies label text on Windows and right justifies it on Mac. The panel styler should only affect colors if the label is embedded in a panel.

Now that I think about this, if your label is in a Rhino tabbed panel you should be able to apply your own style to control the text and background colors, the Rhino style should not get applied if the control has a style override.

@JohnM the labels are in a dockable panel that integrates with the tabs like properties and layers etc. The text justification is not affected. Center justified text still is centered. Text color and Background color are ignored/overridden.

Did you try changing the colors in a style on your labels? The panel system creates a host Eto Panel and applies a style to the host. The style includes syncing label text and background colors. The style should get ignored if a control has a specific style associated with it.

Just seeing this now – must’ve missed a notification. Thanks for the feedback, @JohnM. To confirm Timur’s finding, I tried both the StaticAlignedLabel and applying styles. In both cases the TextColor and BackgroundColor parameters are ignored (text renders black, background grey, no matter what).

code:
style code

result:
style result

This occurs if and only if the control is part of a Rhino panel. As part of a Window or anything else, the colors render correctly.

Any other ideas for a workaround? Otherwise a fix would be great. :slight_smile:

This is my test command:

  [Guid("38A54E81-1694-4388-986D-9A7F0D9820E9")]
  public class TestPanelWithLableStyle : Panel
  {
    public TestPanelWithLableStyle()
    {
      this.Styles.Add<Label>("seahawks", c =>
      {
        c.TextColor = Colors.Blue;
        c.BackgroundColor = Colors.Green;
      });
      this.Styles.Add<Label>("yellow_on_red", c =>
      {
        c.TextColor = Colors.Yellow;
        c.BackgroundColor = Colors.Red;
      });
      Content = new RhinoTableLayout(RhinoLayout.PaddingType.RhinoPanel, RhinoLayout.SpacingType.Panel)
      {
        Rows =
        {
          new Label { Text = "Default label colors" },
          new Label { Text = "Yellow on red", Style = "yellow_on_red" },
          new Label { Text = "Go Hawks!", Style = "seahawks" },
          new Label { Text = "Another default color label" },
          null
        }
      };
    }
  }

  [CommandStyle(Style.Hidden)]
  public class TestPanelLabelColor : Rhino.Commands.Command
  {
    public TestPanelLabelColor()
    {
      Panels.RegisterPanel(CommandsPlugIn.Instance, typeof(TestPanelWithLableStyle), "Label Color Test", System.Drawing.SystemIcons.Information);
    }

    public override string EnglishName => "TestPanelLabelColor";

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      Panels.OpenPanel(typeof(TestPanelWithLableStyle).GUID);
      return Result.Success;
    }
  }

Run TestPanelLabelColor which should display something like this:

The top and bottom labels are styled using the default host style/colors, the middle two use custom styles provided by the runtime panel and control the text and background colors.

Thanks, @JohnM. I had the style set at the parent, but not the panel. :see_no_evil:

Works great now. :+1:

I have a related problem caused by the same issue here.

My plugin does not have any custom styling - the default system colors for everything.

The problem I see is when using Rhino 7 on Windows all Label backgrounds are gray. I expected it to be the default background color of the plugin.

Setting custom colors for Label background feels like a hack, and it is also different on different platforms.

Is there a suggested solution for this, or is this a bug?

Rhino 7 on MacOS
Screenshot 2021-04-26 at 10.32.34

Rhino 6 on Windows

Rhino 7 on Windows
Screenshot 2021-04-26 at 10.48.23

Thanks,
Martin

1 Like