Skip to content

Commit

Permalink
Add iOS TextEditor project
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Dec 11, 2018
1 parent 4b22ab0 commit dbf703f
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 7 deletions.
15 changes: 15 additions & 0 deletions CLanguage.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{4542
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CEditor", "Samples\Mac\CEditor.csproj", "{E2A5AB72-C825-47F7-96BD-D102192C4B99}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLanguage.Editor.iOS", "Editor\iOS\CLanguage.Editor.iOS.csproj", "{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,18 @@ Global
{E2A5AB72-C825-47F7-96BD-D102192C4B99}.Release|x64.Build.0 = Release|x86
{E2A5AB72-C825-47F7-96BD-D102192C4B99}.Release|x86.ActiveCfg = Release|x86
{E2A5AB72-C825-47F7-96BD-D102192C4B99}.Release|x86.Build.0 = Release|x86
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Debug|x64.ActiveCfg = Debug|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Debug|x64.Build.0 = Debug|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Debug|x86.ActiveCfg = Debug|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Debug|x86.Build.0 = Debug|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Release|Any CPU.Build.0 = Release|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Release|x64.ActiveCfg = Release|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Release|x64.Build.0 = Release|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Release|x86.ActiveCfg = Release|Any CPU
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -100,5 +114,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{13FC4538-EA48-4F84-9F1A-109701F9285F} = {708F9D6D-D03E-4C60-AEEE-85276AD55A24}
{E2A5AB72-C825-47F7-96BD-D102192C4B99} = {45420E5C-B4D7-4E1B-A850-80B74885D96C}
{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0} = {708F9D6D-D03E-4C60-AEEE-85276AD55A24}
EndGlobalSection
EndGlobal
13 changes: 12 additions & 1 deletion Editor/Mac/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
using NativeColor = UIKit.UIColor;
using NativeFont = UIKit.UIFont;
using NativeStringAttributes = UIKit.UIStringAttributes;
using NativeTextAlignment = UIKit.UITextAlignment;
#elif __MACOS__
using AppKit;
using NativeColor = AppKit.NSColor;
using NativeFont = AppKit.NSFont;
using NativeStringAttributes = AppKit.NSStringAttributes;
using NativeTextAlignment = AppKit.NSTextAlignment;
#endif

using Foundation;

namespace CLanguage.Editor
{
static class Extensions
Expand All @@ -28,12 +32,19 @@ public static string GetIndent (this string line)

#if __IOS__
public static NativeColor Rgb (int r, int g, int b) => NativeColor.FromRGB (r, g, b);
public static NativeColor Gray (int g) => NativeColor.FromWhite (g / ((nfloat)255), 1);
public static NativeColor Gray (int g) => NativeColor.FromWhiteAlpha (g / ((nfloat)255), 1);
public static NativeFont Font (string name, int size) => NativeFont.FromName (name, size);
public static string GetFontName (this NativeFont f) => f.Name;
public static NSUnderlineStyle ToKit (this NSUnderlineStyle s) => s;
public static NativeColor ColorWithAlphaComponent (this NativeColor color, nfloat alpha) => color.ColorWithAlpha (alpha);
public static NativeTextAlignment TextAlignmentRight = NativeTextAlignment.Right;
#else
public static NativeColor Rgb (int r, int g, int b) => NativeColor.FromRgb (r, g, b);
public static NativeColor Gray (int g) => NativeColor.FromWhite (g / ((nfloat)255), 1);
public static NativeFont Font (string name, int size) => NativeFont.FromFontName (name, size);
public static string GetFontName (this NativeFont f) => f.FontName;
public static NSUnderlineStyle ToKit (this NSUnderlineStyle s) => (nint)s;
public static NativeTextAlignment TextAlignmentRight = NativeTextAlignment.Right;
#endif
}
}
37 changes: 31 additions & 6 deletions Editor/Mac/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ public Theme (bool isDark)
ForegroundColor = !isDark ? Rgb (101, 121, 140) : Rgb (127, 140, 152),
}.Dictionary;
SelectedAttributes = new NativeStringAttributes {
BackgroundColor = !isDark ? NSColor.SelectedTextBackground : NSColor.SelectedTextBackground.ColorWithAlphaComponent (0.5f),
#if __MACOS__
BackgroundColor = !isDark ? NativeColor.SelectedTextBackground : NativeColor.SelectedTextBackground.ColorWithAlphaComponent (0.5f),
#elif __IOS__
BackgroundColor = Rgb (0, 0x84, 0xD1).ColorWithAlpha (0.5f),
#endif
}.Dictionary;

