HLayout StaticText

Hey,
i would like to put StaticText in the top left corner of each view of the HLayout and not quite happy with declaring fixed pixels on the screen. Is there a way to make the position of the StaticText in dependency of the Position of the View in the HLayout?
In Addition: can the text variables put together in one variable “texts” to set for example the size and font of the text for all of the texts. Do I have to declare a function for this? thanks.

//var txt = txt.font = Font("Monaco", 11);
var durtxt = StaticText(window, Rect(20, 10, 200, 20)).string_("durations").front;
var reptxt = StaticText(window, Rect(415, 10, 200, 20)).string_("repetitions").front;
var ntstxt = StaticText(window, Rect(810, 10, 200, 20)).string_("notes").front;

code:

(
~getRandomSet = {
	arg set;
	var numSteps = rrand(10,30);
	set = set ? ();
	set.putAll((
		durations: {exprand(0.1,2)}!numSteps,
		repetitions: {5.rand}!numSteps,
		notes: {rrand(-24,24)}!numSteps,
        // added motif here
		motif: {rrand(-12,12)}!5
	));
};

~viewSet = {
	arg set;
	var window = Window.closeAll.new("Mark Fell Sequencer", Rect.new(700, 450, 1200, 400));

	//var txt = txt.font = Font("Monaco", 11);
	var durtxt = StaticText(window, Rect(20, 10, 200, 20)).string_("durations").front;
	var reptxt = StaticText(window, Rect(415, 10, 200, 20)).string_("repetitions").front;
	var ntstxt = StaticText(window, Rect(810, 10, 200, 20)).string_("notes").front;

	var sliders = (
		durations: MultiSliderView().background_(Color.rand),
		repetitions: MultiSliderView().background_(Color.rand),
		notes: MultiSliderView().background_(Color.rand)
	);

	var specs = (
		durations: ControlSpec(0.01,10,\exp),
		repetitions: ControlSpec(0,10,\lin,1),
		notes: ControlSpec(30,100,\lin,0.5), //quarter-tones
	);

	var updater = {
		loop{
			sliders.keysValuesDo{
				arg k,sl;
				sl.value = specs[k].unmap(set[k]);
			};
			0.1.wait;
		};
	}.fork(AppClock);

	sliders.keysValuesDo{
		arg k,sl;
		sl.action = { set[k] = specs[k].map(sl.value).postln };
		sl.elasticMode_(1); // makes the squares fit evenly
		sl.showIndex = true; // cursor mode
	};

	window.view.layout = HLayout(*[\durations,\repetitions,\notes].collect(sliders[_]));
	window.onClose = { updater.free };
	window.front.alwaysOnTop_(true);
};
)
a = ~getRandomSet.();
~viewSet.(a);

The structure would be:

  • HLayout
    • VLayout
      • StaticText
      • MultiSliderView
    • VLayout
      • StaticText
      • MultiSliderView
    • VLayout
      • StaticText
      • MultiSliderView

Nested layouts are kind of the essence of the whole layout approach.

hjh

thanks @jamshark70. I have found “Layout Management” in the help file. This is probably helping out.

its working now :slight_smile: But changing the size of the font is not working. Is there something wrong with the syntax?

var texts = (
	durations: StaticText().string_("durations").font_("Helvetica", 14),
	repetitions: StaticText().string_("repetitions").font_("Helvetica", 14),
	notes: StaticText().string_("notes").font_("Helvetica", 14),
);

window.view.layout_(
	HLayout(
		VLayout(
			texts[\durations],
			sliders[\durations]
		),
		VLayout(
			texts[\repetitions],
			sliders[\repetitions],
		),
		VLayout(
			texts[\notes],
			sliders[\notes]
		),
	)
);

http://doc.sccode.org/Classes/StaticText.html#Basic%20Example

// adjust look , alignment and content
a.background=Color.grey;
a.align = \center;
a.font = Font("Monaco", 11);
a.string = "Your Rolex";

It needs to be a Font object. You’ve given a string and a number, which are in themselves not a Font.

hjh