These are chat archives for AvaloniaUI/Avalonia

21st
Dec 2018
Nikita Tsukanov
@kekekeks
Dec 21 2018 05:50 UTC
I don't think you can write something like Core2D using Flux/Redux
Not something with potentially millions of objects in "application state tree"
Miha Markič
@MihaMarkic
Dec 21 2018 06:25 UTC
I did some experiments with redux https://github.com/MihaMarkic/sharp-redux and react https://github.com/MihaMarkic/SharpReact Don't have Avalonia bindings ATM. But seems doable. The beauty of redux/react is that it simplifies things a lot, plus makes app repeatable and better testable.
Jonathan
@vanillajonathan
Dec 21 2018 09:09 UTC
Oh, cool
Jonathan
@vanillajonathan
Dec 21 2018 09:43 UTC
I've heard that WPF have dynamic binding while UWP have static binding. It seems Avalonia also have dynamic binding, but maybe static would have been better.
Nikita Tsukanov
@kekekeks
Dec 21 2018 09:46 UTC
x:Bind?
Jonathan
@vanillajonathan
Dec 21 2018 09:46 UTC
Yeah, that one.
I have no experience with WPF or UWP but static binding sounds nicer to me than dynamic binding. Can static typing be used on Avalonia? I guess this is an area where UWP is better than WPF.
Nikita Tsukanov
@kekekeks
Dec 21 2018 09:48 UTC
Won't be available until we get a XAML compiler
Which isn't planned anytime soon, I think
XAML-to-MSIL compiler, I mean
Sergey Terekhin
@Sergey-Terekhin
Dec 21 2018 09:50 UTC
Hi everyone!
Have you seen this present from MS: https://github.com/dotnet/wpf
Nikita Tsukanov
@kekekeks
Dec 21 2018 09:50 UTC
Yes, but haven't seen any actual WPF source code there
Only System.Xaml
Sergey Terekhin
@Sergey-Terekhin
Dec 21 2018 10:35 UTC
They promise to add it later )
Jonathan
@vanillajonathan
Dec 21 2018 11:28 UTC
When they release the promised source code, then what does that mean for Avalonia?
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:47 UTC

Hi, I'm trying to use Avalonia from F# Interactive on windows, I have this minimal code:

#r @"../packages/NETStandard.Library/build/netstandard2.0/ref/netstandard.dll"
#load "../.paket/load/net462/Avalonia.Desktop.fsx"
#load "../.paket/load/netstandard2.0/Avalonia.Desktop.fsx"
open Avalonia
AppBuilder
  .Configure<Avalonia.Application>()
  .UsePlatformDetect()
  .SetupWithoutStarting()

let app = Avalonia.Application()
app.Initialize()

let form = Avalonia.Controls.Window()
form.Show()
form.PointerPressed.Add(fun i -> printfn "%A" i)
form.Activated.Add(fun i -> printfn "gotfocus")
form.set_Background Avalonia.Media.Brushes.Wheat

the form appears but the contents are frozen with whatever was behind the form (my desktop) when it is initially shown.