BackgroundColor = NativeColor.TextBackground;
BackgroundColor = !isDark ? Rgb (0xFF, 0xFF, 0xFF) : Rgb (41, 42, 47);
ErrorBubbleBackgroundColor = !isDark ? Rgb (0xC5, 0, 0xB) : Rgb (0xC5 * 2 /4, 0, 0xB);
ErrorBubbleTextAttributes = new NativeStringAttributes {
ForegroundColor = Gray (255).ColorWithAlphaComponent (0.9375f),
Expand All @@ -75,12 +79,13 @@ public Theme (bool isDark)
ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Function] = MakeAttrs (Rgb (204, 102, 0), Rgb (255, 161, 79));
}

#if __MACOS__
public NSDictionary ErrorAttributes (string message)
{
return new NativeStringAttributes {
//BackgroundColor = !isDark ? Rgb (0xFF, 0xCC, 0xCC) : Rgb (0x55, 0x00, 0x00),
UnderlineColor = !isDark ? Rgb (0xFE, 0x00, 0x0B) : Rgb (0xFF, 0x00, 0x0B),
UnderlineStyle = (int)NSUnderlineStyle.Thick,
UnderlineStyle = NSUnderlineStyle.Thick.ToKit (),
ToolTip = message,
}.Dictionary;
}
Expand All @@ -89,33 +94,53 @@ public NSDictionary WarningAttributes (string message)
{
return new NativeStringAttributes {
UnderlineColor = NativeColor.SystemYellowColor,// !isDark ? Rgb (120, 73, 42) : Rgb (0xFF, 0xD3, 0x20),
UnderlineStyle = (int)NSUnderlineStyle.Thick,
UnderlineStyle = NSUnderlineStyle.Thick.ToKit (),
ToolTip = message,
}.Dictionary;
}
#elif __IOS__
public NSDictionary ErrorAttributes (string message)
{
return new NativeStringAttributes {
//BackgroundColor = !isDark ? Rgb (0xFF, 0xCC, 0xCC) : Rgb (0x55, 0x00, 0x00),
UnderlineColor = !isDark ? Rgb (0xFE, 0x00, 0x0B) : Rgb (0xFF, 0x00, 0x0B),
UnderlineStyle = NSUnderlineStyle.Thick.ToKit (),
}.Dictionary;
}

public NSDictionary WarningAttributes (string message)
{
return new NativeStringAttributes {
UnderlineColor = NativeColor.Yellow,// !isDark ? Rgb (120, 73, 42) : Rgb (0xFF, 0xD3, 0x20),
UnderlineStyle = NSUnderlineStyle.Thick.ToKit (),
}.Dictionary;
}
#endif

NSDictionary MakeAttrs (NativeColor color, NativeColor darkColor) => new NativeStringAttributes {
Font = codeFont,
ForegroundColor = isDark ? darkColor : color,
}.Dictionary;

NSDictionary MakeLineNumberAttrs () => new NativeStringAttributes {
Font = Font (codeFont.FontName, (int)(NativeFont.SystemFontSize * 0.8 + 0.5)),
Font = Font (codeFont.GetFontName (), (int)(NativeFont.SystemFontSize * 0.8 + 0.5)),
ForegroundColor = LineNumberColor,
ParagraphStyle = new NSMutableParagraphStyle {
Alignment = NSTextAlignment.Right,
Alignment = TextAlignmentRight,
}
}.Dictionary;

static string FindFontFamily ()
{
#if __MACOS__
var fonts = NSFontManager.SharedFontManager.AvailableFonts;
if (NSScreen.MainScreen.BackingScaleFactor > 1.1 && fonts.Contains ("FiraCode-Retina")) {
return "FiraCode-Retina";
}
if (fonts.Contains ("FiraCode-Regular")) {
return "FiraCode-Regular";
}
#endif
return "Menlo-Regular";
}
}
Expand Down
65 changes: 65 additions & 0 deletions Editor/iOS/CLanguage.Editor.iOS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{82DEEC57-00B6-4878-A3A2-BB8616BFA1A0}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>CLanguage.Editor.iOS</RootNamespace>
<AssemblyName>CLanguage.Editor.iOS</AssemblyName>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchFastDev>true</MtouchFastDev>
<MtouchProfiling>true</MtouchProfiling>
<IOSDebuggerPort>64808</IOSDebuggerPort>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\Mac\Theme.cs">
<Link>Theme.cs</Link>
</Compile>
<Compile Include="..\Mac\Extensions.cs">
<Link>Extensions.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CLanguage\CLanguage.csproj">
<Project>{A53988E1-9F38-44E6-8B29-8C3F1C4CD487}</Project>
<Name>CLanguage</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>
26 changes: 26 additions & 0 deletions Editor/iOS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("CLanguage.Editor.iOS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

0 comments on commit dbf703f

Please sign in to comment.