public XamarinLayoutManager(AbsoluteLayout container, LayoutPreset preset) : base(preset) { Container = container; Container.SizeChanged += (sender, e) => { if (!InLayout) { System.Threading.ThreadPool.QueueUserWorkItem((state) => { Device.BeginInvokeOnMainThread(Layout); }, null); } }; Container.LayoutChanged += (object sender, EventArgs e) => { if (!InLayout) { System.Threading.ThreadPool.QueueUserWorkItem((state) => { Device.BeginInvokeOnMainThread(Layout); }, null); } }; }
/// <summary> /// Sets an anchor AND a margin preset. This is most likely the method you want. /// /// </summary> /// <remarks> /// Note that the current size and minimum size of the control affects how /// each of the margins will be set, so if your control needs to shrink beyond its /// current size / min size, you should either not call this method or only call it when your /// control has a size of (0, 0). Otherwise your control's size will never be able /// to go below the size implied by the margins set in this method. /// </remarks> public static void SetAnchorAndMarginPreset(Control control, LayoutPreset preset, LayoutPresetMode mode = LayoutPresetMode.MinSize, int margin = 0) { SetAnchorPreset(control, preset); SetMarginsPreset(control, preset, mode, margin); }
public FormsLayoutManager(AbsoluteLayout container, LayoutPreset preset) : base(preset) { Container = container; Container.LayoutChanged += UpdateLayout; Container.SizeChanged += UpdateLayout; }
public static void DeleteLayoutPreset(LayoutPreset preset) { if (!preset.File.ExistsNow()) { return; } preset.File.Delete(); }
public FormsLayoutManager(AbsoluteLayout container, LayoutPreset preset) : base(preset) { Container = container; Container.LayoutChanged += UpdateLayout; Container.SizeChanged += UpdateLayout; }
private void LoadPreset(LayoutPreset preset) { if (!preset.Load()) { Dialog_Alert.Open(Lang.Get("Dialog_Config.Tab.Content.Preset.Invalid", preset.Name)); return; } Dialog_Alert.Open(Lang.Get("Dialog_Config.Tab.Content.Preset.Loaded", preset.Name)); RefreshEditor(); }
private void Save() { var xe = new XElement(LayoutPreset.RootElementName); xe.Add(new XAttribute(LayoutPreset.VersionAttributeName, Mod.Version)); if (_includeDocked) { xe.Add(HudLayout.Docked.ToXml(HudLayout.DockedElementName, _includeHeight ? Theme.InspectPaneHeight.Value : -1, _includeWidth ? Theme.InspectPaneTabWidth.Value : -1, _includeTabs ? Theme.InspectPaneMinTabs.Value : -1)); } if (_includeFloating) { xe.Add(HudLayout.Floating.ToXml(HudLayout.FloatingElementName, _includeHeight ? Theme.HudHeight.Value : -1, _includeWidth ? Theme.HudWidth.Value : -1)); } Persistent.SaveLayoutPreset(_name, xe); LayoutPreset.RefreshUserPresets(); Dialog_Alert.Open(Lang.Get("Alert.Saved", _name)); Close(); }
protected override void DrawContent(Rect rect) { var vGrid = rect.GetVGrid(GUIPlus.LargePadding, -1f, 70f); var l = new ListingPlus(); l.BeginScrollView(vGrid[1], ref _scrollPosition, ref _scrollView); foreach (var preset in LayoutPreset.UserList) { if (_selected == null) { _selected = preset; } if (l.RadioButton_NewTemp(preset.Label, _selected == preset)) { _selected = preset; } } l.EndScrollView(ref _scrollView); l.Begin(vGrid[2]); var buttonGrid = l.GetButtonGrid(-1f, -1f); if (GUIPlus.DrawButton(buttonGrid[1], Lang.Get("Dialog_Presets.Delete"), enabled: _selected?.IsUserMade ?? false)) { ConfirmDelete(); } if (GUIPlus.DrawButton(buttonGrid[2], Lang.Get("Button.Close"))) { Close(); } l.End(); }
/// <summary> /// Changes all the margins of a control at once to common presets. /// The result is that the control is laid out as specified by the preset. /// /// Note that the current size and minimum size of the control affects how /// each of the margins will be set, so if your control needs to shrink beyond its /// current size / min size, you should either not call this method or only call it when your /// control has a size of (0, 0). Otherwise your control's size will never be able /// to go below the size implied by the margins set in this method. /// </summary> /// <param name="preset"></param> /// <param name="resizeMode"></param> /// <param name="margin">Some extra margin to add depending on the preset chosen.</param> public static void SetMarginsPreset(Control control, LayoutPreset preset, LayoutPresetMode resizeMode = LayoutPresetMode.MinSize, int margin = 0) { control.Measure(Vector2.Infinity); var newSize = control.Size; var minSize = control.DesiredSize; if ((resizeMode & LayoutPresetMode.KeepWidth) == 0) { newSize = new Vector2(minSize.X, newSize.Y); } if ((resizeMode & LayoutPresetMode.KeepHeight) == 0) { newSize = new Vector2(newSize.X, minSize.Y); } var parentSize = control.Parent?.Size ?? Vector2.Zero; var anchorLeft = control.GetValue <float>(AnchorLeftProperty); var anchorTop = control.GetValue <float>(AnchorBottomProperty); var anchorRight = control.GetValue <float>(AnchorRightProperty); var anchorBottom = control.GetValue <float>(AnchorBottomProperty); float marginLeft; float marginTop; float marginRight; float marginBottom; // Left Margin. switch (preset) { case LayoutPreset.TopLeft: case LayoutPreset.BottomLeft: case LayoutPreset.CenterLeft: case LayoutPreset.LeftWide: case LayoutPreset.HorizontalCenterWide: case LayoutPreset.Wide: case LayoutPreset.TopWide: case LayoutPreset.BottomWide: // The AnchorLeft bit is to reverse the effect of anchors, // So that the preset result is the same no matter what margins are set. marginLeft = parentSize.X * (0 - anchorLeft) + margin; break; case LayoutPreset.CenterTop: case LayoutPreset.CenterBottom: case LayoutPreset.Center: case LayoutPreset.VerticalCenterWide: marginLeft = parentSize.X * (0.5f - anchorLeft) - newSize.X / 2; break; case LayoutPreset.TopRight: case LayoutPreset.BottomRight: case LayoutPreset.CenterRight: case LayoutPreset.RightWide: marginLeft = parentSize.X * (1 - anchorLeft) - newSize.X - margin; break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } // Top Anchor. switch (preset) { case LayoutPreset.TopLeft: case LayoutPreset.TopRight: case LayoutPreset.LeftWide: case LayoutPreset.TopWide: case LayoutPreset.Wide: case LayoutPreset.RightWide: case LayoutPreset.CenterTop: case LayoutPreset.VerticalCenterWide: marginTop = parentSize.Y * (0 - anchorTop) + margin; break; case LayoutPreset.CenterLeft: case LayoutPreset.CenterRight: case LayoutPreset.HorizontalCenterWide: case LayoutPreset.Center: marginTop = parentSize.Y * (0.5f - anchorTop) - newSize.Y / 2; break; case LayoutPreset.CenterBottom: case LayoutPreset.BottomLeft: case LayoutPreset.BottomRight: case LayoutPreset.BottomWide: marginTop = parentSize.Y * (1 - anchorTop) - newSize.Y - margin; break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } // Right Anchor. switch (preset) { case LayoutPreset.TopLeft: case LayoutPreset.CenterLeft: case LayoutPreset.BottomLeft: case LayoutPreset.LeftWide: marginRight = parentSize.X * (0 - anchorRight) + newSize.X + margin; break; case LayoutPreset.CenterTop: case LayoutPreset.CenterBottom: case LayoutPreset.Center: case LayoutPreset.VerticalCenterWide: marginRight = parentSize.X * (0.5f - anchorRight) + newSize.X; break; case LayoutPreset.CenterRight: case LayoutPreset.TopRight: case LayoutPreset.Wide: case LayoutPreset.HorizontalCenterWide: case LayoutPreset.TopWide: case LayoutPreset.BottomWide: case LayoutPreset.RightWide: case LayoutPreset.BottomRight: marginRight = parentSize.X * (1 - anchorRight) - margin; break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } // Bottom Anchor. switch (preset) { case LayoutPreset.TopWide: case LayoutPreset.TopLeft: case LayoutPreset.TopRight: case LayoutPreset.CenterTop: marginBottom = parentSize.Y * (0 - anchorBottom) + newSize.Y + margin; break; case LayoutPreset.CenterLeft: case LayoutPreset.CenterRight: case LayoutPreset.Center: case LayoutPreset.HorizontalCenterWide: marginBottom = parentSize.Y * (0.5f - anchorBottom) + newSize.Y; break; case LayoutPreset.CenterBottom: case LayoutPreset.BottomLeft: case LayoutPreset.BottomRight: case LayoutPreset.LeftWide: case LayoutPreset.Wide: case LayoutPreset.RightWide: case LayoutPreset.VerticalCenterWide: case LayoutPreset.BottomWide: marginBottom = parentSize.Y * (1 - anchorBottom) - margin; break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } control.SetValue(MarginLeftProperty, marginLeft); control.SetValue(MarginTopProperty, marginTop); control.SetValue(MarginRightProperty, marginRight); control.SetValue(MarginBottomProperty, marginBottom); }
/// <summary> /// Changes all the anchors of a node at once to common presets. /// The result is that the anchors are laid out to be suitable for a preset. /// </summary> /// <param name="preset"> /// The preset to apply to the anchors. /// </param> /// <param name="keepMargin"> /// If this is true, the control margin values themselves will not be changed, /// and the control position and size will change according to the new anchor parameters. /// If false, the control margins will adjust so that the control position and size remains the same relative to its parent. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown if <paramref name="preset" /> isn't a valid preset value. /// </exception> public static void SetAnchorPreset(Control control, LayoutPreset preset, bool keepMargin = false) { // TODO: Implement keepMargin. // Left Anchor. switch (preset) { case LayoutPreset.TopLeft: case LayoutPreset.BottomLeft: case LayoutPreset.CenterLeft: case LayoutPreset.LeftWide: case LayoutPreset.HorizontalCenterWide: case LayoutPreset.Wide: case LayoutPreset.TopWide: case LayoutPreset.BottomWide: control.SetValue(AnchorLeftProperty, 0f); break; case LayoutPreset.CenterTop: case LayoutPreset.CenterBottom: case LayoutPreset.Center: case LayoutPreset.VerticalCenterWide: control.SetValue(AnchorLeftProperty, 0.5f); break; case LayoutPreset.TopRight: case LayoutPreset.BottomRight: case LayoutPreset.CenterRight: case LayoutPreset.RightWide: control.SetValue(AnchorLeftProperty, 1f); break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } // Top Anchor. switch (preset) { case LayoutPreset.TopLeft: case LayoutPreset.TopRight: case LayoutPreset.LeftWide: case LayoutPreset.TopWide: case LayoutPreset.Wide: case LayoutPreset.RightWide: case LayoutPreset.CenterTop: case LayoutPreset.VerticalCenterWide: control.SetValue(AnchorTopProperty, 0f); break; case LayoutPreset.CenterLeft: case LayoutPreset.CenterRight: case LayoutPreset.HorizontalCenterWide: case LayoutPreset.Center: control.SetValue(AnchorTopProperty, 0.5f); break; case LayoutPreset.CenterBottom: case LayoutPreset.BottomLeft: case LayoutPreset.BottomRight: case LayoutPreset.BottomWide: control.SetValue(AnchorTopProperty, 1f); break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } // Right Anchor. switch (preset) { case LayoutPreset.TopLeft: case LayoutPreset.CenterLeft: case LayoutPreset.BottomLeft: case LayoutPreset.LeftWide: control.SetValue(AnchorRightProperty, 0f); break; case LayoutPreset.CenterTop: case LayoutPreset.CenterBottom: case LayoutPreset.Center: case LayoutPreset.VerticalCenterWide: control.SetValue(AnchorRightProperty, 0.5f); break; case LayoutPreset.CenterRight: case LayoutPreset.TopRight: case LayoutPreset.Wide: case LayoutPreset.HorizontalCenterWide: case LayoutPreset.TopWide: case LayoutPreset.BottomWide: case LayoutPreset.RightWide: case LayoutPreset.BottomRight: control.SetValue(AnchorRightProperty, 1f); break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } // Bottom Anchor. switch (preset) { case LayoutPreset.TopWide: case LayoutPreset.TopLeft: case LayoutPreset.TopRight: case LayoutPreset.CenterTop: control.SetValue(AnchorBottomProperty, 0f); break; case LayoutPreset.CenterLeft: case LayoutPreset.CenterRight: case LayoutPreset.Center: case LayoutPreset.HorizontalCenterWide: control.SetValue(AnchorBottomProperty, 0.5f); break; case LayoutPreset.CenterBottom: case LayoutPreset.BottomLeft: case LayoutPreset.BottomRight: case LayoutPreset.LeftWide: case LayoutPreset.Wide: case LayoutPreset.RightWide: case LayoutPreset.VerticalCenterWide: case LayoutPreset.BottomWide: control.SetValue(AnchorBottomProperty, 1f); break; default: throw new ArgumentOutOfRangeException(nameof(preset), preset, null); } }
public static LayoutPreset[] GetUserPresets() { var directory = new DirectoryInfo(Path.Combine(Mod.ConfigDirectory.FullName, PresetsDirectoryName)); return(directory.Exists ? directory.GetFiles("*" + PresetExtension).Select(file => LayoutPreset.Prepare(null, file)).Where(preset => preset != null).ToArray() : new LayoutPreset[] { }); }
public static LayoutPreset[] GetFixedPresets() { var list = new List <LayoutPreset>(); foreach (var mod in LoadedModManager.RunningMods) { var directory = new DirectoryInfo(Path.Combine(mod.RootDir, mod == Mod.ContentPack ? PresetsDirectoryName : ModPresetsDirectoryName)); if (!directory.Exists) { continue; } list.AddRange(directory.GetFiles("*" + PresetExtension).Select(file => LayoutPreset.Prepare(mod, file)).Where(preset => preset != null)); } return(list.ToArray()); }
private void Delete() { Persistent.DeleteLayoutPreset(_selected); _selected = null; LayoutPreset.RefreshUserPresets(); }
public static void Open() { LayoutPreset.RefreshUserPresets(); Find.WindowStack.Add(new Dialog_Presets()); }