Skip to content

Commit

Permalink
single cursor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Nov 2, 2020
1 parent 97881d3 commit ce22e9e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"profiles": {
"fvim": {
"commandName": "Project"
"commandName": "Project",
"commandLineArgs": "--debug-multigrid"
},
"norc": {
"commandName": "Project",
Expand Down
4 changes: 2 additions & 2 deletions ViewModels/CursorViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ open ReactiveUI
open FVim.def
open FVim.common.helpers

type CursorViewModel(cursorMode: int option) =
type CursorViewModel(cursorMode: int option, isRootCursor: bool) =
inherit ViewModelBase(None, None, Some 1.0, Some 1.0)

member val enabled: bool = true with get,set
member val ingrid: bool = false with get,set
member val row: int = 0 with get,set
member val col: int = 0 with get,set
member val modeidx: int = _d -1 cursorMode with get,set
Expand All @@ -28,6 +27,7 @@ type CursorViewModel(cursorMode: int option) =
member val blinkoff: int = 0 with get,set
member val blinkwait: int = 0 with get,set
member val cellPercentage: int = 100 with get,set
member val IsRootCursor:bool = isRootCursor with get
member val shape: CursorShape = CursorShape.Block with get,set

member this.Clone() =
Expand Down
71 changes: 41 additions & 30 deletions ViewModels/EditorViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type EditorViewModel(_gridid: int, ?parent: EditorViewModel, ?_gridsize: GridSiz
?_cursormode: int, ?_anchorX: float, ?_anchorY: float) as this =
inherit ViewModelBase(_anchorX, _anchorY, _measuredsize)

let m_cursor_vm = new CursorViewModel(_cursormode)
let m_cursor_vm = new CursorViewModel(_cursormode, parent.IsNone)
let m_popupmenu_vm = new PopupMenuViewModel()
let m_child_grids = ObservableCollection<IGridUI>()
let m_resize_ev = Event<IGridUI>()
Expand Down Expand Up @@ -86,30 +86,35 @@ type EditorViewModel(_gridid: int, ?parent: EditorViewModel, ?_gridsize: GridSiz
// do not use the default colors for cursor
let colorf = if hlid = 0 then GetReverseColor else id
let fg, bg, sp = colorf fg, colorf bg, colorf sp
let chksum = m_cursor_vm.VisualChecksum()
m_cursor_vm.typeface <- theme.guifont
m_cursor_vm.wtypeface <- theme.guifontwide
m_cursor_vm.fontSize <- m_fontsize
m_cursor_vm.text <- text
m_cursor_vm.fg <- fg
m_cursor_vm.bg <- bg
m_cursor_vm.sp <- sp
m_cursor_vm.underline <- attrs.underline
m_cursor_vm.undercurl <- attrs.undercurl
m_cursor_vm.bold <- attrs.bold
m_cursor_vm.italic <- attrs.italic
m_cursor_vm.cellPercentage <- Option.defaultValue 100 mode.cell_percentage
m_cursor_vm.blinkon <- on
m_cursor_vm.blinkoff <- off
m_cursor_vm.blinkwait <- wait
m_cursor_vm.shape <- Option.defaultValue CursorShape.Block mode.cursor_shape
m_cursor_vm.X <- origin.X
m_cursor_vm.Y <- origin.Y
m_cursor_vm.Width <- width
m_cursor_vm.Height <- m_glyphsize.Height
if chksum <> m_cursor_vm.VisualChecksum() then
m_cursor_vm.RenderTick <- m_cursor_vm.RenderTick + 1
trace _gridid "set cursor info, color = %A %A %A" fg bg sp

if _gridid = 1 && States.ui_multigrid then () else

this.DoWithRootCursorVM((fun cursor_vm x y ->
let chksum = m_cursor_vm.VisualChecksum()
cursor_vm.typeface <- theme.guifont
cursor_vm.wtypeface <- theme.guifontwide
cursor_vm.fontSize <- m_fontsize
cursor_vm.text <- text
cursor_vm.fg <- fg
cursor_vm.bg <- bg
cursor_vm.sp <- sp
cursor_vm.underline <- attrs.underline
cursor_vm.undercurl <- attrs.undercurl
cursor_vm.bold <- attrs.bold
cursor_vm.italic <- attrs.italic
cursor_vm.cellPercentage <- Option.defaultValue 100 mode.cell_percentage
cursor_vm.blinkon <- on
cursor_vm.blinkoff <- off
cursor_vm.blinkwait <- wait
cursor_vm.shape <- Option.defaultValue CursorShape.Block mode.cursor_shape
cursor_vm.X <- x
cursor_vm.Y <- y
cursor_vm.Width <- width
cursor_vm.Height <- m_glyphsize.Height
if chksum <> m_cursor_vm.VisualChecksum() then
cursor_vm.RenderTick <- cursor_vm.RenderTick + 1
trace _gridid "set cursor info, color = %A %A %A" fg bg sp
), origin.X, origin.Y)

let clearBuffer preserveContent =
let oldgrid = m_gridbuffer
Expand Down Expand Up @@ -187,11 +192,10 @@ type EditorViewModel(_gridid: int, ?parent: EditorViewModel, ?_gridsize: GridSiz
putBuffer line

let cursorGoto id row col =
m_cursor_vm.ingrid <- (id = _gridid)
if id = _gridid then
m_cursor_vm.row <- row
m_cursor_vm.col <- col
cursorConfig()
cursorConfig()

let changeMode (name: string) (index: int) =
m_cursor_vm.modeidx <- index
Expand Down Expand Up @@ -420,14 +424,16 @@ type EditorViewModel(_gridid: int, ?parent: EditorViewModel, ?_gridsize: GridSiz

theme.cursoren_ev.Publish
|> Observable.subscribe (fun en ->
if m_cursor_vm.ingrid then
if m_cursor_vm.IsRootCursor then
setCursorEnabled en)

States.Register.Watch "font" fontConfig

this.ObservableForProperty(fun x -> x.IsFocused)
|> Observable.subscribe (fun x ->
trace _gridid "focus state changed: %A" x.Value)
trace _gridid "focus state changed: %A" x.Value
if x.Value then cursorConfig()
)
]

interface IGridUI with
Expand Down Expand Up @@ -461,7 +467,7 @@ type EditorViewModel(_gridid: int, ?parent: EditorViewModel, ?_gridsize: GridSiz
member __.GetPoint row col =
Point(double(col) * m_glyphsize.Width, double(row) * m_glyphsize.Height)

member this.SetMeasuredSize (v: Size) =
member __.SetMeasuredSize (v: Size) =
trace _gridid "set measured size: %A" v
let gridui = this :> IGridUI
let gw, gh = gridui.GridWidth, gridui.GridHeight
Expand All @@ -472,6 +478,11 @@ type EditorViewModel(_gridid: int, ?parent: EditorViewModel, ?_gridsize: GridSiz
if this.IsTopLevel then
m_resize_ev.Trigger(this)

member __.DoWithRootCursorVM (fn: CursorViewModel -> float -> float -> unit, x: float, y: float) =
match parent with
| Some p -> p.DoWithRootCursorVM(fn, x + this.X, y + this.Y)
| None -> fn m_cursor_vm x y

(******************* Exposed properties ***********************)

member __.Item with get(row, col) = m_gridbuffer.[row, col]
Expand Down
4 changes: 2 additions & 2 deletions Views/Cursor.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Cursor() as this =
let mutable sp = Colors.Red

let mutable cursor_fb = AllocateFramebuffer (20.0) (20.0) 1.0
let mutable cursor_fb_vm = CursorViewModel(Some -1)
let mutable cursor_fb_vm = CursorViewModel(Some -1, true)
let mutable cursor_fb_s = 1.0

let ensure_fb() =
Expand Down Expand Up @@ -61,7 +61,7 @@ type Cursor() as this =

let showCursor (v: bool) =
let opacity =
if (v && this.ViewModel.enabled && this.ViewModel.ingrid)
if (v && this.ViewModel.enabled)
|| not this.IsActive // don't blink if inactive
then 1.0
else 0.0
Expand Down
4 changes: 3 additions & 1 deletion Views/Editor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
DataContext = "{Binding CursorInfo}"
Height = "{Binding Height, Mode=OneWay}"
Width = "{Binding Width, Mode=OneWay}"
IsVisible = "{Binding IsRootCursor}"
IsActive = "{Binding $parent[Window].IsActive, Mode=OneWay}"
HorizontalAlignment = "Left"
VerticalAlignment = "Top"
Focusable = "False"
IsActive = "{Binding $parent[Window].IsActive, Mode=OneWay}"
ZIndex = "10"
>
</fvim:Cursor>

Expand Down

0 comments on commit ce22e9e

Please sign in to comment.