Nikita Tsukanov
@kekekeks
Dec 21 2018 11:47 UTC
several controls ported and a good foundation for accessibility support
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:48 UTC
image.png
Nikita Tsukanov
@kekekeks
Dec 21 2018 11:48 UTC
let app = Avalonia.Application()
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:48 UTC
the Activated event does work
Nikita Tsukanov
@kekekeks
Dec 21 2018 11:48 UTC
don't do this
you also need an actual xaml to be loaded with the app
you won't get the control theme otherwise
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:49 UTC
In the docs, I haven't found examples that wouldn't involve creating a project and dealing with assembly resources. I'm looking for a way I could manage it without too much extra files from a script, even if barebone
Nikita Tsukanov
@kekekeks
Dec 21 2018 11:51 UTC
You need to at least initialize style includes
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:52 UTC
@kekekeks thanks, is there any code sample or in the library itself that I should look at to make basic initialisation programmatically?
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:53 UTC
the platform detection seems to run fine, and I'm eager to look at the library further, but being able to fiddle with it from FSI is important for my current experimentations
Nikita Tsukanov
@kekekeks
Dec 21 2018 11:53 UTC
Since F# is now built-in to .NET Core SDK, I think we can add F# examples to the main solution
Gauthier Segay
@smoothdeveloper
Dec 21 2018 11:54 UTC
:+1: nice sample, I see loading from a theme assembly
more F# samples and references in the docs would be great, I'll see if I can come by with some PR if I can get going a little bit
work to bring FSI to .net core is also ongoing, so scripting samples should ultimately work xplatform
thanks a lot for your support!
Nikita Tsukanov
@kekekeks
Dec 21 2018 12:02 UTC
For FSI there might be issues with the main loop
Probably need some integration layer so we could control the main loop while letting the FSI to push continuations via Dispatcher.UIThread.InvokeAsync
Gauthier Segay
@smoothdeveloper
Dec 21 2018 12:03 UTC
> System.InvalidOperationException: Could not create IAssetLoader : maybe Application.RegisterServices() wasn't called?
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Uri uri, Uri baseUri, Object rootInstance)
   at Avalonia.Markup.Xaml.Styling.StyleInclude.get_Loaded()
   at Avalonia.Markup.Xaml.Styling.StyleInclude.Avalonia.Styling.ISetStyleParent.NotifyResourcesChanged(ResourcesChangedEventArgs e)
   at Avalonia.Styling.Styles.<.ctor>b__2_0(IStyle x)
   at Avalonia.Collections.AvaloniaListExtensions.<>c__DisplayClass0_0`1.<ForEachItem>b__0(Int32 _, T i)
   at Avalonia.Collections.AvaloniaListExtensions.<>c__DisplayClass1_0`1.<ForEachItem>g__Add|0(Int32 index, IList items)
   at Avalonia.Collections.AvaloniaListExtensions.<>c__DisplayClass1_0`1.<ForEachItem>b__2(Object _, NotifyCollectionChangedEventArgs e)
   at Avalonia.Collections.AvaloniaList`1.NotifyAdd(IList t, Int32 index)
   at Avalonia.Collections.AvaloniaList`1.Add(T item)
   at FSI_0005.Initialize@23.Invoke(String x) in ...
I need to register some service IAssetLoader
Nikita Tsukanov
@kekekeks
Dec 21 2018 12:04 UTC
It's usually registered by AppBuilder
Gauthier Segay
@smoothdeveloper
Dec 21 2018 12:04 UTC
@kekekeks I hope it can be worked around, maybe switch to another thread in FSI and sycnhronize the UI calls.
Nikita Tsukanov
@kekekeks
Dec 21 2018 12:05 UTC
Basically before doing anything you need to
AppBuilder.Configure<App>().UsePlatformDetect().SetupWithoutStarting()
They you could get application instance from AppBuilder returned from SetupWithoutStarting
And work from there
Gauthier Segay
@smoothdeveloper
Dec 21 2018 12:06 UTC
mmh:
type App() =
    inherit Application()
    override this.Initialize() = 
        let baseUri = Uri("resm:base")
        [
            "resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"
            "resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"
        ] |> List.iter (fun x -> this.Styles.Add(StyleInclude(baseUri, Source=Uri(x))))

let app =
  AppBuilder
    .Configure<App>()
    .UsePlatformDetect()
    .SetupWithoutStarting()
System.NotSupportedException: The invoked member is not supported in a dynamic assembly.
   at System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceNames()
   at Avalonia.Shared.PlatformSupport.AssetLoader.AssemblyDescriptor..ctor(Assembly assembly)
   at Avalonia.Shared.PlatformSupport.AssetLoader..ctor(Assembly assembly)
   at Avalonia.Shared.PlatformSupport.StandardRuntimePlatformServices.Register(Assembly assembly)
   at Avalonia.AppBuilder.<>c.<.ctor>b__0_0(AppBuilder builder)
   at Avalonia.Controls.AppBuilderBase`1.<>c__DisplayClass37_0.<.ctor>b__0()
   at Avalonia.Controls.AppBuilderBase`1.Setup()
   at Avalonia.Controls.AppBuilderBase`1.SetupWithoutStarting()
