-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b47388f
commit e75371a
Showing
12 changed files
with
388 additions
and
115 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,61 @@ | ||
namespace Fabulous.Maui | ||
|
||
open System.Collections.Generic | ||
open System.Runtime.CompilerServices | ||
open Fabulous | ||
open Fabulous.StackAllocatedCollections | ||
open Fabulous.StackAllocatedCollections.StackList | ||
open Microsoft.Maui | ||
|
||
type FabulousApplication() = | ||
inherit Node() | ||
inherit Node(Microsoft.Maui.Handlers.ApplicationHandler()) | ||
|
||
interface Microsoft.Maui.IApplication with | ||
let _windows = List<IWindow>() | ||
member this.Windows = _windows | ||
|
||
interface IApplication with | ||
member this.CloseWindow(window) = failwith "todo" | ||
member this.CreateWindow(activationState) = failwith "todo" | ||
member this.CreateWindow(activationState) = _windows[0] | ||
member this.OpenWindow(window) = failwith "todo" | ||
member this.ThemeChanged() = failwith "todo" | ||
member this.Handler = failwith "todo" | ||
member this.Parent = failwith "todo" | ||
member this.Windows = failwith "todo" | ||
member this.Handler with set value = failwith "todo" | ||
member this.Handler | ||
with get () = this.Handler | ||
and set value = this.Handler <- value | ||
member this.Parent = this.Parent | ||
member this.Windows = _windows :> IReadOnlyList<_> | ||
|
||
module Application = | ||
let WidgetKey = Widgets.register<FabulousApplication>() | ||
|
||
let Windows = | ||
Attributes.defineListWidgetCollection | ||
"Application_Windows" | ||
ViewNode.get | ||
(fun target -> (target :?> FabulousApplication).Windows) | ||
|
||
[<AutoOpen>] | ||
module ApplicationBuilders = | ||
type Fabulous.Maui.View with | ||
static member inline Application<'msg>() = | ||
WidgetBuilder<'msg, IApplication>( | ||
CollectionBuilder<'msg, IApplication, IWindow>( | ||
Application.WidgetKey, | ||
AttributesBundle(StackList.empty(), ValueNone, ValueNone) | ||
Application.Windows | ||
) | ||
|
||
[<Extension>] | ||
type ApplicationCollectionExtensions = | ||
[<Extension>] | ||
static member inline Yield<'msg, 'itemType when 'itemType :> IWindow> | ||
( | ||
_: CollectionBuilder<'msg, IApplication, IWindow>, | ||
x: WidgetBuilder<'msg, 'itemType> | ||
) = | ||
{ Widgets = MutStackArray1.One(x.Compile()) } : Content<'msg> | ||
|
||
[<Extension>] | ||
static member inline Yield<'msg, 'itemType when 'itemType :> IWindow> | ||
( | ||
_: CollectionBuilder<'msg, IApplication, IWindow>, | ||
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>> | ||
) = | ||
{ Widgets = MutStackArray1.One(x.Compile()) } : Content<'msg> |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
namespace Fabulous.Maui | ||
|
||
open System.Runtime.CompilerServices | ||
open Microsoft.Maui | ||
open Microsoft.Maui.Graphics | ||
open Microsoft.Maui.Handlers | ||
open Fabulous | ||
|
||
type FabulousLabel() = | ||
inherit Node(LabelHandler()) | ||
|
||
let mutable _frame = Rect.Zero | ||
let mutable _desiredSize = Size.Zero | ||
|
||
member val Text = "" with get, set | ||
member val TextColor = Colors.Black with get, set | ||
|
||
interface ILabel with | ||
member this.Arrange(bounds) = | ||
_frame <- Microsoft.Maui.Layouts.LayoutExtensions.ComputeFrame(this, bounds) | ||
let viewHandler = this.Handler :?> IViewHandler | ||
if viewHandler <> null then viewHandler.PlatformArrange(_frame) | ||
_frame.Size | ||
|
||
member this.Focus() = failwith "todo" | ||
member this.InvalidateArrange() = failwith "todo" | ||
member this.InvalidateMeasure() = failwith "todo" | ||
member this.Measure(widthConstraint, heightConstraint) = | ||
_desiredSize <- Microsoft.Maui.Layouts.LayoutExtensions.ComputeDesiredSize(this, widthConstraint, heightConstraint) | ||
_desiredSize | ||
|
||
member this.Unfocus() = failwith "todo" | ||
member this.AnchorX = 0.5 | ||
member this.AnchorY = 0.5 | ||
member this.AutomationId = null | ||
member this.Background = SolidPaint(Colors.White) | ||
member this.CharacterSpacing = 1. | ||
member this.Clip = null | ||
member this.DesiredSize = failwith "todo" | ||
member this.FlowDirection = FlowDirection.MatchParent | ||
member this.Font = Microsoft.Maui.Font.Default | ||
member this.Frame = _frame | ||
member this.Height = -1 | ||
member this.HorizontalLayoutAlignment = failwith "todo" | ||
member this.HorizontalTextAlignment = TextAlignment.Start | ||
member this.InputTransparent = true | ||
member this.IsEnabled = failwith "todo" | ||
member this.IsFocused = failwith "todo" | ||
member this.LineHeight = 1. | ||
member this.Margin = failwith "todo" | ||
member this.MaximumHeight = failwith "todo" | ||
member this.MaximumWidth = failwith "todo" | ||
member this.MinimumHeight = failwith "todo" | ||
member this.MinimumWidth = failwith "todo" | ||
member this.Opacity = 1. | ||
member this.Padding = Thickness() | ||
member this.Parent = this.Parent | ||
member this.Rotation = 0. | ||
member this.RotationX = 0. | ||
member this.RotationY = 0. | ||
member this.Scale = 1. | ||
member this.ScaleX = 1. | ||
member this.ScaleY = 1. | ||
member this.Semantics = null | ||
member this.Shadow = null | ||
member this.Text = this.Text | ||
member this.TextColor = this.TextColor | ||
member this.TextDecorations = TextDecorations.None | ||
member this.TranslationX = 0. | ||
member this.TranslationY = 0. | ||
member this.VerticalLayoutAlignment = failwith "todo" | ||
member this.VerticalTextAlignment = failwith "todo" | ||
member this.Visibility = Visibility.Visible | ||
member this.Width = -1 | ||
member this.ZIndex = failwith "todo" | ||
member this.Frame with set value = failwith "todo" | ||
member this.IsFocused with set value = failwith "todo" | ||
|
||
member this.Handler | ||
with get () : IElementHandler = this.Handler | ||
and set value = this.Handler <- value | ||
|
||
member this.Handler | ||
with get () = this.Handler :?> IViewHandler | ||
and set (value: IViewHandler) = this.Handler <- value | ||
|
||
module FabulousLabel = | ||
let WidgetKey = Widgets.register<FabulousLabel>() | ||
|
||
let Text = | ||
Attributes.defineSimpleScalarWithEquality<string> | ||
"Text" | ||
(fun _ newValue node -> | ||
let target = node.Target :?> FabulousLabel | ||
match newValue with | ||
| ValueNone -> target.Text <- "" | ||
| ValueSome value -> target.Text <- value | ||
let res = (target :> ILabel).Handler | ||
res.UpdateValue("Text")) | ||
|
||
let TextColor = | ||
Attributes.defineSimpleScalarWithEquality<Color> | ||
"TextColor" | ||
(fun _ newValue node -> | ||
let target = node.Target :?> FabulousLabel | ||
match newValue with | ||
| ValueNone -> target.TextColor <- null | ||
| ValueSome value -> target.TextColor <- value | ||
let res = (target :> ILabel).Handler | ||
res.UpdateValue("TextColor")) | ||
|
||
[<AutoOpen>] | ||
module LabelBuilders = | ||
type Fabulous.Maui.View with | ||
static member inline Label<'msg>(text: string) = | ||
WidgetBuilder<'msg, ILabel>(FabulousLabel.WidgetKey, FabulousLabel.Text.WithValue(text)) | ||
|
||
[<Extension>] | ||
type LabelModifiers = | ||
[<Extension>] | ||
static member inline textColor(this: WidgetBuilder<'msg, #ILabel>, value: Color) = | ||
this.AddScalar(FabulousLabel.TextColor.WithValue(value)) |
Oops, something went wrong.