/// <summary> /// 设置属性 /// </summary> protected override void SetAttributes() { RadioBox control = this.ControlHost.Content as RadioBox; if (!string.IsNullOrEmpty(control.ToolTip) && this.ProjectDocument != null) { this.HtmlWriter.AddAttribute("tooltip-name", this.ProjectDocument.Name + "_" + control.ToolTip); } base.SetAttributes(); }
internal void AddRadioBox(MenuNames menuname, bool oneMustStayAktive, RadioBox Box1, RadioBox Box2) { var checkbox1 = MenuDictionary[menuname.ToString()].Add(Box1.Identifier, new CheckBox(Box1.Name, Box1.DefaultValue)); var checkbox2 = MenuDictionary[menuname.ToString()].Add(Box2.Identifier, new CheckBox(Box2.Name, Box2.DefaultValue)); RandioboxDictionary.Add(Box1.Name, checkbox2); RandioboxDictionary.Add(Box2.Name, checkbox1); if (oneMustStayAktive) { checkbox1.OnValueChange += CheckBoxChanged_OneStayActive; checkbox2.OnValueChange += CheckBoxChanged_OneStayActive; } else { checkbox1.OnValueChange += CheckBoxChanged_JustDisable; checkbox2.OnValueChange += CheckBoxChanged_JustDisable; } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (service != null) { using (FormStringCollection form = new FormStringCollection((ICollection)value)) { if (service.ShowDialog(form) == DialogResult.OK) { RadioBox box = (RadioBox)context.Instance; value = new RadioBoxCollection(box, form.Collection); } } } } return(value); }
/// <summary> /// 设置子元素 /// </summary> protected override void SetChildElements() { RadioBox control = this.ControlHost.Content as RadioBox; this.HtmlWriter.AddAttribute("dojoType", "Controls/RadioButton"); if (!IsPreview && !string.IsNullOrEmpty(this.ControlHost.Name)) { this.HtmlWriter.AddAttribute("id", this.ControlHost.Name); this.HtmlWriter.AddAttribute("name", this.ControlHost.Name); } StringBuilder sbProps = new StringBuilder(); StringBuilder returnContent = new StringBuilder(); string props = control.BuildControlProps(this.ScreenDefinition, this.IsPreview, this.PermissionData, returnContent); if (!string.IsNullOrEmpty(props)) { sbProps.AppendFormat("{0},", props); } if (sbProps.ToString().Length > 0) { this.HtmlWriter.AddAttribute("data-dojo-props", sbProps.ToString().Substring(0, sbProps.ToString().Length - 1), false); } if (control.ExistProperty("IsReadOnly") && control.IsReadOnly) { this.HtmlWriter.AddAttribute("readonly", "readonly"); } if (control.ExistProperty("IsEnable") && !control.IsEnable) { this.HtmlWriter.AddAttribute("disabled", "disabled"); } this.HtmlWriter.AddAttribute("style", "width:16px !important;height:16px !important;"); this.HtmlWriter.RenderBeginTag("input"); this.HtmlWriter.RenderEndTag(); this.HtmlWriter.RenderBeginTag("span"); this.HtmlWriter.WriteEncodedText(control.Text == null ? "" : control.Text); this.HtmlWriter.RenderEndTag(); }
public void ParseWidgets(IContainer ParentWidget, Dictionary <string, object> Data) { foreach (string name in Data.Keys) { if (!(Data[name] is JObject)) { throw new Exception($"Expected an Object, but got {Data[name].GetType().Name} in key '{name}' inside 'widgets'"); } Dictionary <string, object> config = ((JObject)Data[name]).ToObject <Dictionary <string, object> >(); if (!config.ContainsKey("type")) { throw new Exception($"Widget definition must contain a 'type' key in widget '{name}'"); } if (!(config["type"] is string)) { throw new Exception($"Widget type must be a string."); } Widget w = null; string type = (string)config["type"]; switch (type) { case "container": w = new Container(ParentWidget); break; case "label": w = new DynamicLabel(ParentWidget); break; case "numeric": w = new NumericBox(ParentWidget); break; case "textbox": w = new TextBox(ParentWidget); break; case "button": w = new Button(ParentWidget); break; case "dropdown": w = new DropdownBox(ParentWidget); break; case "checkbox": w = new CheckBox(ParentWidget); break; case "radiobox": w = new RadioBox(ParentWidget); break; case "switch_picker": w = new GameSwitchBox(ParentWidget); break; case "variable_picker": w = new GameVariableBox(ParentWidget); break; case "multitextbox": w = new MultilineTextBox(ParentWidget); break; case "multilabel": w = new MultilineDynamicLabel(ParentWidget); break; default: throw new Exception($"Unknown widget type '{type}' in widget '{name}'"); } if (WidgetLookup.ContainsKey(name)) { throw new Exception($"Two or more widgets with the same were found: '{name}'"); } WidgetLookup.Add(name, w); int X = 0; int Y = 0; int Width = -1; int Height = -1; string text = null; int wvalue = 0; int? min_value = null; int? max_value = null; Font font = null; List <ListItem> items = null; int idx = -1; bool enabled = true; List <ClickAction> clickactions = new List <ClickAction>(); foreach (string key in config.Keys) { if (key == "type") { continue; } object value = config[key]; switch (key) { case "x": EnsureType(typeof(long), value, "x"); X = Convert.ToInt32(value); break; case "y": EnsureType(typeof(long), value, "y"); Y = Convert.ToInt32(value); break; case "width": EnsureType(typeof(long), value, "width"); Width = Convert.ToInt32(value); if (Width < 1) { throw new Exception($"Widget width ({Width}) must be greater than 0."); } break; case "height": EnsureType(typeof(long), value, "height"); Height = Convert.ToInt32(value); if (Height < 1) { throw new Exception($"Widget height ({Height}) must be greater than 0."); } break; case "font": if (type != "label" && type != "textbox" && type != "button" && type != "dropdown" && type != "checkbox" && type != "radiobox" && type != "multitextbox" && type != "multilabel") { throw new Exception($"Widget type ({type}) can not contain a 'font' field."); } if (value is string) { if (!Fonts.ContainsKey((string)value)) { throw new Exception($"Undefined font name '{(string) value}"); } font = Fonts[(string)value]; } else if (value is JObject) { font = ParseFont(((JObject)value).ToObject <Dictionary <string, object> >()); } else { throw new Exception($"Expected a String or Object, but got {value.GetType().Name} in 'font'"); } break; case "value": if (type != "numeric") { throw new Exception($"Widget type ({type}) can not contain a 'value' field."); } EnsureType(typeof(long), value, "value"); wvalue = Convert.ToInt32(value); break; case "min_value": if (type != "numeric") { throw new Exception($"Widget type ({type}) can not contain a 'min_value' field."); } EnsureType(typeof(long), value, "min_value"); min_value = Convert.ToInt32(value); break; case "max_value": if (type != "numeric") { throw new Exception($"Widget type ({type}) can not contain a 'max_value' field."); } EnsureType(typeof(long), value, "max_value"); max_value = Convert.ToInt32(value); break; case "text": if (type != "label" && type != "textbox" && type != "button" && type != "checkbox" && type != "radiobox" && type != "multitextbox" && type != "multilabel") { throw new Exception($"Widget type ({type}) can not contain a 'text' field."); } EnsureType(typeof(string), value, "text"); text = (string)value; break; case "items": if (type != "dropdown") { throw new Exception($"Widget type ({type}) can not contain an 'items' field."); } if (!(value is JArray)) { throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'items'"); } List <object> ary = ((JArray)value).ToObject <List <object> >(); items = new List <ListItem>(); foreach (object o in ary) { EnsureType(typeof(string), o, "items"); items.Add(new ListItem((string)o)); } break; case "index": if (type != "dropdown") { throw new Exception($"Widget type ({type}) can not contain an 'index' field."); } EnsureType(typeof(long), value, "index"); idx = Convert.ToInt32(value); if (idx < 0) { throw new Exception($"Index field must be greater than or equal to 0."); } break; case "enabled": if (type != "label" && type != "dropdown" && type != "switch_picker" && type != "variable_picker" && type != "checkbox" && type != "radiobox" && type != "textbox" && type != "numeric" && type != "button" && type != "multilabel") { throw new Exception($"Widget type ({type}) can not contain an 'enabled' field."); } EnsureType(typeof(bool), value, "enabled"); enabled = Convert.ToBoolean(value); break; case "widgets": if (!(value is JObject)) { throw new Exception($"Expected an Object, but got a {value.GetType().Name} in key 'widgets'"); } ParseWidgets(w, ((JObject)value).ToObject <Dictionary <string, object> >()); break; case "clicked": if (type != "radiobox" && type != "dropdown") { throw new Exception($"Widget type ({type}) can not contain a 'clicked' field."); } if (!(value is JArray)) { throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'clicked'"); } List <object> clickdata = ((JArray)value).ToObject <List <object> >(); for (int i = 0; i < clickdata.Count; i++) { object action = clickdata[i]; if (!(action is JObject)) { throw new Exception($"Expected an Object, but got {action.GetType().Name} in key 'clicked', element {i}"); } Dictionary <string, object> actionobject = ((JObject)action).ToObject <Dictionary <string, object> >(); if (!actionobject.ContainsKey("action")) { throw new Exception($"Click definition in 'clicked', element {i} must contain an 'action' key."); } string actiontype = null; List <object> actionparams = new List <object>(); string actioncondition = null; foreach (string actionkey in actionobject.Keys) { object actionvalue = actionobject[actionkey]; switch (actionkey) { case "action": EnsureType(typeof(string), actionvalue, "action"); actiontype = (string)actionvalue; if (actiontype != "enable" && actiontype != "disable" && actiontype != "check" && actiontype != "uncheck" && actiontype != "set") { throw new Exception($"Unknown action type '{actiontype}'."); } break; case "parameter": if (!(actionvalue is string) && !(actionvalue is JArray)) { throw new Exception($"Expected a string or Array, but got {actionvalue.GetType().Name} in key 'parameter'."); } if (actionvalue is string) { actionparams.Add((string)actionvalue); } else { List <object> paramlist = ((JArray)actionvalue).ToObject <List <object> >(); foreach (object paramvalue in paramlist) { actionparams.Add(paramvalue); } } break; case "condition": EnsureType(typeof(string), actionvalue, "condition"); actioncondition = (string)actionvalue; break; default: throw new Exception($"Unknown key '{actionkey}' inside 'clicked' definition"); } } clickactions.Add(new ClickAction(actiontype, actionparams, actioncondition)); } break; default: throw new Exception($"Unknown key '{key}' inside widget definition"); } } EnabledLookup.Add(name, enabled); w.SetPosition(X, Y); if (Width != -1 && Height != -1) { w.SetSize(Width, Height); } else if (Width != -1) { w.SetWidth(Width); } else if (Height != -1) { w.SetHeight(Height); } if (type == "label") { if (!string.IsNullOrEmpty(text)) { ((DynamicLabel)w).SetText(text); } if (font != null) { ((DynamicLabel)w).SetFont(font); } //((DynamicLabel) w).SetParser(this); ((DynamicLabel)w).SetColors(ConditionParser.Colors); ((DynamicLabel)w).SetEnabled(enabled); } if (type == "multilabel") { if (!string.IsNullOrEmpty(text)) { ((MultilineDynamicLabel)w).SetText(text); } if (font != null) { ((MultilineDynamicLabel)w).SetFont(font); } //((MultilineDynamicLabel) w).SetParser(this); ((MultilineDynamicLabel)w).SetColors(ConditionParser.Colors); ((MultilineDynamicLabel)w).SetEnabled(enabled); } if (type == "textbox") { if (!string.IsNullOrEmpty(text)) { ((TextBox)w).SetInitialText(text); } if (font != null) { ((TextBox)w).TextArea.SetFont(font); } ((TextBox)w).OnTextChanged += Save; } if (type == "numeric") { ((NumericBox)w).SetValue(wvalue); if (min_value != null) { ((NumericBox)w).MinValue = (int)min_value; } if (max_value != null) { ((NumericBox)w).MaxValue = (int)max_value; } ((NumericBox)w).OnValueChanged += Save; } if (type == "button") { if (!string.IsNullOrEmpty(text)) { ((Button)w).SetText(text); } if (font != null) { ((Button)w).SetFont(font); } } if (type == "dropdown") { if (items == null && idx != -1 || items != null && idx >= items.Count) { throw new Exception($"Index cannot be greater than or equal to the total item size."); } if (items != null) { ((DropdownBox)w).SetItems(items); } if (idx != -1) { ((DropdownBox)w).SetSelectedIndex(idx); } if (font != null) { ((DropdownBox)w).SetFont(font); } ((DropdownBox)w).OnSelectionChanged += Save; ((DropdownBox)w).OnSelectionChanged += delegate(BaseEventArgs e) { EvaluateAction(clickactions); }; } if (type == "checkbox") { if (font != null) { ((CheckBox)w).SetFont(font); } if (!string.IsNullOrEmpty(text)) { ((CheckBox)w).SetText(text); } } if (type == "radiobox") { if (font != null) { ((RadioBox)w).SetFont(font); } if (!string.IsNullOrEmpty(text)) { ((RadioBox)w).SetText(text); } ((RadioBox)w).OnCheckChanged += delegate(BaseEventArgs e) { if (((RadioBox)w).Checked) { EvaluateAction(clickactions); } }; } if (type == "switch_picker") { ((GameSwitchBox)w).OnSwitchChanged += Save; } if (type == "variable_picker") { ((GameVariableBox)w).OnVariableChanged += Save; } if (type == "multitextbox") { if (font != null) { ((MultilineTextBox)w).SetFont(font); } if (!string.IsNullOrEmpty(text)) { ((MultilineTextBox)w).SetText(text); } } SetWidgetEnabled(w, enabled); } }
public static void Main(params string[] Args) { Graphics.Start(); Audio.Start(); //BorderlessWindow Window = new BorderlessWindow(); //Window.Show(); UIWindow Window = new UIWindow(); Window.SetBackgroundColor(SystemColors.WindowBackground); GroupBox GroupBox1 = new GroupBox(Window.UI.Container); GroupBox1.SetPosition(64, 64); GroupBox1.SetSize(400, 400); Label Label1 = new Label(GroupBox1); Label1.SetPosition(16, 21); Label1.SetText("Hello world! This is a standard Windows UI label."); Button Button1 = new Button(GroupBox1); Button1.SetPosition(16, 36); Button1.SetText("Start task"); Button1.OnPressed += delegate(BaseEventArgs e) { Console.WriteLine($"Clicked button 1!"); Audio.BGMPlay("D:/Dropbox/Pokemon Jam/Audio/BGM/Battle trainer.ogg", 50, 4); }; Button Button2 = new Button(GroupBox1); Button2.SetPosition(16, Button1.Position.Y + Button1.Size.Height + 4); Button2.SetText("End task"); Button2.OnPressed += delegate(BaseEventArgs e) { Console.WriteLine("Clicked button 2!"); }; CheckBox CheckBox1 = new CheckBox(GroupBox1); CheckBox1.SetPosition(16, Button2.Position.Y + Button2.Size.Height + 4); CheckBox1.OnCheckChanged += delegate(BaseEventArgs e) { Console.WriteLine("Clicked checkbox 1!"); }; TabView TabView1 = new TabView(GroupBox1); TabView1.SetPosition(130, 46); TabView1.SetSize(200, 200); TabView1.CreateTab("Autotiles"); TabView1.CreateTab("Tilesets"); TabView1.OnTabChanged += delegate(BaseEventArgs e) { Console.WriteLine("Changed tab!"); }; ListBox ListBox1 = new ListBox(GroupBox1); ListBox1.SetPosition(15, CheckBox1.Position.Y + CheckBox1.Size.Height + 10); ListBox1.SetSize(100, 200); ListBox1.SetItems(new List <ListItem>() { new ListItem("Alpha"), new ListItem("Beta"), new ListItem("Gamma"), new ListItem("Delta"), new ListItem("Epsilon"), new ListItem("Zeta"), new ListItem("Etha"), new ListItem("Iota"), new ListItem("Kappa"), new ListItem("Labda"), new ListItem("Mu"), new ListItem("Nu"), new ListItem("Xi"), new ListItem("Omicron"), new ListItem("Pi"), new ListItem("Rho"), new ListItem("Sigma"), new ListItem("Tau"), new ListItem("Upsilon"), new ListItem("Phi"), new ListItem("Chi"), new ListItem("Psi"), new ListItem("Omega") }); ListBox1.OnSelectionChanged += delegate(BaseEventArgs e) { Console.WriteLine($"Selection: {ListBox1.SelectedIndex}"); }; RadioBox RadioBox1 = new RadioBox(GroupBox1); RadioBox1.SetPosition(ListBox1.Position.X, ListBox1.Position.Y + ListBox1.Size.Height + 10); RadioBox1.SetText("Is shiny?"); RadioBox1.OnCheckChanged += delegate(BaseEventArgs e) { if (RadioBox1.Checked) { System.Console.WriteLine("Checked RadioBox 1"); } }; RadioBox RadioBox2 = new RadioBox(GroupBox1); RadioBox2.SetPosition(RadioBox1.Position.X, RadioBox1.Position.Y + RadioBox1.Size.Height + 4); RadioBox2.SetText("Is modifiable?"); RadioBox2.OnCheckChanged += delegate(BaseEventArgs e) { if (RadioBox2.Checked) { System.Console.WriteLine("Checked RadioBox 2"); } }; Window.Show(); while (Graphics.CanUpdate()) { Graphics.Update(); } Graphics.Stop(); }
public override IView ConvertTo(FigmaNode currentNode, ProcessedNode parent, FigmaRendererService rendererService) { var figmaInstance = (FigmaInstance)currentNode; var button = new RadioBox() { Text = "" }; var view = (NSButton)button.NativeObject; //view.BezelStyle = NSBezelStyle.Rounded; var controlType = figmaInstance.ToControlType(); switch (controlType) { case NativeControlType.ButtonLarge: case NativeControlType.ButtonLargeDark: view.ControlSize = NSControlSize.Regular; break; case NativeControlType.ButtonStandard: case NativeControlType.ButtonStandardDark: view.ControlSize = NSControlSize.Regular; break; case NativeControlType.ButtonSmall: case NativeControlType.ButtonSmallDark: view.ControlSize = NSControlSize.Small; break; } var label = figmaInstance.children .OfType <FigmaText>() .FirstOrDefault(); if (label != null) { button.Text = label.characters; view.Font = label.style.ToNSFont(); } //first figma var group = figmaInstance.children .OfType <FigmaGroup>() .FirstOrDefault(); if (group != null) { if (group.name == "Disabled") { button.Enabled = false; } } if (controlType.ToString().EndsWith("Dark", StringComparison.Ordinal)) { view.Appearance = NSAppearance.GetAppearance(NSAppearance.NameDarkAqua); } return(new View(view)); }
public virtual void UpdatePositions() { RxPositions = RadioBox.CreateRxPositions(); }