there is some emit code that currently doesn't work in FSI, I'll investigate with the F# team to see if there is a workaround for that
Nikita Tsukanov
@kekekeks
Dec 21 2018 12:34 UTC
It seems that our
Resource scan code isn't quite ready for dynamic assemblies
Nikita Tsukanov
@kekekeks
Dec 21 2018 12:43 UTC
Should be an easy fix though
Jonathan
@vanillajonathan
Dec 21 2018 12:56 UTC
Visual Studio XAML design previewer doesn't show any title bar or minimize, maximize, close buttons
Nikita Tsukanov
@kekekeks
Dec 21 2018 13:27 UTC
Works as intended
Will implement those when we'll get CSD support
Which is needed for several wayland compositors anyway
Jonathan
@vanillajonathan
Dec 21 2018 14:13 UTC
Oh, I can't put plaintext before or after bindings. Such as <TextBlock Text="Weight: {Binding Weight} kg" />
Nikita Tsukanov
@kekekeks
Dec 21 2018 14:18 UTC
Once new layout code is ready you'll be able to use text runs
The infrastructure for basic document model is here, it's just blocked by Skia backend for now
Jonathan
@vanillajonathan
Dec 21 2018 14:21 UTC
Also working with <Grid> is not pleasant. It seems I have to add a <RowDefinition> for every row.
ahopper
@ahopper
Dec 21 2018 14:26 UTC
@vanillajonathan you can use StringFormat to do what you want in bindings
Nikita Tsukanov
@kekekeks
Dec 21 2018 14:27 UTC
@vanillajonathan What layout are you trying to do?
Jonathan
@vanillajonathan
Dec 21 2018 14:36 UTC
@kekekeks One with 2 columns and 10 rows. I find myself having to repeat RowDefs which feels pretty tedious.
@ahopper Oh, you mean in the ViewModel? Because I don't know that String.Format is possible in the XAML.
Nikita Tsukanov
@kekekeks
Dec 21 2018 14:38 UTC
The usual way for doing such layouts is SharedSizeGroups
ahopper
@ahopper
Dec 21 2018 14:38 UTC
nope, it is a parameter in the binding
Jonathan
@vanillajonathan
Dec 21 2018 14:39 UTC
@ahopper Oh, I have no idea about this.
Nikita Tsukanov
@kekekeks
Dec 21 2018 14:39 UTC
I think {Binding Weight, StringFormat='Weight: {0} kg'}
Jonathan
@vanillajonathan
Dec 21 2018 14:45 UTC
Hmm, this doesn't seem to work
ahopper
@ahopper
Dec 21 2018 14:45 UTC
I don't think you need the 's
Jonathan
@vanillajonathan
Dec 21 2018 14:45 UTC
Yeah, I don't think so either. I removed them, but it still does not work.
ahopper
@ahopper
Dec 21 2018 14:50 UTC
not in font of any real code at the moment and I think this has changed in a recent portablexaml release but sometimes you prefix the format string with {} but I don't thing it should be needed in this case
Jonathan
@vanillajonathan
Dec 21 2018 14:52 UTC
Oh, maybe when Avalonia integrates System.Xaml things will be more compatible
ahopper
@ahopper
Dec 21 2018 14:54 UTC
StringFormat does work, I use it lots, just not in a position to find an example right now
in earlier versions you had to prefix { & } with \
ahopper
@ahopper
Dec 21 2018 14:59 UTC
Text="{Binding txGain, StringFormat=tx rf gain \{0\}}"
Jonathan
@vanillajonathan
Dec 21 2018 15:01 UTC
Ah, yes this works! Visual Studio didn't warn me about unescaped { and }.
On each TextBlock i have to explicitly set Grid.Row and Grid.Column, this not so pleasant to work with. It doesn't auto-arrange like flexbox in HTML5.
Nikita Tsukanov
@kekekeks
Dec 21 2018 15:05 UTC
You can have multiple controls in the same grid cell
That's why it doesn't auto-set these properties
Jonathan
@vanillajonathan
Dec 21 2018 15:07 UTC
Oh, that sounds weird...
Nikita Tsukanov
@kekekeks
Dec 21 2018 15:07 UTC
Commonly used for setting background control
I think we could port AutoGrid
Jonathan
@vanillajonathan
Dec 21 2018 15:21 UTC
Yeah, that one looks much more easy to use and less obtuse.
Benedikt Stebner
@Gillibald
Dec 21 2018 15:50 UTC
Trying to "finish" the skia text layout this year. This also will support inlines etc. Just need to figure out how to hack in the missing HarfBuzz bits. Probably have to maintain the HarfBuzzSharp implementation myself in the future to get features in faster. Color fonts will only work with Skia. In general the skia text layout should behave similar to the direct write layout.
Steven Kirk
@grokys
Dec 21 2018 16:19 UTC
nice one @Gillibald -- really looking forward to being able to get inlines merged!
btw, i've started work on an MVVM tutorial: AvaloniaUI/avaloniaui.net#38
i wrote the tutorial after the demo app, so i may have missed some steps
but i wanted to get the tutorial finished and then i'll run through the steps
however if anyone else wants to run through it and point out what's missing/wrong, that would be great too ;)
Nikita Tsukanov
@kekekeks
Dec 21 2018 16:29 UTC
@Gillibald You can P/Invoke AddUtf8
You only need __Internal and libHarfBuzzSharp DllImport variants
They have to be chosen at runtime though
@grokys I've sent a email to https://wpf-tutorial.com/ guys asking if we could use their content as a base
Benedikt Stebner
@Gillibald
Dec 21 2018 16:46 UTC
@kekekeks Thanks will have a look
Benedikt Stebner
@Gillibald
Dec 21 2018 17:08 UTC
Too bad HarfBuzzApi is internal. Just starting with the Windows version to make sure it solves my issues.
Nikita Tsukanov
@kekekeks
Dec 21 2018 17:15 UTC
Just copy-paste
[DllImport(HARFBUZZ, CallingConvention = CallingConvention.Cdecl)]
        public extern static void hb_buffer_add_utf16(hb_buffer_t buffer, byte[] text, int text_length, uint item_offset, int item_length);
