Getting Main UI widgets to scale

I’m sorry if this has already been discussed before, I’ve tried to search and read what I thought might be relevant, but I haven’t really found anything.

My problem is that I can’t find a way to get (custom) widgets to scale nicely. It’s not so much a problem with very simple widgets like most of the standard widgets, because they have quite a lot of “free space” to eat into before you get into real trouble. But when trying to make more “intricate” widgets, for example by using the echart gauges (which can produce very nice results), it quickly turns out to bite me.

I quite liked HABPanel back in OH2, but the failure to scale meant that I didn’t really bother to use it much. So, I was hoping that the new Main UI would handle it better. And while it does handle it better, it’s still limited.

The problem boils down to, as far as I can understand, that none of the units that I can use to specify distances, size etc are relative to the widget size. I know that px has been given its own “relativity logic” in HTML/CSS, but that has mostly made them useless in my opinion (because they’re unpredictable). rem and em scale to the device, but not to the viewport and certainly not to the widget. ‘vw’. etc doesn’t seem to be supported, but they wouldn’t work either. ‘%’ tends to be the percentage of something, just never what you want it to be (usually the outermost container I think).

In many ways this isn’t a problem with Main UI, it is a problem with HTML/CSS. I really wish they would come up with some way to reference a percentage of a specified parent, like 2:47% to use 47% of the second parent or something like that. But, this probably won’t happen, at least not anytime soon, so it’s not relevant here. Usually you have to solve this using JavaScript and calculate and overwrite selected values according to the circumstances. It’s somewhat fragile, ugly, slow and far from ideal, but it’s what we got. But, that’s not possible when writing YAML widgets for Main UI. So, this is where Main UI comes into the picture really.

My question is: Is there any way at all to reference the widget size that I’ve missed. If not, maybe that would be a good idea? I get that it might be somewhat complicated, but in a UI like this, I’d consider it really essential. I’d hate to have to make “one version” of each widget for each intended use, layout wise. I mean, gauges for example can be shown relatively small and still be readable, and they could “pop-up” into a larger version when pressed. As it is today, that would have to be two different widgets, or everything will be “out of scale” when it comes to line widths, fonts sizes, distances etc. The layout of each page where you want to place them will also vary, so it should be expected that they won’t always have the same size. The whole “dynamic layout” and “responsive design” kind of guarantees that widgets will be displayed in different sizes, and that just doesn’t work very well when all the internal parts of the widget is fixed-sized or “unpredictable-sized”.

You’ve hit the nail on the head here. This is very much where the limitations lie, especially if you’re interested in text scaling and there just isn’t much MainUI can do about it.

There are workarounds out there for some of these problems. The easiest, most of the time, is to continue to use % and just do the math (e.g., B is 50% of A and I want C to be 33% of B so I have to use 16.6% since the % refers all the way back up to A). But for more complex things, there might be other solutions. For example, if it’s a more graphical display you might be able to render it as an svg. If it really comes down to it, there are (fairly hacky) ways to get the widget width.

Thanks, the “fairly hacky” way seems very interesting, although potentially fragile if further restrictions are placed in the future to prevent “security exploits” and whatnot :+1:

What I was thinking was that maybe it would be possible to introduce some new “unit” like say ww and wh that worked the same way as vw and vh does only that they referenced the widget. MainUI would then have to substitute these when “compiled” with values generated by some JS code that would exist in all widgets that used these “units”. I know nothing about how this is done technically in MainUI, so this might not be possible at all, but I would think that if it is, it would be quite valuable for widgets in general.

Hi

I have this problem in the Main ui. The layout doesn’t hit nicely.

Without seeing your widget or page code, it is going to be difficult to direct you to a solution.

component: oh-grid-row
config: {}
slots:
  default:
    - component: oh-grid-col
      config:
        width: "50"
      slots:
        default:
          - component: oh-slider-card
            config:
              item: HoofdlampJelmerSchouw
              label: true
              max: 100
              min: 0
              releaseOnly: true
              scale: true
              step: 1
              title: Lamp schouw
    - component: oh-grid-col
      config:
        width: "50"
      slots:
        default:
          - component: oh-slider-card
            config:
              item: HoofdlampJelmerBureau
              label: true
              max: 100
              min: 0
              releaseOnly: true
              scale: true
              step: 1
              title: Lamp bureau
    - component: oh-grid-col
      config:
        width: "50"
      slots:
        default:
          - component: oh-slider-card
            config:
              item: NachtlampJelmer
              label: true
              max: 100
              min: 0
              releaseOnly: true
              scale: true
              step: 1
              title: Nachtlamp
    - component: oh-grid-col
      config:
        width: "50"
      slots:
        default:
          - component: oh-toggle-card
            config:
              item: Lsc_mengpaneel
              outline: false
              title: Mengpaneel


What is the problem that you are trying to solve? The output you have displayed is correct based on that widget code.

Is your issue the height of the cards? Unless you manually define the height of each card, the toggle card will always be taller than the slider cards because of the nature of the toggle and slider components.

Thanks for your replay. Can you give me a sample how i can adjust the height manual for the sliders,… :slight_smile:

Control of things like the size of elements in the page is through css. This is a very large topic, and you can find many sites to help you (one of my favorites is CSS Tutorial).

See here for a discussion of how to apply css to a widget component:

In this case, you want to set the height property of the slider card so you would add something like:

style:
  height: 100px

to the card’s config, of course, adjusting the actual height value to suit your needs.

Hi Thanks for the sample but it doesn’t work for me.

component: oh-slider-card
config:
  item: NachtlampJelmer
  label: true
  max: 100
  min: 0
  releaseOnly: true
  scale: true
  step: 1
  title: Nachtlamp
  style:
  height: 100px
slots: null


In yaml. the indentations are part of the syntax. Check your posted code; the indentation of height is the same as style. In the sample I posted height is indented one more level than style to indicate that is it a key int eh style object.

1 Like

Thanks. That was the problem.

component: oh-slider-card
config:
  style:
    height: 100px
    item: NachtlampJelmer
    label: true
    max: 100
    min: 0
    releaseOnly: true
    scale: true
    step: 1
    title: Nachtlamp
  title: Nachtlamp
  item: NachtlampJelmer
slots: null