-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- allow values to not conform to IWritable. This makes dealing with values that don't change nicer. - Component Base: - extract core component logic into reusable base class. - expose `ForceRender` method. - DSL: - Panel add create - Text Block add padding overload - TODO App: - Add modal host sample
- Loading branch information
Showing
11 changed files
with
327 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
namespace Avalonia.FuncUI | ||
|
||
open System | ||
open System.Diagnostics.CodeAnalysis | ||
open Avalonia.Controls | ||
open Avalonia.FuncUI | ||
open Avalonia.FuncUI.Types | ||
open Avalonia.FuncUI.VirtualDom | ||
open Avalonia.Threading | ||
|
||
[<AllowNullLiteral>] | ||
[<AbstractClass>] | ||
[<DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)>] | ||
type ComponentBase() as this = | ||
inherit Border () | ||
let context = new Context(this) | ||
let componentId = Guid.Unique | ||
|
||
let mutable lastViewElement : IView option = None | ||
let mutable lastViewAttrs: IAttr list = List.empty | ||
|
||
member internal this.Context with get () = context | ||
member internal this.ComponentId with get () = componentId | ||
|
||
abstract member Render : IComponentContext -> IView | ||
|
||
member private this.UIThreadUpdate() : unit = | ||
let nextViewElement = Some (this.Render context) | ||
|
||
// reset internal context counter | ||
context.AfterRender () | ||
|
||
// update view | ||
VirtualDom.updateBorderRoot (this, lastViewElement, nextViewElement) | ||
lastViewElement <- nextViewElement | ||
|
||
let nextViewAttrs = context.ComponentAttrs | ||
|
||
// update attrs | ||
Patcher.patch ( | ||
this, | ||
{ Delta.ViewDelta.ViewType = typeof<Border> | ||
Delta.ViewDelta.ConstructorArgs = null | ||
Delta.ViewDelta.KeyDidChange = false | ||
Delta.ViewDelta.Outlet = ValueNone | ||
Delta.ViewDelta.Attrs = Differ.diffAttributes (lastViewAttrs, nextViewAttrs) } | ||
) | ||
|
||
lastViewAttrs <- nextViewAttrs | ||
|
||
context.EffectQueue.ProcessAfterRender () | ||
|
||
member private this.Update () : unit = | ||
Dispatcher.UIThread.Post (fun _ -> this.UIThreadUpdate ()) | ||
|
||
member this.ForceRender () = | ||
this.Update () | ||
|
||
override this.OnInitialized () = | ||
base.OnInitialized () | ||
|
||
(context :> IComponentContext).trackDisposable ( | ||
context.OnRender.Subscribe (fun _ -> | ||
this.Update () | ||
) | ||
) | ||
|
||
this.UIThreadUpdate () | ||
|
||
override this.OnDetachedFromLogicalTree (eventArgs: Avalonia.LogicalTree.LogicalTreeAttachmentEventArgs) = | ||
base.OnDetachedFromLogicalTree eventArgs | ||
(context :> IDisposable).Dispose () | ||
|
||
override this.StyleKeyOverride = typeof<Border> |
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,25 +1,27 @@ | ||
namespace Avalonia.FuncUI.DSL | ||
|
||
[<AutoOpen>] | ||
module Panel = | ||
module Panel = | ||
open Avalonia.Controls | ||
open Avalonia.FuncUI.Types | ||
open Avalonia.FuncUI.Builder | ||
open Avalonia.Media.Immutable | ||
open Avalonia.Media | ||
|
||
let create (attrs: IAttr<Panel> list): IView<Panel> = | ||
ViewBuilder.Create<Panel>(attrs) | ||
|
||
type Panel with | ||
|
||
static member children<'t when 't :> Panel>(value: IView list) : IAttr<'t> = | ||
let getter : ('t -> obj) = (fun control -> control.Children :> obj) | ||
|
||
AttrBuilder<'t>.CreateContentMultiple("Children", ValueSome getter, ValueNone, value) | ||
|
||
static member background<'t when 't :> Panel>(value: IBrush) : IAttr<'t> = | ||
AttrBuilder<'t>.CreateProperty<IBrush>(Panel.BackgroundProperty, value, ValueNone) | ||
|
||
static member background<'t when 't :> Panel>(color: string) : IAttr<'t> = | ||
color |> Color.Parse |> ImmutableSolidColorBrush |> Panel.background | ||
color |> Color.Parse |> ImmutableSolidColorBrush |> Panel.background | ||
|
||
static member background<'t when 't :> Panel>(color: Color) : IAttr<'t> = | ||
color |> ImmutableSolidColorBrush |> Panel.background |
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
Oops, something went wrong.