private void ComposeDialog() { int height = 200; int tableWidth = 150; int textAreaWidth = 200; int headerHeight = 20; int labelWidth = 60; var spacer = ElementStdBounds .TitleBar(); var tableBounds = Fixed(0, 0, tableWidth, height); var labelBounds = Fixed(0, 0, labelWidth, headerHeight); var nameInputBounds = Fixed(labelWidth, 0, textAreaWidth - labelWidth, headerHeight); var headerBounds = Fixed(0, 0, textAreaWidth, headerHeight) .WithChildren(labelBounds, nameInputBounds); var textAreaBounds = Fixed(0, 0, textAreaWidth, height) .FixedUnder(headerBounds, HalfPadding); var textContainerBounds = Fill .WithSizing(ElementSizing.FitToChildren) .FixedRightOf(tableBounds, HalfPadding) .WithChildren(textAreaBounds, headerBounds); var bodyBounds = Fill .WithSizing(ElementSizing.FitToChildren) .FixedUnder(spacer) .WithChildren(textContainerBounds, tableBounds); var bgBounds = Fill .WithFixedPadding(ElementToDialogPadding) .WithChildren(bodyBounds) .WithSizing(ElementSizing.FitToChildren); var dialogBounds = ElementStdBounds .AutosizedMainDialog .WithAlignment(EnumDialogArea.CenterMiddle); SingleComposer = capi.Gui.CreateCompo("aliaseditor", dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar("Alias Editor", () => TryClose()) .AddStaticText("Alias:", CairoFont.WhiteSmallishText(), labelBounds) .AddTextInput(nameInputBounds, OnAliasNameChanged, CairoFont.TextInput(), "aliastextinput") .AddTextArea(textAreaBounds, OnAliasTextChanged, CairoFont.TextInput(), "aliastextarea") .AddCellList(tableBounds, (cell, elBounds) => new GuiElementCell(capi, cell, elBounds) { ShowModifyIcons = false }, OnMouseDownOnCell, OnMouseDownOnCell, cellList, "aliascellarea") .Compose(); textArea = SingleComposer.GetTextArea("aliastextarea"); textArea.Enabled = false; textInput = SingleComposer.GetTextInput("aliastextinput"); }
public GuiDialogBlockEntityTextInput(string DialogTitle, BlockPos blockEntityPos, string text, ICoreClientAPI capi, int maxwidth = 130, int maxLines = 4) : base(DialogTitle, capi) { this.blockEntityPos = blockEntityPos; ElementBounds textAreaBounds = ElementBounds.Fixed(0, 0, 300, 150); textareaFixedY = textAreaBounds.fixedY; // Clipping bounds for textarea ElementBounds clippingBounds = textAreaBounds.ForkBoundingParent().WithFixedPosition(0, 30); ElementBounds scrollbarBounds = clippingBounds.CopyOffsetedSibling(textAreaBounds.fixedWidth + 3).WithFixedWidth(20); ElementBounds cancelButtonBounds = ElementBounds.FixedSize(0, 0).FixedUnder(clippingBounds, 2 * 5).WithAlignment(EnumDialogArea.LeftFixed).WithFixedPadding(10, 2); ElementBounds saveButtonBounds = ElementBounds.FixedSize(0, 0).FixedUnder(clippingBounds, 2 * 5).WithAlignment(EnumDialogArea.RightFixed).WithFixedPadding(10, 2); // 2. Around all that is 10 pixel padding ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; bgBounds.WithChildren(clippingBounds, scrollbarBounds, cancelButtonBounds, saveButtonBounds); //textAreaBounds, // 3. Finally Dialog ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.RightMiddle) .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0); SingleComposer = capi.Gui .CreateCompo("blockentitytexteditordialog", dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar(DialogTitle, OnTitleBarClose) .BeginChildElements(bgBounds) .BeginClip(clippingBounds) .AddTextArea(textAreaBounds, OnTextAreaChanged, CairoFont.TextInput().WithFontSize(20), "text") .EndClip() .AddVerticalScrollbar(OnNewScrollbarvalue, scrollbarBounds, "scrollbar") .AddSmallButton(Lang.Get("Cancel"), OnButtonCancel, cancelButtonBounds) .AddSmallButton(Lang.Get("Save"), OnButtonSave, saveButtonBounds) .EndChildElements() .Compose() ; SingleComposer.GetTextArea("text").SetMaxLines(maxLines); SingleComposer.GetTextArea("text").SetMaxWidth((int)(maxwidth * RuntimeEnv.GUIScale)); SingleComposer.GetScrollbar("scrollbar").SetHeights( (float)textAreaBounds.fixedHeight, (float)textAreaBounds.fixedHeight ); if (text.Length > 0) { SingleComposer.GetTextArea("text").SetValue(text); } }
private void ComposeDialog() { ElementBounds leftColumn = ElementBounds.Fixed(0, 28, 120, 25); ElementBounds rightColumn = leftColumn.RightCopy(); ElementBounds buttonRow = ElementBounds.Fixed(0, 28, 360, 25); ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; bgBounds.WithChildren(leftColumn, rightColumn); ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog .WithAlignment(EnumDialogArea.CenterMiddle) .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0); if (SingleComposer != null) { SingleComposer.Dispose(); } string[] names = new string[] { "circle", "bee", "cave", "home", "ladder", "pick", "rocks", "ruins", "spiral", "star1", "star2", "trader", "vessel" }; int index = names.IndexOf(waypoint.Icon); if (index < 0) { index = 0; } SingleComposer = capi.Gui .CreateCompo("worldmap-modwp", dialogBounds) .AddShadedDialogBG(bgBounds, false) .AddDialogTitleBar("Modify waypoint", () => TryClose()) .BeginChildElements(bgBounds) .AddRichtext("Color (<a href=\"https://www.99colors.net/dot-net-colors\">List</a>)", CairoFont.WhiteSmallText(), leftColumn = leftColumn.FlatCopy()) .AddTextInput(rightColumn = rightColumn.FlatCopy().WithFixedWidth(150), onColorChanged, CairoFont.TextInput(), "colorInput") .AddDynamicCustomDraw(rightColumn.FlatCopy().WithFixedWidth(30).WithFixedOffset(160, 0), onDrawColorRect, "colorRect") .AddStaticText("Name", CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 5)) .AddTextInput(rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(200), onNameChanged, CairoFont.TextInput(), "nameInput") .AddStaticText("Icon", CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 5)) .AddDropDown( names, new string[] { "<icon name=\"wpCircle\">", "<icon name=\"wpBee\">", "<icon name=\"wpCave\">", "<icon name=\"wpHome\">", "<icon name=\"wpLadder\">", "<icon name=\"wpPick\">", "<icon name=\"wpRocks\">", "<icon name=\"wpRuins\">", "<icon name=\"wpSpiral\">", "<icon name=\"wpStar1\">", "<icon name=\"wpStar2\">", "<icon name=\"wpTrader\">", "<icon name=\"wpVessel\">" }, index, onIconSelectionChanged, rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(60), CairoFont.WhiteSmallishText(), "iconInput" ) .AddSmallButton("Cancel", onCancel, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100), EnumButtonStyle.Normal) .AddSmallButton("Delete", onDelete, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.CenterFixed), EnumButtonStyle.Normal) .AddSmallButton("Save", onSave, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.RightFixed), EnumButtonStyle.Normal, key: "saveButton") .EndChildElements() .Compose() ; var col = System.Drawing.Color.FromArgb(0, ColorUtil.ColorR(waypoint.Color), ColorUtil.ColorG(waypoint.Color), ColorUtil.ColorB(waypoint.Color)); if (col.IsKnownColor) { SingleComposer.GetTextInput("colorInput").SetValue(col.ToKnownColor().ToString().ToLowerInvariant()); } else { SingleComposer.GetTextInput("colorInput").SetValue(ColorUtil.Int2Hex(waypoint.Color)); } SingleComposer.GetTextInput("nameInput").SetValue(waypoint.Title); }
private void ComposeDialog() { ElementBounds leftColumn = ElementBounds.Fixed(0, 28, 120, 25); ElementBounds rightColumn = leftColumn.RightCopy(); ElementBounds buttonRow = ElementBounds.Fixed(0, 28, 360, 25); ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; bgBounds.WithChildren(leftColumn, rightColumn); ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog .WithAlignment(EnumDialogArea.CenterMiddle) .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0); if (SingleComposer != null) { SingleComposer.Dispose(); } SingleComposer = capi.Gui .CreateCompo("worldmap-addwp", dialogBounds) .AddShadedDialogBG(bgBounds, false) .AddDialogTitleBar(Lang.Get("Add waypoint"), () => TryClose()) .BeginChildElements(bgBounds) .AddStaticText(Lang.Get("Name"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.FlatCopy()) .AddTextInput(rightColumn = rightColumn.FlatCopy().WithFixedWidth(200), onNameChanged, CairoFont.TextInput(), "nameInput") .AddRichtext(Lang.Get("waypoint-color"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 5)) .AddTextInput(rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(150), onColorChanged, CairoFont.TextInput(), "colorInput") .AddDynamicCustomDraw(rightColumn.FlatCopy().WithFixedWidth(30).WithFixedOffset(160, 0), onDrawColorRect, "colorRect") .AddStaticText(Lang.Get("Icon"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 9)) .AddDropDown( new string[] { "circle", "bee", "cave", "home", "ladder", "pick", "rocks", "ruins", "spiral", "star1", "star2", "trader", "vessel" }, new string[] { "<icon name=\"wpCircle\">", "<icon name=\"wpBee\">", "<icon name=\"wpCave\">", "<icon name=\"wpHome\">", "<icon name=\"wpLadder\">", "<icon name=\"wpPick\">", "<icon name=\"wpRocks\">", "<icon name=\"wpRuins\">", "<icon name=\"wpSpiral\">", "<icon name=\"wpStar1\">", "<icon name=\"wpStar2\">", "<icon name=\"wpTrader\">", "<icon name=\"wpVessel\">" }, 0, onIconSelectionChanged, rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(60), CairoFont.WhiteSmallishText(), "iconInput" ) .AddStaticText(Lang.Get("Pinned"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 9)) .AddSwitch(onPinnedToggled, rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(200), "pinnedSwitch") .AddSmallButton(Lang.Get("Cancel"), onCancel, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100), EnumButtonStyle.Normal) .AddSmallButton(Lang.Get("Save"), onSave, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.RightFixed), EnumButtonStyle.Normal, key: "saveButton") .EndChildElements() .Compose() ; SingleComposer.GetButton("saveButton").Enabled = false; }
public GuiDialogBlockEntityCommand(BlockPos BlockEntityPosition, string command, ICoreClientAPI capi) : base("Command block", BlockEntityPosition, capi) { double pad = GuiElementItemSlotGrid.unscaledSlotPadding; int spacing = 5; double size = GuiElementPassiveItemSlot.unscaledSlotSize + GuiElementItemSlotGrid.unscaledSlotPadding; double innerWidth = 300; // 1.2. Name and Hotkey double halfWidth = innerWidth / 2 - 5; // 1.3. Commands text ElementBounds commmandsBounds = ElementBounds.Fixed(0, 30, innerWidth, 30); // 1.3. Command textarea ElementBounds textAreaBounds = ElementBounds.Fixed(0, 0, innerWidth - 20, 200); // 1.3.2. Clipping bounds for textarea ElementBounds clippingBounds = ElementBounds.Fixed(0, 0, innerWidth - 20 - 1, 200 - 1).FixedUnder(commmandsBounds, spacing - 10); // 1.3.3 Scrollbar right of textarea ElementBounds scrollbarBounds = clippingBounds.CopyOffsetedSibling(clippingBounds.fixedWidth + 6, -1).WithFixedWidth(20).FixedGrow(0, 2); // 1.4. Clear Macro button ElementBounds cancelBounds = ElementBounds.FixedSize(0, 0).FixedUnder(clippingBounds, 6 + 2 * spacing).WithAlignment(EnumDialogArea.LeftFixed).WithFixedPadding(10, 2); ElementBounds saveBounds = ElementBounds.FixedSize(0, 0).FixedUnder(clippingBounds, 6 + 2 * spacing).WithAlignment(EnumDialogArea.RightFixed).WithFixedPadding(10, 2); // 2. Around all that is 10 pixel padding ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; // 3. Finally Dialog ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.RightMiddle) .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0); if (SingleComposer != null) { SingleComposer.Dispose(); } SingleComposer = capi.Gui .CreateCompo("commandeditordialog", dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar("Command Editor", OnTitleBarClose) .BeginChildElements(bgBounds) .AddStaticText("Commands", CairoFont.WhiteSmallText(), commmandsBounds) .BeginClip(clippingBounds) .AddTextArea(textAreaBounds, OnCommandCodeChanged, CairoFont.TextInput().WithFontSize(16), "commands") .EndClip() .AddVerticalScrollbar(OnNewCmdScrollbarvalue, scrollbarBounds, "scrollbar") .AddSmallButton("Cancel", OnCancel, cancelBounds) .AddSmallButton("Save", OnSave, saveBounds) .EndChildElements() .Compose() ; SingleComposer.GetTextArea("commands").SetValue(command); SingleComposer.GetTextArea("commands").OnCursorMoved = OnTextAreaCursorMoved; SingleComposer.GetScrollbar("scrollbar").SetHeights( (float)textAreaBounds.fixedHeight - 1, (float)textAreaBounds.fixedHeight ); SingleComposer.UnfocusOwnElements(); }