Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Designer visual studio doesn't work #142

Open
tomlm opened this issue Nov 9, 2024 · 4 comments
Open

Visual Designer visual studio doesn't work #142

tomlm opened this issue Nov 9, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@tomlm
Copy link
Collaborator

tomlm commented Nov 9, 2024

I was poking around this and made some interesting discoveries.

The way the designer renders the preview window is it has an out of process app which binds to the projects AppBuilder to instantiate the environment and then it renders the control inside of that.

The problem is that out of process host app is not a console app, and so all console APIs blow up. And even it were a console app it's looking for a bitmap to send back to the preview page.

BUT I managed to get it working sort of by doing this:

  1. in program.cs I create an AppBuilder property
  2. in UseConsolonia I use Designer.IsDesignMode to return a standard Avalonia.Desktop AppBuilder with a #ifdef DEBUG around it
  3. I add conditional nuget package references to Avalonia.Desktop environment so they are only included on DEBUG builds
  4. I add designer attributes to control
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100"

it displays a preview (although completely illegible)!

Issues I had:

  • I had to add FontFamily FontSize Foreground and Background to render anything which didn't have that on it. (The colors panel actually previewed the best because it has explicit colors
  • The size of the image that is created is literally 100x100 pixels so I had to zoom to 800% to see anything.

I think this approach might work, but I think we need some combination of styling and scaling to make it work.

There are some alternative approaches that might be possible as well, but it would be more complicated

  • create an IConsole which paints onto an Avalonia canvas?
  • Somehow hack the host process to take snapshot of console window?

I don't know...but I thought I'd record what I figured out for whenever/whomever tries to tackle this.

@tomlm tomlm added the enhancement New feature or request label Nov 9, 2024
@jinek
Copy link
Owner

jinek commented Nov 11, 2024

May be we need own plugins for VS and Rider to run a proper out of process terminal and capture the window render. Just first thought.
IConsole which draws to canvas is little hacky but could work. Any mono font would work for it, but we have stuff like special characters, we would need to write own terminal emulator basically.
By the way, theoretically, do we have an option to render some terminal emulator into a bitmap? May be we already have some existing cross-platform emulator which can do this?

@tomlm
Copy link
Collaborator Author

tomlm commented Nov 11, 2024

Yeah, I'm pursuing that route right now. I can capture the console output as VT100 codes, as raw char buffer or as a bmp.

branch tomlm/preview is where I'm working. I'm trying to get a previewer working as Consolonia app, then I will try binding that to via one of the means to the avalonia preview

@tomlm
Copy link
Collaborator Author

tomlm commented Nov 12, 2024

Making progress, I think it's going to work!

@tomlm
Copy link
Collaborator Author

tomlm commented Nov 12, 2024

image

That's rendered by launching the console app in the background and pulling over the PixelBuffer to the avalonia side and rendering it in graphics there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants