public void ApplySkin(UISkinData skin) { Toggle toggle = GetComponent <Toggle>(); toggle.GetComponent <RectTransform>().sizeDelta = skin.toggleSize; toggle.colors = skin.buttonColorBlock; }
public void ApplySkin(UISkinData skin) { TMP_Text text = GetComponent <TMP_Text>(); text.font = skin.font; text.color = skin.normalTextColor; text.enableAutoSizing = false; switch (textFormat) { case TextFormat.Header1: text.fontSize = skin.fontSizeH1; break; case TextFormat.Header2: text.fontSize = skin.fontSizeH2; break; case TextFormat.Body: text.fontSize = skin.fontSizeBody; break; case TextFormat.Small: text.fontSize = skin.fontSizeSmall; break; } //print( gameObject.transform.parent.parent.name + ">>" + gameObject.transform.parent.name + ">>" + gameObject.GetInstanceID() + "font size" + text.fontSize); }
void ISkinHandler.ApplySkin(UISkinData skin) { fillImage.color = skin.buttonColorBlock.selectedColor; backgroundImage.color = skin.normalTextColor; Slider slider = GetComponent <Slider>(); slider.colors = skin.buttonColorBlock; }
public void ApplySkin(UISkinData skin) { button.transition = Selectable.Transition.ColorTint; button.colors = skin.buttonColorBlock; TMP_Text[] labels = button.GetComponentsInChildren <TMP_Text>(); foreach (TMP_Text label in labels) { label.color = skin.buttonTextColor; } //button.image.sprite = skin.buttonSprite; }
public virtual void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { OnQuestionAnswered += answeredEvent; question = q; if (question.required) { string strAterixColor = "#" + ColorUtility.ToHtmlStringRGB(skinData.requiredAsterixColor); question.instructions += " " + "<" + strAterixColor + "><b>*</b></color>"; } gameObject.name = "QurstionPanel" + question.questiontype + "_" + question.id; if (q.instructions == null || q.instructions.Length == 0) { headerLayout.gameObject.SetActive(false); } this.skinData = skinData; }
void GenerateQuestionnaireUI(Questionnaire questionnaire, UISkinData skin) { // TODO: Clear UI if (studySettings.questionnaireHeaderAs1stQuestion) { TextViewQuestion textViewQuestion = new TextViewQuestion() { id = "title", title = questionnaire.title, text = questionnaire.instructions }; var questions = questionnaire.questions.ToList(); questions.Insert(0, textViewQuestion); questionnaire.questions = questions.ToArray(); } foreach (Question question in questionnaire.questions) { QuestionPanelUI panelUI = GeneratePanelForQuestionType(question.questiontype); if (panelUI != null) { panelUI.SetQuestion(question, questionnairePanel.OnQuestionAnswered, skin); panelUI.SetQuestionIDVisibility(studySettings.showQuestionId); questionnairePanel.questionPanels.Add(panelUI); panelUI.HidePanel(); } } questionnairePanel.Init(); //Canvas.ForceUpdateCanvases(); //questionnairePanelUI.contentScrollbarVertical.value = 1; //Canvas.ForceUpdateCanvases(); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); multiFieldQuestion = question as MultiFieldQuestion; instructionsText.text = question.instructions; idText.text = question.id; placeholder.text = multiFieldQuestion.placeholder; inputField.onSubmit.AddListener(OnMultiFieldSubmit); inputField.onDeselect.AddListener(OnMultiFieldSubmit); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); radioListQuestion = question as RadioListQuestion; instructionsText.text = question.instructions; idText.text = question.id; toggles = new List <Toggle>(); //VariableGridLayoutGroup gridLayout; //LayoutGroup layoutGroup; //if(radioListQuestion.horizontal) { // layoutGroup = itemsUI.gameObject.AddComponent<HorizontalLayoutGroup>(); // layoutGroup.childAlignment = TextAnchor.MiddleCenter; // layoutGroup.padding.left = 1; // layoutGroup.padding.right = 1; // layoutGroup.padding.top = 1; // layoutGroup.padding.bottom = 1; //} else { // layoutGroup = itemsUI.gameObject.AddComponent<VerticalLayoutGroup>(); // layoutGroup.childAlignment = TextAnchor.MiddleCenter; // layoutGroup.padding.left = 1; // layoutGroup.padding.right = 1; // layoutGroup.padding.top = 1; // layoutGroup.padding.bottom = 1; //} VariableGridLayoutGroup gridLayoutGroup = itemsUI.gameObject.AddComponent <VariableGridLayoutGroup>(); gridLayoutGroup.childAlignment = TextAnchor.MiddleCenter; gridLayoutGroup.padding.left = 1; gridLayoutGroup.padding.right = 1; gridLayoutGroup.padding.top = 1; gridLayoutGroup.padding.bottom = 1; gridLayoutGroup.spacing = new Vector2(0, skinData.fontSizeBody); gridLayoutGroup.constraint = VariableGridLayoutGroup.Constraint.FixedColumnCount; gridLayoutGroup.constraintCount = 2; for (int i = 0; i < radioListQuestion.labels.Length; i++) { //GameObject container = new GameObject("container",typeof(RectTransform)); //container.AddComponent<HorizontalLayoutGroup>(); GameObject label = Instantiate(labelPrefab); LayoutElement labelLayout = label.GetComponent <LayoutElement>(); labelLayout.flexibleWidth = skinData.canvasSize.x * 0.6f; // 10; labelLayout.preferredWidth = skinData.canvasSize.x * 0.75f; labelLayout.minWidth = -1; labelLayout.minHeight = -1; //labelLayout.flexibleWidth = 10; //labelLayout.preferredWidth = 12; //labelLayout.minWidth = -1; //labelLayout.minHeight = -1; TMP_Text text = label.GetComponent <TMP_Text>(); text.text = radioListQuestion.labels[i]; //text.autoSizeTextContainer = true; //text.enableAutoSizing = true; text.ForceMeshUpdate(true); text.GetComponent <SkinText>().textFormat = TextFormat.Body; text.margin = new Vector4(text.fontSize, 0, 0, 0); GameObject radioItem = Instantiate(radioItemPrefab); Toggle toggle = radioItem.GetComponent <Toggle>(); LayoutElement toggleLayout = toggle.GetComponent <LayoutElement>(); toggleLayout.flexibleWidth = 1; toggle.SetIsOnWithoutNotify(false); toggles.Add(toggle); toggle.onValueChanged.AddListener((val) => { OnItemSelected(toggle, radioListQuestion.id, val); }); //container.transform.parent = itemsUI; radioItem.transform.parent = itemsUI; label.transform.parent = itemsUI; //container.transform.localPosition = Vector3.zero; //container.transform.localRotation = Quaternion.identity; //container.transform.localScale = Vector3.one; label.transform.localPosition = Vector3.zero; label.transform.localRotation = Quaternion.identity; label.transform.localScale = Vector3.one; // label.transform.parent.localScale; radioItem.transform.localPosition = Vector3.zero; radioItem.transform.localRotation = Quaternion.identity; radioItem.transform.localScale = Vector3.one; // radioItem.transform.parent.localScale; if (label.GetComponent <Button>()) { Button btn = label.GetComponent <Button>(); btn.onClick.AddListener(() => { toggle.isOn = !toggle.isOn; }); } } LayoutRebuilder.ForceRebuildLayoutImmediate(itemsUI); //Canvas.ForceUpdateCanvases(); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData = null) { base.SetQuestion(q, answeredEvent, skinData); radioGridQuestion = question as RadioGridQuestion; instructionsText.text = question.instructions; idText.text = question.id; questionItems = new List <List <Toggle> >(); VerticalLayoutGroup panelLayout = itemsUI.GetComponent <VerticalLayoutGroup>(); panelLayout.spacing = 0.0f; panelLayout.padding.left = 0; panelLayout.padding.right = 0; panelLayout.padding.top = 0; panelLayout.padding.bottom = 1; for (int i = 0; i < radioGridQuestion.q_text.Length; i++) { GameObject textObj = Instantiate(labelPrefab); LayoutElement layout = textObj.GetComponent <LayoutElement>(); layout.enabled = true; layout.minHeight = 1; layout.minWidth = 1; layout.preferredWidth = 2; layout.preferredHeight = 1.5f; TMP_Text questionText = textObj.GetComponent <TMP_Text>(); questionText.text = radioGridQuestion.q_text[i].text; questionText.alignment = TextAlignmentOptions.Bottom; Vector2 textSize = questionText.GetPreferredValues(radioGridQuestion.q_text[i].text); //questionText.margin = new Vector4(0,0,1,-0.75f); textObj.transform.parent = itemsUI; textObj.transform.localPosition = Vector3.zero; textObj.transform.localRotation = Quaternion.identity; textObj.transform.localScale = textObj.transform.parent.localScale; //RadioGroup radioGroup = new RadioGroup(radioGridQuestion.q_text[i].id); List <Toggle> toggles = new List <Toggle>(); //radioGroup.OnGroupSelected += OnItemSelected; GameObject itemsContainer = new GameObject("itemsContainer", typeof(RectTransform)); itemsContainer.transform.parent = itemsUI; itemsContainer.transform.localPosition = Vector3.zero; itemsContainer.transform.localRotation = Quaternion.identity; itemsContainer.transform.localScale = itemsContainer.transform.parent.localScale; HorizontalLayoutGroup horizontalLayoutGroup = itemsContainer.AddComponent <HorizontalLayoutGroup>(); horizontalLayoutGroup.childControlHeight = true; horizontalLayoutGroup.childControlWidth = true; //horizontalLayoutGroup.spacing = -2; for (int j = 0; j < radioGridQuestion.labels.Length; j++) { GameObject container = new GameObject("container", typeof(RectTransform)); VerticalLayoutGroup verticalLayoutGroup = container.AddComponent <VerticalLayoutGroup>(); verticalLayoutGroup.childControlWidth = true; verticalLayoutGroup.childControlHeight = true; verticalLayoutGroup.spacing = 0.2f; container.transform.parent = itemsContainer.transform; container.transform.parent = container.transform; container.transform.localPosition = Vector3.zero; container.transform.localRotation = Quaternion.identity; container.transform.localScale = container.transform.parent.localScale; GameObject label = Instantiate(labelPrefab); TMP_Text labelText = label.GetComponent <TMP_Text>(); labelText.GetComponent <SkinText>().textFormat = TextFormat.Small; labelText.text = radioGridQuestion.labels[j]; labelText.alignment = TextAlignmentOptions.Center; labelText.fontStyle = FontStyles.Italic; label.transform.parent = container.transform; label.transform.localPosition = Vector3.zero; label.transform.localRotation = Quaternion.identity; label.transform.localScale = Vector3.one; LayoutElement labelLayout = labelText.GetComponent <LayoutElement>(); labelLayout.enabled = true; labelLayout.minWidth = skinData.toggleSize.x; labelLayout.minHeight = 0.5f; // skinData.toggleSize.y; labelLayout.preferredWidth = skinData.toggleSize.x; labelLayout.preferredHeight = 1.0f; // skinData.toggleSize.y; GameObject item = Instantiate(radioItemPrefab); Toggle toggle = item.GetComponent <Toggle>(); //LayoutElement toggleLayout = textObj.GetComponent<LayoutElement>(); //toggleLayout.enabled = true; //toggleLayout.minHeight = 1; //toggleLayout.minWidth = 1; //toggleLayout.preferredWidth = 1; //toggleLayout.preferredHeight = 1; //radioGroup.AddToggle(toggle); toggle.SetIsOnWithoutNotify(false); toggle.onValueChanged.AddListener((val) => { OnItemSelected(toggle, radioGridQuestion.id, val); }); toggles.Add(toggle); item.transform.parent = container.transform; item.transform.localPosition = new Vector3(0, 0, skinData.radioZOffset); //item.transform.localPosition = Vector3.zero; item.transform.localRotation = Quaternion.identity; item.transform.localScale = Vector3.one; } //radioGroup.Init(); //questionItems.Add(radioGroup); questionItems.Add(toggles); } //Canvas.ForceUpdateCanvases(); //LayoutGridElements(); //Invoke("LayoutGridElements",0.16f); //Canvas.ForceUpdateCanvases(); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); submitQuestion = q as SubmitQuestion; submitButton.onClick.AddListener(Submit); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); sliderQuestion = question as SliderQuestion; instructionsText.text = question.instructions; idText.text = question.id; minLabel.text = sliderQuestion.left; maxLabel.text = sliderQuestion.right; slider.minValue = sliderQuestion.min_value; slider.maxValue = sliderQuestion.max_value; slider.wholeNumbers = question.datatype == QuestionDataType.Integer; slider.SetValueWithoutNotify(slider.minValue); valueLabel.text = slider.value.ToString(); slider.onValueChanged.AddListener(OnSliderValueChanged); incrementValueButton.onClick.AddListener(IncrementValue); decrementValueButton.onClick.AddListener(DecrementValue); sliderQuestion.answer = !float.IsNaN(sliderQuestion.min_value) ? sliderQuestion.min_value : 0; }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); fieldQuestion = question as FieldQuestion; instructionsText.text = question.instructions; idText.text = question.id; placeholder.text = fieldQuestion.placeholder; inputField.onValueChanged.AddListener(OnFieldSubmited); //inputField.onEndEdit.AddListener(OnFieldSubmited); //inputField.onSubmit.AddListener(OnFieldSubmited); //inputField.onDeselect.AddListener(OnFieldSubmited); }
public void ApplySkin(UISkinData skin) { Button btn = GetComponent <Button>(); btn.colors = skin.submitColorBlock; }
public void ApplySkin(UISkinData skin) { image.sprite = skin.panelSprite; image.color = skin.backgroundColor; }
public void ApplySkin(UISkinData skin) { TMP_Dropdown dropdown = GetComponent <TMP_Dropdown>(); dropdown.colors = skin.buttonColorBlock; }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); downQuestion = q as DropDownQuestion; instructionsText.text = question.instructions; idText.text = question.id; dropdown.ClearOptions(); dropdown.AddOptions(downQuestion.items); dropdown.onValueChanged.AddListener(OnDropDownValueChanged); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); instructionsText.text = question.instructions; idText.text = question.id; toggles = new List <Toggle>(); checkQuestion = (question as CheckListQuestion); gridLayout.startAxis = VariableGridLayoutGroup.Axis.Horizontal; int factor = checkQuestion.questions.Length / maxQuestionsVertical; factor = (factor == 0 ? 1 : factor); //if(checkQuestion.horizontal) { // gridLayout.constraint = VariableGridLayoutGroup.Constraint.FixedRowCount; // gridLayout.constraintCount = 1; // gridLayout.childAlignment = TextAnchor.MiddleCenter; //}else{ gridLayout.constraint = VariableGridLayoutGroup.Constraint.FixedColumnCount; gridLayout.constraintCount = 2 * factor; gridLayout.childAlignment = TextAnchor.MiddleCenter; gridLayout.spacing = spacing; maxWidth = maxTextWidth / factor; maxHeight = maxTextHeight / factor; //} for (int i = 0; i < checkQuestion.questions.Length; i++) { //GameObject labeledItem = Instantiate(checkItemLabeledPrefab); //GameObject checkItem = labeledItem.transform.Find("Checkbox").gameObject; GameObject checkItem = Instantiate(checkItemPrefab); Toggle toggle = checkItem.GetComponent <Toggle>(); toggle.isOn = false; toggle.onValueChanged.AddListener(HandleToggleValueChanged); LayoutElement toggleLayout = toggle.GetComponent <LayoutElement>(); toggleLayout.enabled = true; toggleLayout.minWidth = skinData.toggleSize.x; toggleLayout.minHeight = skinData.toggleSize.y; toggles.Add(toggle); //GameObject label = labeledItem.transform.Find("QuestionLabelInteractive").gameObject; GameObject label = Instantiate(labelPrefab); TMP_Text text = label.GetComponent <TMP_Text>(); text.text = checkQuestion.questions[i].text; text.margin = new Vector4(-spacing.x / 4f, 0, 0, 0); text.autoSizeTextContainer = true; //text.enableAutoSizing = true; text.ForceMeshUpdate(true); LayoutElement labelLayout = label.GetComponent <LayoutElement>(); //float w = text.preferredWidth * preferredWidthScaler; //float h = text.preferredHeight * preferredHeightScaler; ////labelLayout.preferredWidth = - 1; ////labelLayout.preferredHeight = - 1; //labelLayout.preferredWidth = -1; //Mathf.Clamp(w,0,maxWidth); //labelLayout.preferredHeight = -1; // Mathf.Clamp(h,0,maxHeight); if (factor == 1) { labelLayout.flexibleWidth = skinData.canvasSize.x * 0.6f; // 10; labelLayout.preferredWidth = skinData.canvasSize.x * 0.75f; labelLayout.minWidth = -1; labelLayout.minHeight = -1; } if (label.GetComponent <Button>()) { Button btn = label.GetComponent <Button>(); btn.onClick.AddListener(() => { toggle.isOn = !toggle.isOn; }); } //labeledItem.transform.parent = itemsUI; checkItem.transform.parent = itemsUI; label.transform.parent = itemsUI; label.transform.localPosition = new Vector3(0, 0, skinData.radioZOffset); label.transform.localRotation = Quaternion.identity; label.transform.localScale = label.transform.parent.localScale; checkItem.transform.localPosition = new Vector3(0, 0, skinData.radioZOffset); //checkItem.transform.localPosition = Vector3.zero; checkItem.transform.localRotation = Quaternion.identity; checkItem.transform.localScale = label.transform.parent.localScale; } LayoutRebuilder.ForceRebuildLayoutImmediate(itemsUI); }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); textViewQuestion = question as TextViewQuestion; idText.text = question.id; text.text = textViewQuestion.text; instructionsText.text = textViewQuestion.title; instructionsText.fontSize = skinData.fontSizeH2; question.isAnswered = true; }
public override void SetQuestion(Question q, UnityAction <Question> answeredEvent, UISkinData skinData) { base.SetQuestion(q, answeredEvent, skinData); inputField.enableWordWrapping = false; numFieldQuestion = question as NumFieldQuestion; instructionsText.text = question.instructions; idText.text = question.id; //switch(question.datatype) { //case QuestionDataType.Integer: // inputField.contentType = TMP_InputField.ContentType.IntegerNumber; // break; //case QuestionDataType.Float: // inputField.contentType = TMP_InputField.ContentType.DecimalNumber; // break; //} //incrementButton.gameObject.SetActive(numFieldQuestion.spinbutton); //decrementButton.gameObject.SetActive(numFieldQuestion.spinbutton); //if(numFieldQuestion.spinbutton) { // incrementButton.onClick.AddListener(IncrementValue); // //decrementButton.onClick.AddListener(DecrementValue); //} //inputField.onSelect.AddListener(OnFieldSelected); //inputField.onValueChanged.AddListener(OnNumFieldSubmitted); //inputField.onSubmit.AddListener(OnNumFieldSubmitted); //inputField.onDeselect.AddListener(OnNumFieldSubmitted); if (numberPad) { numberPad.OnNumberSelected += NumberPad_OnNumberSelected; //numberPad.OnConfirm += NumberPad_OnConfirm; numberPad.OnDelete += NumberPad_OnDelete; } }