WelcomeUDT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG

//@version=5

// @description    Library for Welcome UDT
library('WelcomeUDT')


//#region ———————————————————— Library functions


// @type              Initialize type values
// @field bar         X position for label
// @field price       Y position for label
// @field phrase      Text for label
// @field bg          Color for label
// @field variable    Boolean for enable new line and delete line
export type Settings
	int     bar
	float   price
	string  phrase
	color   bg       = color.blue
	bool    variable = true


// @function    Print out label
// @param       Settings types
// @returns     Label object
export printLabel(Settings setup) =>
	if setup.variable
		var label lab = na
		label.delete(lab)
		lab := label.new(setup.bar, setup.price, setup.phrase, color = setup.bg)
	else
		label.new(setup.bar, setup.price, setup.phrase, color = setup.bg)
//#endregion



//#region ———————————————————— Example Code
// Inputs for Settings
priceInput     = input.float(    0,         minval = 0)
phraseInput    = input.text_area('Welcome UDT')
colorInput     = input.color(  color.blue)
variableInput  = input.bool(     true)

// Types for Settings
Settings setup = Settings.new(bar_index[0], priceInput, phraseInput, colorInput, variableInput)

// Alternative way to write types
// Settings setup = Settings.new(
//   bar      = bar_index[0],
//   price    = priceInput,
//   phrase   = phraseInput,
//   bg       = colorInput,
//   variable = variableInput)

printLabel(setup)
//#endregion