Post Reply 
 
Thread Rating:
  • 9 Votes - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ScrollBox間のスクロール連動
05-09-2017, 01:20 PM
Post: #1
ScrollBox間のスクロール連動
複数のScrollBoxでスクロール動作を連動したいと思っています。
スクロール時のEventを拾ってテストコードの動作までは確認できたのですが、
スクロールバーをドラッグしている間の連動が実現できておりません。
何か良い方法があればご教示願います。

Code:
{curl 8.0 applet}
{curl-file-attributes character-encoding = "shift-jis"}

{def vb1 = {VBox}}
{def sb1 = {ScrollBox width = 100px, height = 100px, vb1}}
{def vb2 = {VBox}}
{def sb2 = {ScrollBox width = 100px, height = 100px, vb2}}

{def make-ev1 =
    {proc {arg-sb:ScrollBox}:EventHandler
        {return
            {on PointerScroll at sb:ScrollBox do
                {after 0s do
                    {arg-sb.scroll-to x = sb.horizontal-position, y = sb.vertical-position}
                }
            }
        }
    }
}

{def make-ev2 =
    {proc {arg-sb:ScrollBox}:EventHandler
        {return
            {on pee:PointerEnvelopeEvent at sb:ScrollBox do
                {if pee.contents isa PointerMotion then
                    {after 0s do
                        {arg-sb.scroll-to x = sb.horizontal-position, y = sb.vertical-position}
                    }
                }
            }
        }
    }
}

{sb1.add-event-handler {make-ev1 sb2}}
{sb1.add-event-handler {make-ev2 sb2}}
{sb2.add-event-handler {make-ev1 sb1}}
{sb2.add-event-handler {make-ev2 sb1}}

{for i:int = 1 to 20 do
    {vb1.add {Label i  & "行目"}}
    {vb2.add {Label i  & "行目"}}
}

{View
    {HBox
        sb1,
        sb2
    },
    visibility = "normal",
    {on WindowClose do
        {exit}
    }
}
Find all posts by this user
Quote this message in a reply
05-10-2017, 11:35 AM
Post: #2
RE: ScrollBox間のスクロール連動
ScrollBarを使えば、実現可能かと思います。
下記サンプルをご参考にしてみてください。

Code:
{curl 8.0 applet}
{curl-file-attributes character-encoding = "utf8"}

{define-proc {sync-scroll src:ScrollBox, obj:ScrollBox}:void
    {def src-vbar = {src.get-vscroll}}
    {def src-hbar = {src.get-hscroll}}

    {def obj-vbar = {obj.get-vscroll}}
    {def obj-hbar = {obj.get-hscroll}}
||--    {output vsbar2}
||--    {output hsbar2}

    {src-vbar.add-event-handler
        {on e:Adjustment do
            {obj-vbar.set-scroll-value {src-vbar.get-scroll-value}}
        }
    }

    {src-hbar.add-event-handler
        {on e:Adjustment do
            {obj-hbar.set-scroll-value {src-hbar.get-scroll-value}}
        }
    }
}

{def vb1 = {VBox}}
{def sb1 = {ScrollBox width = 100px, height = 100px, vb1}}
{def vb2 = {VBox}}
{def sb2 = {ScrollBox width = 100px, height = 100px, vb2}}

||--{def make-ev1 =
||--    {proc {arg-sb:ScrollBox}:EventHandler
||--        {return
||--            {on PointerScroll at sb:ScrollBox do
||--                {after 0s do
||--                    {arg-sb.scroll-to x = sb.horizontal-position, y = sb.vertical-position}
||--                }
||--            }
||--        }
||--    }
||--}
||--
||--{def make-ev2 =
||--    {proc {arg-sb:ScrollBox}:EventHandler
||--        {return
||--            {on pee:PointerEnvelopeEvent at sb:ScrollBox do
||--                {if pee.contents isa PointerMotion then
||--                    {after 0s do
||--                        {arg-sb.scroll-to x = sb.horizontal-position, y = sb.vertical-position}
||--                    }
||--                }
||--            }
||--        }
||--    }
||--}
||--
||--{sb1.add-event-handler {make-ev1 sb2}}
||--{sb1.add-event-handler {make-ev2 sb2}}
||--{sb2.add-event-handler {make-ev1 sb1}}
||--{sb2.add-event-handler {make-ev2 sb1}}

{for i:int = 1 to 20 do
    {vb1.add {Label i  & "行目"}}
    {vb2.add {Label i  & "行目"}}
}

{sync-scroll sb1, sb2}

{View
    {HBox
        sb1,
        sb2
    },
    visibility = "normal",
    {on WindowClose do
        {exit}
    }
}
Find all posts by this user
Quote this message in a reply
05-10-2017, 01:31 PM
Post: #3
RE: ScrollBox間のスクロール連動
>tdeng様
ご教示いただきありがとうございます。
こちらのソースを参考にし、期待通りの動作をすることを確認できました。
Find all posts by this user
Quote this message in a reply
Post Reply 

Forum Jump:


User(s) browsing this thread:
1 Guest(s)