Change ServerMeterView font and/or size?

It seems like the font choice and size are hard coded into the ServerMeterView.sc file. Am I seeing that right? I’m not great at reading the source .sc files.

Just wondering if there’s a simple way to adjust the size/appearance of a simple ServerMeterView.new(s, ~mainwindow, 0@0, 1, 2); in a GUI I’m putting together.

yes, there are ways.

either you can modify a copy of the ServerMeterView class file (or subclass it) and then save your variant with a new class name.

or you can, perhaps better and what i sometimes do, reach in and manipulate views in an existing ServerMeterView instance. like this…


~mainwindow= Window().front;
v= ServerMeterView.new(s, ~mainwindow, 0@0, 1, 2);
v.view.allChildren.do{|c| if(c.isKindOf(StaticText), {c.font = Font.monospace(14)})};
~mainwindow.refresh;

this technique will work for most basic features like font sizes and colours and can also be handy to for example toggle all canFocus_ in a gui.

although in this case we need to do some more work. some of the text is drawn from within a UserView. (starting at line 35 in ServerMeter.sc)
the way to change that in an existing meter is to swap out the whole drawFunc. not optimal but, oh well.

so first we figure out which view is the UserView…

v.view.allChildren.do{|c| c.postln};

it’s #2.
then we can copy the drawFunc code from the class source file, modify it and write it back like this…


(
var meterWidth = v.view.allChildren[2].bounds.width;
v.view.allChildren[2].drawFunc = {
try {
Pen.color = \QPalette.asClass.new.windowText;
} {
Pen.color = Color.white;
};
Pen.font = Font.monospace(12); //my custom font!
Pen.stringCenteredIn("0", Rect(0, 0, meterWidth, 12));
Pen.stringCenteredIn("-80", Rect(0, 170, meterWidth, 12));
};
~mainwindow.refresh;
)

the meterWidth variable made this slightly messy. you can simplify the whole function and add your own hardcoded values…


(
v.view.allChildren[2].drawFunc = {
Pen.color = Color.white;
Pen.font = Font.monospace(12);
Pen.stringCenteredIn("0", Rect(0, 0, 15, 12));
Pen.stringCenteredIn("-80", Rect(0, 170, 15, 12));
};
~mainwindow.refresh;
)

_f

22 juli 2021 kl. 01:40 skrev stwbass via scsynth <noreply@m.scsynth.org>:

stwbass
July 21

It seems like the font choice and size are hard coded into the ServerMeterView.sc file. Am I seeing that right? I’m not great at reading the source .sc files.

Just wondering if there’s a simple way to adjust the size/appearance of a simple ServerMeterView.new(s, ~mainwindow, 0@0, 1, 2); in a GUI I’m putting together.


Visit Topic or reply to this email to respond. Email replies to this address may be posted publicly and archived on scsynth.org (privacy policy).

You are receiving this because you enabled mailing list mode. To unsubscribe from these emails, click here.

#|
fredrikolofsson.com musicalfieldsforever.com

1 Like

brilliant! thank you so much!