Esempio n. 1
0
		protected override Control CreateOptions()
		{
			var foregroundPicker = new ColorPicker();
			foregroundPicker.ValueChanged += (sender, e) =>
			{
				foreach (var update in foregroundUpdates)
					update(foregroundPicker.Value);
			};

			var backgroundPicker = new ColorPicker();
			backgroundPicker.ValueChanged += (sender, e) =>
			{
				foreach (var update in backgroundUpdates)
					update(backgroundPicker.Value);
			};

			var formColorPicker = new ColorPicker { Value = BackgroundColor };
			formColorPicker.ValueChanged += (sender, e) => BackgroundColor = formColorPicker.Value;

			var fontPicker = new Button { Text = "Pick Font" };
			fontPicker.Click += (sender, e) =>
			{
				var dlg = new FontDialog();
				dlg.FontChanged += (sender2, e2) =>
				{
					var font = dlg.Font;
					foreach (var update in fontUpdates)
						update(font);
				};
				dlg.ShowDialog(this);
			};

			return new StackLayout
			{
				Orientation = Orientation.Horizontal,
				Spacing = 5,
				Items = {
					null,
					new Label { Text = "Text", VerticalAlignment = VerticalAlignment.Center },
					foregroundPicker,
					new Label { Text = "Background", VerticalAlignment = VerticalAlignment.Center },
					backgroundPicker,
					new Label { Text = "Form", VerticalAlignment = VerticalAlignment.Center },
					formColorPicker,
					fontPicker,
					null
				}
			};
		}
Esempio n. 2
0
		protected override Control CreateOptions()
		{
			var foregroundPicker = new ColorPicker();
			foregroundPicker.ValueChanged += (sender, e) =>
			{
				foreach (var update in foregroundUpdates)
					update(foregroundPicker.Value);
			};

			var backgroundPicker = new ColorPicker();
			backgroundPicker.ValueChanged += (sender, e) =>
			{
				foreach (var update in backgroundUpdates)
					update(backgroundPicker.Value);
			};

			var formColorPicker = new ColorPicker { Value = BackgroundColor };
			formColorPicker.ValueChanged += (sender, e) => BackgroundColor = formColorPicker.Value;

			var fontPicker = new Button { Text = "Pick Font" };
			fontPicker.Click += (sender, e) => {
				var dlg = new FontDialog();
				dlg.FontChanged += (sender2, e2) => {
					var font = dlg.Font;
					foreach (var update in fontUpdates)
						update(font);
				};
				dlg.ShowDialog(this);
			};

			return new TableLayout(
				new TableRow(
					null, 
					new Label { Text = "Text", VerticalAlign = VerticalAlign.Middle },
					foregroundPicker,
					new Label { Text = "Background", VerticalAlign = VerticalAlign.Middle },
					backgroundPicker,
					new Label { Text = "Form", VerticalAlign = VerticalAlign.Middle },
					formColorPicker,
					fontPicker,
					null
				)
			);
		}
Esempio n. 3
0
		Control PickFontWithStartingFont()
		{
			var button = new Button { Text = "Pick Font with initial starting font" };
			button.Click += delegate
			{
				var dialog = new FontDialog
				{
					Font = selectedFont
				};
				dialog.FontChanged += delegate
				{
					// need to handle this event for OS X, where the dialog is a floating window
					UpdatePreview(dialog.Font);
					Log.Write(dialog, "FontChanged, Font: {0}", dialog.Font);
				};
				var result = dialog.ShowDialog(ParentWindow);
				// do not get the font here, it may return immediately with a result of DialogResult.None on certain platforms
				Log.Write(dialog, "Result: {0}", result);
			};
			return button;
		}
Esempio n. 4
0
		Control PickFont()
		{
			var button = new Button { Text = "Pick Font" };
			button.Click += delegate
			{
				var dialog = new FontDialog();
				dialog.FontChanged += delegate
				{
					// you need to handle this event for OS X, where the dialog is a floating window
					UpdatePreview(dialog.Font);
					Log.Write(dialog, "FontChanged, Font: {0}", dialog.Font);
				};
				var result = dialog.ShowDialog(ParentWindow);
				Log.Write(dialog, "Result: {0}", result);
			};
			return button;
		}
Esempio n. 5
0
 /// <summary>
 /// Raises the font changed event.
 /// </summary>
 public void OnFontChanged(FontDialog widget, EventArgs e)
 {
     widget.Platform.Invoke(() => widget.OnFontChanged(e));
 }
Esempio n. 6
0
			/// <summary>
			/// Raises the font changed event.
			/// </summary>
			public void OnFontChanged(FontDialog widget, EventArgs e)
			{
				widget.Platform.Invoke(() => widget.OnFontChanged(e));
			}