And replace HARFBUZZ with libHarfBuzzSharp
Benedikt Stebner
@Gillibald
Dec 21 2018 17:20 UTC
Do we have to avoid Reflection.Emit for this? Calling this with the help of DynamicMethod should work on all platforms except IOS or am I wrong?
Nikita Tsukanov
@kekekeks
Dec 21 2018 17:23 UTC
Just have two P/Invokes
One for iOS, another for everything else
And select at runtime
Meanwhile send a PR to SkiaSharp
That would be faster than just waiting for the fix
Benedikt Stebner
@Gillibald
Dec 21 2018 17:54 UTC
I am just not familiar with the SkiaSharp project. If I don't need to touch the native dependencies it should be easy to implement this feature myself.
Nikita Tsukanov
@kekekeks
Dec 21 2018 17:55 UTC
It doesn't have custom native code for harfbuzz
Since harfbuzz has C API
So you can rebuild only the managed part
Doesn't seem to work like expected
Rectangles have zero height
Benedikt Stebner
@Gillibald
Dec 21 2018 20:50 UTC
Y there is some issue with the measurement cache.
There are some other related issues
Nikita Tsukanov
@kekekeks
Dec 21 2018 20:55 UTC
We need to import grid from WPF, I guess
ahopper
@ahopper
Dec 21 2018 21:04 UTC
@kekekeks #2185 is working very nicely here :+1:
Nikita Tsukanov
@kekekeks
Dec 21 2018 21:09 UTC
Good
Still need to add support for opaque visuals before merging
@vanillajonathan Ported WpfAutoGrid - https://github.com/AvaloniaUI/AvaloniaAutoGrid
But it depends on #2190