Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Sep 23, 2021
1 parent 99610a7 commit 694e460
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 88 deletions.
90 changes: 46 additions & 44 deletions Views/Grid.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -363,50 +363,52 @@ type Grid() as this =

// gui widgets
let placements = getGuiWidgetPlacements vm.BufNr
for ({ns = ns; mark = mark}, cell, {trow=r;tcol=c}) in vm.Extmarks.Values do
// if cell.marks does not have this mark, it means cell has scrolled out of view.
if not (ns = guiwidgetNamespace && cell.ContainsMark mark) then () else
match (placements.TryGetValue mark) with
| false, _ -> ()
| true, ({widget=wid; w=grid_w; h=grid_h} as p) ->
let hideAttr = p.GetHideAttr()
let singleLine = grid_h = 1
let lineOverlap = vm.CursorInfo.row |> (r <<-> r+grid_h)
let colOverlap = vm.CursorInfo.col |> (c <<-> c+grid_w)
let hide = match hideAttr with
| CursorOverlap -> lineOverlap && colOverlap
| CursorLineOverlap -> lineOverlap
| _ -> false
if hide then () else
let r, c, w, h = float r * gh, float c * gw, float grid_w * gw, float grid_h * gh
let bounds = Rect(vm_x + c, vm_y + r, w, h)
use _clip = ctx.PushClip(bounds)
let widget = getGuiWidget wid
match widget with
| BitmapWidget img ->
let src, dst = p.GetDrawingBounds img.Size bounds
ctx.DrawImage(img, src, dst)
| VectorImageWidget (img) ->
let src, dst = p.GetDrawingBounds (Size(img.Width,img.Height)) bounds
let themed, svg_fg, svg_bg =
p.GetSvgAttr(hideAttr, lineOverlap, colOverlap, singleLine)
if themed then
m_gadget_brush.Color <- svg_bg
ctx.FillRectangle(m_gadget_brush, bounds)
let scaleMatrix = Matrix.CreateScale(dst.Width / src.Width, dst.Height / src.Height)
let translateMatrix = Matrix.CreateTranslation(dst.Left, dst.Top)
use _tr = ctx.PushPreTransform(scaleMatrix * translateMatrix)
if themed then
img.SetTheme(m_gadget_brush, svg_fg, svg_bg)
img.Draw(ctx)
| PlainTextWidget(text) ->
let fg, bg, font, size = p.GetTextAttr()
m_gadget_brush.Color <- bg
ctx.FillRectangle(m_gadget_brush, bounds)
m_gadget_brush.Color <- fg
let text = FormattedText(text, font, size, TextAlignment.Left, TextWrapping.Wrap, bounds.Size)
ctx.DrawText(m_gadget_brush, bounds.TopLeft, text)
| _ -> ()
let drawGuiWidgets ({ns = ns; mark = mark}, cell: GridBufferCell, {trow=r;tcol=c}) =
// if cell.marks does not have this mark, it means cell has scrolled out of view.
if ns = guiwidgetNamespace && cell.ContainsMark mark then
match (placements.TryGetValue mark) with
| false, _ -> ()
| true, ({widget=wid; w=grid_w; h=grid_h} as p) ->
let hideAttr = p.GetHideAttr()
let singleLine = grid_h = 1
let lineOverlap = vm.CursorInfo.row |> (r <<-> r+grid_h)
let colOverlap = vm.CursorInfo.col |> (c <<-> c+grid_w)
let hide = match hideAttr with
| CursorOverlap -> lineOverlap && colOverlap
| CursorLineOverlap -> lineOverlap
| _ -> false
if hide then () else
let r, c, w, h = float r * gh, float c * gw, float grid_w * gw, float grid_h * gh
let bounds = Rect(vm_x + c, vm_y + r, w, h)
use _clip = ctx.PushClip(bounds)
let widget = getGuiWidget wid
match widget with
| BitmapWidget img ->
let src, dst = p.GetDrawingBounds img.Size bounds
ctx.DrawImage(img, src, dst)
| VectorImageWidget (img) ->
let src, dst = p.GetDrawingBounds (Size(img.Width,img.Height)) bounds
let themed, svg_fg, svg_bg =
p.GetSvgAttr(hideAttr, lineOverlap, colOverlap, singleLine)
if themed then
m_gadget_brush.Color <- svg_bg
ctx.FillRectangle(m_gadget_brush, bounds)
let scaleMatrix = Matrix.CreateScale(dst.Width / src.Width, dst.Height / src.Height)
let translateMatrix = Matrix.CreateTranslation(dst.Left, dst.Top)
use _tr = ctx.PushPreTransform(scaleMatrix * translateMatrix)
if themed then
img.SetTheme(m_gadget_brush, svg_fg, svg_bg)
img.Draw(ctx)
| PlainTextWidget(text) ->
let fg, bg, font, size = p.GetTextAttr()
m_gadget_brush.Color <- bg
ctx.FillRectangle(m_gadget_brush, bounds)
m_gadget_brush.Color <- fg
let text = FormattedText(text, font, size, TextAlignment.Left, TextWrapping.Wrap, bounds.Size)
ctx.DrawText(m_gadget_brush, bounds.TopLeft, text)
| _ -> ()
for tup in vm.Extmarks.Values do
drawGuiWidgets tup

// scrollbar
// todo mouse over opacity adjustment
Expand Down
44 changes: 0 additions & 44 deletions fvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,50 +74,6 @@ function! s:fvim_on_vim_enter()
call rpcnotify(g:fvim_channel, 'OnInitComplete')
endfunction

lua <<EOF
fvim_test_gui = function()
local gui = require('gui-widgets')
local w1 = gui.put_file("F:/test/push_1.png","image/png")
local w2 = gui.put_file("F:/test/push_2.png","image/png")
gui.place(w1, 0, 0, 0, 8, 2, {
['clicked-widget']=w2;
['clicked-exec']='silent call VsimToggleColor()';
['released-widget']=w1;
['halign']='center';
['valign']='center';
['stretch']='uniform';
['hide']='cursor';
})

local w3 = gui.put_data("Hello Text","text/plain")
gui.place(w3, 0, 2, 0, 20, 2, {
['text-font']='Arial';
['text-scale']=2;
['text-hlid']='Normal';
['hide']='cursorline';
})

local w4 = gui.put_file("F:/test/5.svg", "image/svg")
gui.place(w4, 0, 4, 0, 8, 2, {
['halign']='center';
['valign']='center';
['stretch']='uniform';
['hide']='cursor';
['svg-themed']=true;
})

local w5 = gui.put_file("F:/test/7.svg", "image/svg")
gui.place(w5, 0, 6, 0, 8, 1, {
['halign']='center';
['valign']='center';
['stretch']='uniform';
['hide']='cursor';
['svg-themed']=true;
})
gui.update_view(0)
end
EOF

augroup FVim
autocmd BufWinEnter * call s:fvim_on_bufwinenter()
autocmd WinEnter * call s:fvim_on_winenter()
Expand Down

0 comments on commit 694e460

Please sign in to comment.