Esempio n. 7
0
		public RichTextAreaSection()
		{
			var richText = new RichTextArea();
			richText.Size = new Size(-1, 300);
			richText.Text = LoremText;

			var range = new Range<int>(6, 10);
			var buffer = richText.Buffer;
			buffer.SetFont(range, Fonts.Cursive(20, FontStyle.Bold, FontDecoration.Underline));
			buffer.SetForeground(range, Colors.Blue);
			buffer.SetBackground(range, Colors.Yellow);

			buffer.SetBold(new Range<int>(11, 16), true);
			buffer.SetItalic(new Range<int>(18, 20), true);
			buffer.SetUnderline(new Range<int>(22, 25), true);
			buffer.SetStrikethrough(new Range<int>(28, 38), true);

			richText.CaretIndex = LoremText.Length - 1;

			richText.SelectionChanged += (sender, e) =>
			{
				UpdateBindings(BindingUpdateMode.Destination);
				Log.Write(sender, "SelectionChanged: {0}", richText.Selection);
			};

			var boldButton = new CheckBox { Text = "Bold" };
			boldButton.CheckedBinding.Bind(richText, r => r.SelectionBold);
			boldButton.CheckedChanged += (sender, e) =>
			{
				richText.Focus();
				UpdateBindings(BindingUpdateMode.Destination);
			};

			var italicButton = new CheckBox { Text = "Italic" };
			italicButton.CheckedBinding.Bind(richText, r => r.SelectionItalic);
			italicButton.CheckedChanged += (sender, e) =>
			{
				richText.Focus();
				UpdateBindings(BindingUpdateMode.Destination);
			};

			var underlineButton = new CheckBox { Text = "Underline" };
			underlineButton.CheckedBinding.Bind(richText, r => r.SelectionUnderline);
			underlineButton.CheckedChanged += (sender, e) => richText.Focus();

			var strikethroughButton = new CheckBox { Text = "Strikethrough" };
			strikethroughButton.CheckedBinding.Bind(richText, r => r.SelectionStrikethrough);
			strikethroughButton.CheckedChanged += (sender, e) => richText.Focus();

			var backgroundButton = new ColorPicker { };
			backgroundButton.ValueBinding.Bind(() => richText.SelectionBackground, val => richText.SelectionBackground = val, h => Binding.AddPropertyEvent(richText, r => r.SelectionBackground, h), h => Binding.RemovePropertyEvent(richText, h));
			backgroundButton.ValueChanged += (sender, e) => richText.Focus();

			var foregroundButton = new ColorPicker { };
			foregroundButton.ValueBinding.Bind(richText, r => r.SelectionForeground);
			foregroundButton.ValueChanged += (sender, e) => richText.Focus();

			var fontButton = new Button();
			fontButton.Bind(c => c.Text, new DelegateBinding<string>(() =>
			{
				var font = richText.SelectionFont;
				if (font == null)
					return "<No Font>";
				return string.Format("{0}, {1}, {2:0.00}pt", font.FamilyName, font.Typeface.Name, font.Size);
			}));
			var fd = new FontDialog();
			fontButton.Click += (sender, e) =>
			{
				fd.Font = richText.SelectionFont;
				fd.FontChanged += (s, ee) =>
				{
					richText.SelectionFont = fd.Font;
					UpdateBindings(BindingUpdateMode.Destination);
				};
				if (fd.ShowDialog(this) == DialogResult.Ok)
					richText.Focus();
			};

			var familyDropDown = new DropDown();
			familyDropDown.DataStore = Fonts.AvailableFontFamilies.OrderBy(r => r.Name);
			familyDropDown.SelectedValueBinding.Bind(richText, r => r.SelectionFamily);
			familyDropDown.SelectedValueChanged += (sender, e) =>
			{
				richText.Focus();
				UpdateBindings(BindingUpdateMode.Destination);
			};

			var formatEnum = new EnumDropDown<RichTextAreaFormat>();
			formatEnum.SelectedValue = RichTextAreaFormat.Rtf;

			var loadButton = new Button { Text = "Load" };
			loadButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue);
			loadButton.Click += (sender, e) => buffer.Load(new MemoryStream(Encoding.UTF8.GetBytes(formatEnum.SelectedValue == RichTextAreaFormat.Rtf ? RtfString : LoremText)), formatEnum.SelectedValue);

			var saveButton = new Button { Text = "Save" };
			saveButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue);
			saveButton.Click += (sender, e) =>
			{
				var stream = new MemoryStream();
				buffer.Save(stream, formatEnum.SelectedValue);
				stream.Position = 0;
				Log.Write(richText, "Saved {0}:\n{1}", formatEnum.SelectedValue, new StreamReader(stream).ReadToEnd());
			};

			formatEnum.SelectedValueChanged += (sender, e) => saveButton.Enabled = loadButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue);

			var clearButton = new Button { Text = "Clear" };
			clearButton.Click += (sender, e) => buffer.Clear();

			var formatting1 = new StackLayout
			{
				Orientation = Orientation.Horizontal,
				Spacing = 5,
				Items =
				{
				    null,
				    boldButton,
				    italicButton,
				    underlineButton,
				    strikethroughButton,
				    null
				}
			};

			var formatting2 = new StackLayout
			{
				Orientation = Orientation.Horizontal,
				Spacing = 5,
				Items =
				{
					null,
					new Label { Text = "Foreground", VerticalAlignment = VerticalAlignment.Center },
					TableLayout.AutoSized(foregroundButton, centered: true),
					new Label { Text = "Background", VerticalAlignment = VerticalAlignment.Center },
					TableLayout.AutoSized(backgroundButton, centered: true),
					null
				}
			};
			var formatting3 = new StackLayout
			{
				Orientation = Orientation.Horizontal,
				Spacing = 5,
				Items =
				{
				    null,
				    fontButton,
				    familyDropDown,
				    null
				}
			};

			var buttons = new StackLayout
			{
				Orientation = Orientation.Horizontal,
				Spacing = 5,
				Items =
				{
				    null,
				    formatEnum,
				    loadButton,
				    saveButton,
				    clearButton,
				    null
				}
			};

			Content = new StackLayout
			{
				Padding = new Padding(10),
				Spacing = 5,
				HorizontalContentAlignment = HorizontalAlignment.Stretch,
				Items =
				{
					buttons,
					TextAreaSection.TextAreaOptions(richText),
					TextAreaSection.TextAreaOptions2(richText),
					TextAreaSection.TextAreaOptions3(richText),
					formatting1,
					formatting2,
					formatting3,
					new StackLayoutItem(richText, expand: true)
				}
			};
		}
