public CheckField(string?name = null, PropertyReference <bool>?bindProp = null, Action?onChanged = null) { if (bindProp != null) { (_getter, _setter) = bindProp.GetAccessors(); name ??= bindProp.DisplayName; Ui.Drawn += Update; } Field = new CheckBox(name) { SizeLayout = new Layout2d(13, 13), PositionLayout = new Layout2d(10, 2) }; Field.Toggled += (sender, f) => { if (_uiLoading) { return; } Value = f.Value; }; if (bindProp != null && _setter == null) { Field.Enabled = false; } Add(Field); SizeLayout = new Layout2d("100%", "24"); OnChanged = onChanged; }
protected virtual void UpdateSize() { if (UseLayout) { SizeLayout = new Layout2d($"{Size.X}", IsMinimized ? $"{MarginY}" : $"{MarginY} + {_yLayout} + 1"); } else { MaximumSize = MinimumSize = new Vector2f(Size.X, MarginY + (IsMinimized ? 0 : ContentHeight)); } }
public RadioField(string name) { Field = new CheckBox(name) { SizeLayout = new Layout2d("20", "20"), PositionLayout = new Layout2d(10, 3) }; Field.Toggled += (sender, f) => { if (_uiLoading) { return; } Value = f.Value; }; Add(Field); SizeLayout = new Layout2d("100%", "24"); }
public TextField(PropertyReference <T> bindProp, string?name, PropConverter <T, string>?conv = null, bool mono = true) { _bindProp = bindProp ?? throw new ArgumentNullException(nameof(bindProp)); (_getter, _setter) = bindProp.GetAccessors(); name ??= bindProp.DisplayName; if (conv?.NameFormat != null) { name = string.Format(CultureInfo.InvariantCulture, conv.NameFormat, name); } _converter = conv ?? PropConverter.Default <T, string>(); Ui.Drawn += Update; name ??= ""; SizeLayout = new Layout2d("100%", "24"); NameLabel = new Label(name) { PositionLayout = new Layout2d("0", "3") }; NameLabel.CeilSize(); Add(NameLabel, "lblName"); Field = new EditBox { PositionLayout = new Layout2d("lblName.right + 5", "(&.h - h) / 2"), SizeLayout = new Layout2d("100% - x", "22") }; Add(Field); if (mono) { Field.Renderer.Font = Ui.FontMono; } if (_bindProp.Property is PropertyInfo pi && _bindProp.Target is BaseObject o && o.IsBound(pi.GetGetMethod() !, out var res) && res.Item1 is UserBinding ub) { _binding = ub; Field.Text = _binding.Code; } if (_setter == null) { Field.ReadOnly = true; } void Validate() { try { Value = Field.Text = Field.Text.Trim(); } catch { // } } Field.Unfocused += (sender, args) => { Validate(); }; Field.ReturnKeyPressed += (sender, s) => { Validate(); }; /*if (!multiline) * { * Field.TextChanged += (sender, s) => * { * if (s.Value[^1] == '\n') * Validate(); * }; * }*/ }
public NumberField(float min, float max, PropertyReference <T> bindProp, string?name = null, float val = 0, string?unit = null, bool deci = true, bool log = false, float step = 0.01f, PropConverter <T, float>?conv = null, float factor = 1, bool inline = false, int?round = 2) { Log = log; Factor = factor; if (bindProp != null) { (_getter, _setter) = bindProp.GetAccessors(); name ??= bindProp.DisplayName; unit ??= bindProp.Unit; _converter = conv ?? PropConverter.Default <T, float>(); Ui.Drawn += Update; } name ??= ""; unit ??= ""; if (conv?.NameFormat != null) { name = string.Format(CultureInfo.InvariantCulture, conv.NameFormat, name); } SizeLayout = new Layout2d("100%", inline ? "24" : "60"); var lblName = new Label(name) { PositionLayout = new Layout2d(5, inline ? 4 : 10) }; lblName.CeilSize(); Add(lblName, "lblName"); var lblUnit = new Label(unit); Add(lblUnit, "lblUnit"); lblUnit.PositionLayout = new Layout2d("&.w - w - 5", inline ? "4" : "10"); lblUnit.SizeLayout = new Layout2d(inline ? 20 : string.IsNullOrWhiteSpace(unit) ? 0 : lblUnit.Size.X, 18); lblUnit.CeilSize(); const int size = 40; Field = new EditBox { PositionLayout = new Layout2d(inline ? $"lblUnit.left - 5 - {size}" : "lblName.right + 5", inline ? "1" : "7"), SizeLayout = new Layout2d(inline ? $"{size}" : "lblUnit.left - 5 - x", "22") }; Add(Field, "txtValue"); if (_setter == null) { Field.ReadOnly = true; } void OnValidated(object?sender, SignalArgsString s) { if (deci) { if (float.TryParse(s.Value, out var res)) { Value = res; return; } } else { if (int.TryParse(s.Value, out var res)) { Value = res; return; } } try { var res = s.Value.Eval <object>().Result; Value = Convert.ToSingle(res, CultureInfo.CurrentCulture); } catch (Exception e) { Console.WriteLine(e); } } Field.ReturnKeyPressed += OnValidated; float smin, smax; if (Log) { (smin, smax) = ((float)Math.Log10(min), (float)Math.Log10(max)); } else { (smin, smax) = (min, max); } Slider = new Slider(smin, smax); if (!Log) { Slider.Step = step; } else { Slider.Step = 0; } var arr = -(int)Math.Log10(step); Slider.SizeLayout = new Layout2d(inline ? $"txtValue.left - lblName.right - 18" : "parent.iw - 20", "22"); Slider.PositionLayout = new Layout2d(inline ? "lblName.width + 13" : "10", inline ? "1" : "37"); if (bindProp == null) { Value = val; } Add(Slider); Slider.ValueChanged += (sender, f) => { if (_uiLoading) { return; } var sv = f.Value; if (sv == Slider.Minimum && LeftValue != null) { sv = LeftValue.Value; } else if (sv == Slider.Maximum && RightValue != null) { sv = RightValue.Value; } else { if (Log) { sv = (float)Math.Round(Math.Pow(10, sv), arr); } } Value = sv; }; Round = round; Update(); Field.CaretPosition = 0; }
public void start() { if (gui != null) { gui.RemoveAllWidgets(); } gui = new Gui(SceneManager.instance().window); font = new Font("EightBitDragon-anqx.ttf"); gui.Font = font; //Создание главной панели MainPanel = new Panel(); Layout2d layout2D = new Layout2d("20%", "100%"); MainPanel.SizeLayout = layout2D; MainPanel.Renderer.BackgroundColor = Color.Black; MainPanel.Renderer.BorderColor = Color.White; MainPanel.Renderer.Borders = new Outline(5); gui.Add(MainPanel); font = new Font("EightBitDragon-anqx.ttf"); //Создание панели с кистями. BrushesPanel = new ScrollablePanel(); BrushesPanel.ScrollbarWidth = 8; BrushesPanel.Renderer.BackgroundColor = Color.Black; BrushesPanel.Renderer.BorderColor = Color.White; BrushesPanel.PositionLayout = new Layout2d("0%", "5%"); BrushesPanel.SizeLayout = new Layout2d("100%", "25%"); MainPanel.Add(BrushesPanel); //Кисти. RadioButtonGroup brushes = new RadioButtonGroup(); Dictionary <string, Color> tempColors = BrushManager.instance().getColors(); //получаем список цветов от менеджера кистей int positionOffset = 0; //определяет смещение для кнопки foreach (var colorKey in tempColors.Keys) { positionOffset += 15; RadioButton colorBrush_Btn = new RadioButton(colorKey); //создаем кнопку с именем colorBrush_Btn.Renderer.TextColor = Color.White; colorBrush_Btn.Renderer.TextColorHover = Color.Blue; colorBrush_Btn.PositionLayout = new Layout2d("0%", positionOffset + "%"); //производим смещение colorBrush_Btn.Toggled += (e, a) => { if (colorBrush_Btn.Checked) { BrushManager.instance().changeCurrentColor(colorKey); } }; //привязываем к кнопке метод изменяющий текущий цвет у менеджера кистей BrushesPanel.Add(colorBrush_Btn); //добавляем кнопку на панель } BrushesPanel.Add(brushes); //список слоев ListBox LayerList = new ListBox(); LayerList.Renderer.TextColor = Color.White; layers = new Dictionary <string, Image>(); Layer[] tempLayerList = SceneManager.instance().currentScene.getLayers(); foreach (var lay in tempLayerList) { //добавляем слои в словарь. При выборе значения в списке - значение будет передано словарю в качестве ключа и будет получение изображение, которое будет передано менеджеру кисти //таким образом рисование будет происходить на выбранном пользователем слое layers.Add(lay.name, lay.picture.image); LayerList.AddItem(lay.name, lay.name); } LayerList.ItemSelected += (e, a) => { BrushManager.instance().changeCurrentImage(layers[LayerList.GetSelectedItemId()]); }; LayerList.Renderer.BackgroundColor = Color.Transparent; LayerPanel = new Panel(); LayerPanel.Renderer.BackgroundColor = Color.Black; LayerPanel.Renderer.BorderColor = Color.White; LayerPanel.PositionLayout = new Layout2d("0%", "30%"); LayerPanel.SizeLayout = new Layout2d("100%", "30%"); LayerPanel.Renderer.Borders = new Outline(0, 5, 0, 0); LayerPanel.Add(LayerList); MainPanel.Add(LayerPanel); //Данные производительности performancePanel = new Panel(); performancePanel.Renderer.BackgroundColor = Color.Black; performancePanel.Renderer.BorderColor = Color.White; performancePanel.Renderer.Borders = new Outline(0, 5, 0, 5); performancePanel.PositionLayout = new Layout2d("0%", "50%"); performancePanel.SizeLayout = new Layout2d("100%", "10%"); frameDelay = new TextBox(); frameDelay.Renderer.BackgroundColor = Color.Transparent; frameDelay.Renderer.TextColor = Color.White; performancePanel.Add(frameDelay); MainPanel.Add(performancePanel); //Контроль симуляций (включение/выключение) objectsControlPanel = new ScrollablePanel(); objectsControlPanel.ScrollbarWidth = 8; GameObject[] Scene_objects = SceneManager.instance().GetGameObjects(); positionOffset = 0; foreach (var obj in Scene_objects) { CheckBox gameObjectSwitcher = new CheckBox(); gameObjectSwitcher.Checked = true; gameObjectSwitcher.Text = obj.name; gameObjectSwitcher.Toggled += (e, a) => { obj.toggleActive(); }; gameObjectSwitcher.PositionLayout = new Layout2d("0%", positionOffset + "%"); gameObjectSwitcher.Renderer.TextColor = Color.White; gameObjectSwitcher.Renderer.TextColorHover = Color.Green; gameObjectSwitcher.Renderer.Font = font; positionOffset += 13; objectsControlPanel.Add(gameObjectSwitcher); } objectsControlPanel.Renderer.BackgroundColor = Color.Black; objectsControlPanel.Renderer.BorderColor = Color.White; objectsControlPanel.Renderer.Borders = new Outline(0, 5, 0, 5); objectsControlPanel.PositionLayout = new Layout2d("0%", "60%"); objectsControlPanel.SizeLayout = new Layout2d("100%", "30%"); MainPanel.Add(objectsControlPanel); }