ServerMeterView in Layout

Is it possible to put a ServerMeterView in a Layout? I don’t understand the behavior here

I can create a View with a layout and add a ServerMeterView outside the Layout

a = Window.new().layout_(VLayout(StaticText().string_("not working"), TextField())).front;
v = ServerMeterView.new(s,a,0@0,2,2);

but not if it’s an HLayout

a = Window.new().layout_(HLayout(StaticText().string_("not working"), TextField())).front;
v = ServerMeterView.new(s,a,0@0,2,2);

and it fails if I try to put it directly in the VLayout

a = Window.new().layout_(VLayout(StaticText().string_("not working"), TextField(), ServerMeterView.new(s,a,0@0,2,2))).front;

I’m new to Layouts so I probably misunderstand something. I had it working fine using FlowLayout and Views, but I’m trying to switch the UI over to Layouts. This is on Windows 10 with SC 3.12.0, if that’s part of the issue.

Thanks!

The catch is to add the ServerMeterView into its own View, and then put the containing View into the Layout.

// OK: A View can contain a ServerMeterView
(
w = Window("test", Rect(800, 200, 500, 400)).front;
v = View(w, w.view.bounds.insetBy(10, 10));
m = ServerMeterView(s, v, Point(0, 0), 2, 2);
)

// Not OK: HLayout can't contain ServerMeterView
(
w = Window("test", Rect(800, 200, 500, 400)).front;
m = ServerMeterView(s, nil, Point(0, 0), 2, 2);
w.layout = HLayout(m);
)

// OK: HLayout can contain a View
// and the View can contain anything including ServerMeterView
(
w = Window("test", Rect(800, 200, 500, 400)).front;

v = View();
m = ServerMeterView(s, v, Point(0, 0), 2, 2);

w.layout = HLayout(v);
)

hjh

2 Likes

perfect. thanks! took out too many layers trying to simplify during problem solving