This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mac] Initial Variations Implementation
- Loading branch information
1 parent
807d5c7
commit c0bfc0c
Showing
7 changed files
with
229 additions
and
63 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
Xamarin.PropertyEditing.Mac/Controls/CreateVariantView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using System; | ||
using System.Reflection; | ||
using AppKit; | ||
using CoreGraphics; | ||
using Foundation; | ||
using Xamarin.PropertyEditing.ViewModels; | ||
|
||
namespace Xamarin.PropertyEditing.Mac | ||
{ | ||
internal class CreateVariantView | ||
: BasePopOverViewModelControl | ||
{ | ||
private const int FrameWidth = 250; | ||
private const int ControlSpacing = 7; | ||
private const int RightEdgeMargin = 12; | ||
|
||
public CreateVariantView (IHostResourceProvider hostResources, PropertyViewModel propertyViewModel) | ||
: base (hostResources, propertyViewModel, Properties.Resources.AddVariationTitle, "pe-resource-editor-32") | ||
{ | ||
Initialize (new CreateVariantViewModel (propertyViewModel.Property)); | ||
} | ||
|
||
private void Initialize (CreateVariantViewModel createVariantViewModel) | ||
{ | ||
Frame = new CGRect (CGPoint.Empty, new CGSize (FrameWidth, 240)); | ||
|
||
int editorHeight = 18; | ||
|
||
var FrameWidthThird = Frame.Width / 3; | ||
|
||
var introduceVariation = new UnfocusableTextField { | ||
StringValue = Properties.Resources.AddVariationHelpText, | ||
TranslatesAutoresizingMaskIntoConstraints = false, | ||
}; | ||
|
||
AddSubview (introduceVariation); | ||
|
||
this.AddConstraints (new[] { | ||
NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f), | ||
NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 18f), | ||
NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), | ||
NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), | ||
}); | ||
|
||
var controlTop = 60; | ||
|
||
var okButton = new FocusableButton { | ||
BezelStyle = NSBezelStyle.Rounded, | ||
Enabled = false, | ||
Highlighted = true, | ||
Title = Properties.Resources.AddVariation, | ||
TranslatesAutoresizingMaskIntoConstraints = false, | ||
}; | ||
|
||
foreach (var viewModel in createVariantViewModel.VariationCategories) { | ||
|
||
var name = new UnfocusableTextField { | ||
Alignment = NSTextAlignment.Right, | ||
StringValue = viewModel.Name + ":", | ||
TranslatesAutoresizingMaskIntoConstraints = false, | ||
}; | ||
|
||
AddSubview (name); | ||
|
||
this.AddConstraints (new[] { | ||
NSLayoutConstraint.Create (name, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, controlTop), | ||
NSLayoutConstraint.Create (name, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, FrameWidthThird), | ||
NSLayoutConstraint.Create (name, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight) | ||
}); | ||
|
||
var popUpButton = new FocusablePopUpButton { | ||
ControlSize = NSControlSize.Small, | ||
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), | ||
TranslatesAutoresizingMaskIntoConstraints = false, | ||
}; | ||
|
||
popUpButton.Activated += (o, e) => { | ||
if (o is FocusablePopUpButton fpb) { | ||
if (fpb.SelectedItem.RepresentedObject is NSObjectFacade menuObjectFacade) { | ||
if (menuObjectFacade.Target is VariationFacade vf) { | ||
vf.ViewModel.SelectedOption = vf.Option; | ||
okButton.Enabled = createVariantViewModel.CreateVariantCommand.CanExecute (null); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var popUpButtonList = new NSMenu (); | ||
popUpButton.Menu = popUpButtonList; | ||
|
||
AddSubview (popUpButton); | ||
|
||
this.AddConstraints (new[] { | ||
NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, controlTop), | ||
NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, FrameWidthThird + ControlSpacing), | ||
NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -FrameWidthThird - ControlSpacing - RightEdgeMargin), | ||
NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight) | ||
}); | ||
|
||
foreach (var variation in viewModel.Variations) { | ||
popUpButtonList.AddItem (new NSMenuItem (variation.Name) { | ||
RepresentedObject = new NSObjectFacade ( | ||
new VariationFacade { | ||
Option = variation, | ||
ViewModel = viewModel }) | ||
}); | ||
} | ||
|
||
controlTop += editorHeight + 8; | ||
} | ||
|
||
okButton.Activated += (sender, e) => { | ||
// TODO Add the Variation | ||
|
||
PopOver.Close (); | ||
}; | ||
|
||
AddSubview (okButton); | ||
|
||
this.AddConstraints (new[] { | ||
NSLayoutConstraint.Create (okButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -RightEdgeMargin), | ||
NSLayoutConstraint.Create (okButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1, -RightEdgeMargin), | ||
NSLayoutConstraint.Create (okButton, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 80) | ||
}); | ||
|
||
Frame = new CGRect (CGPoint.Empty, new CGSize (FrameWidth, controlTop + editorHeight * 2)); | ||
} | ||
} | ||
|
||
internal class VariationFacade | ||
{ | ||
public PropertyVariationOption Option { get; set; } | ||
public VariationViewModel ViewModel { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters