Skip to content

Commit

Permalink
workaround: invalidate root editor directly if it is found
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Mar 21, 2020
1 parent 3540ecc commit b154733
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
7 changes: 1 addition & 6 deletions Views/Cursor.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Cursor() as this =
let mutable cursor_fb = AllocateFramebuffer (20.0) (20.0) 1.0
let mutable cursor_fb_vm = CursorViewModel(Some -1)
let mutable cursor_fb_s = 1.0
let mutable render_queued = false

let ensure_fb() =
let s = this.GetVisualRoot().RenderScaling
Expand Down Expand Up @@ -91,9 +90,7 @@ type Cursor() as this =
(* reconfigure the cursor *)
showCursor true
cursorTimerRun blinkon this.ViewModel.blinkwait
if not render_queued then
render_queued <- true
this.InvalidateVisual()
this.InvalidateVisual()

let setCursorAnimation() =
let transitions = Transitions()
Expand Down Expand Up @@ -181,5 +178,3 @@ type Cursor() as this =
let region = Rect(0.0, 0.0, cellw p, this.Height)
ctx.FillRectangle(SolidColorBrush(this.ViewModel.bg), region)

render_queued <- false

9 changes: 9 additions & 0 deletions Views/Editor.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Editor() as this =

static let ViewModelProperty = AvaloniaProperty.Register<Editor, EditorViewModel>("ViewModel")
static let GridIdProperty = AvaloniaProperty.Register<Editor, int>("GridId")
static let RenderTickProperty = AvaloniaProperty.Register<Editor, int>("RenderTick")

let mutable grid_fb: RenderTargetBitmap = null
let mutable grid_scale: float = 1.0
Expand Down Expand Up @@ -181,6 +182,10 @@ type Editor() as this =
Model.OnGridReady(vm :> IGridUI)
ignore <| Dispatcher.UIThread.InvokeAsync(this.Focus))

this.GetObservable(RenderTickProperty).Subscribe(fun id ->
trace grid_vm "render tick %d" id
this.InvalidateVisual())

vm.ChildGrids.CollectionChanged.Subscribe(fun changes ->
match changes.Action with
| NotifyCollectionChangedAction.Add ->
Expand Down Expand Up @@ -318,4 +323,8 @@ type Editor() as this =
with get () = this.GetValue(GridIdProperty)
and set (v: int) = this.SetValue(GridIdProperty, v)

member this.RenderTick
with get() = this.GetValue(RenderTickProperty)
and set(v) = this.SetValue(RenderTickProperty, v)

static member GetGridIdProp() = GridIdProperty
2 changes: 1 addition & 1 deletion Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Opacity = "{Binding BackgroundImageOpacity}"
/>

<fvim:Editor Grid.Row="1" Grid.Column="1" DataContext="{Binding MainGrid}" GridId="{Binding GridId}" />
<fvim:Editor Grid.Row="1" Grid.Column="1" DataContext="{Binding MainGrid}" GridId="{Binding GridId}" Name="RootEditor" />
<Panel Name="LeftBorder" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" IsVisible="{Binding CustomTitleBar}" Background="{Binding NormalBackground}" />
<Panel Name="RightBorder" Grid.Row="0" Grid.RowSpan="3" Grid.Column="2" IsVisible="{Binding CustomTitleBar}" Background="{Binding NormalBackground}" />
<Panel Name="BottomBorder" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" IsVisible="{Binding CustomTitleBar}" Background="{Binding NormalBackground}" />
Expand Down
15 changes: 8 additions & 7 deletions Views/MainWindow.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open Avalonia.ReactiveUI
open System.Runtime.InteropServices
open Avalonia.Rendering
open Avalonia.Interactivity
open Avalonia.VisualTree

#nowarn "0025"

Expand Down Expand Up @@ -120,12 +121,12 @@ type MainWindow() as this =
DragDrop.SetAllowDrop(this, true)
configBackground()

let flushop =
if RuntimeInformation.IsOSPlatform(OSPlatform.Linux) then
fun () ->
let editor: Avalonia.VisualTree.IVisual = this.GetEditor()
editor.InvalidateVisual()
else this.InvalidateVisual
let flushop () =
let editor: IControl = this.GetEditor()
if editor <> null then
editor.InvalidateVisual()
else
this.InvalidateVisual()

this.Watch [
this.Closing.Subscribe (fun e -> Model.OnTerminating e)
Expand Down Expand Up @@ -185,7 +186,7 @@ type MainWindow() as this =
m_bottom_border <- this.FindControl<Panel>("BottomBorder")

member this.GetEditor() =
this.LogicalChildren.[0] :?> Avalonia.VisualTree.IVisual
this.FindControl("RootEditor")

override this.OnDataContextChanged _ =
let ctx = this.DataContext :?> MainWindowViewModel
Expand Down

0 comments on commit b154733

Please sign in to comment.