Esempio n. 8
0
        public MainForm()
        {
            Title      = $"CodeEditor Test, Platform: {Platform.ID}";
            ClientSize = new Size(1400, 800);

            Menu = new MenuBar(); // show standard macOS menu.


            var editor = new CodeEditor(ProgrammingLanguage.CSharp, true);

            editor.Text =
                @"// Just some sample code
for( int i=0; i<10; i++ )
{
  print(i);
}";
            editor.IsFoldingMarginVisible = true;

            editor.SetupIndicatorStyles();
            editor.AddErrorIndicator(13, 6);

            Action <Font, string> pp = (f, pfx) => MessageBox.Show($"{pfx}: name: {editor.Font.FamilyName}, size: {editor.FontSize}");

            var btn = new Button {
                Text = "Font"
            };

            btn.Click += (s, e) =>
            {
                var originalFont = editor.Font ?? SystemFonts.Default();
                pp(originalFont, "first");
                var fd = new Eto.Forms.FontDialog {
                    Font = originalFont
                };
                fd.FontChanged += (ss, ee) =>
                {
                    editor.Font = fd.Font;
                    pp(editor.Font, "FontChanged");
                };
                var r = fd.ShowDialog(this);
                editor.Font = (r == DialogResult.Ok || r == DialogResult.Yes)
                  ? fd.Font
                  : originalFont;

                pp(fd.Font, "fd");
                pp(editor.Font, "editor");
                //editor.ShowWhitespaceWithColor(Colors.Red);
                //editor.Text = $"name: {editor.FontName}, size: {editor.FontSize}";
            };


            var tests = new Eto.UnitTest.UI.UnitTestPanel(true, Orientation.Vertical);

            this.LoadComplete += async(s, e) =>
            {
                var testSource = new UnitTest.TestSource(System.Reflection.Assembly.GetExecutingAssembly());
                var mtr        = new Eto.UnitTest.Runners.MultipleTestRunner();
                await mtr.Load(testSource);

                tests.Runner           = new UnitTest.Runners.LoggingTestRunner(mtr);
                CodeEditorTests.editor = editor;
                RegexTests.editor      = editor;
            };

            var ta = new TextArea {
                Height = 200
            };

            editor.SelectionChanged                       += (s, e) =>
                                                  ta.Text += $"empty: {e.SelectionIsEmpty}, s:{e.SelectionStart}, e:{e.SelectionEnd}, txt:{e.SelectionText}\n";

            var splitter = new Splitter
            {
                Panel1 = tests,
                Panel2 = new Splitter {
                    Panel1 = editor, Panel2 = ta, Orientation = Orientation.Vertical, Panel1MinimumSize = 100, FixedPanel = SplitterFixedPanel.Panel2
                }
            };

            Content = new TableLayout {
                Rows = { splitter }
            };
        }
Esempio n. 9
0
 /// <summary>
 /// Raises the font changed event.
 /// </summary>
 public void OnFontChanged(FontDialog widget, EventArgs e)
 {
     using (widget.Platform.Context)
         widget.OnFontChanged(e);
 }