Curl Global Community
ScrollBox間のスクロール連動 - Printable Version

+- Curl Global Community (https://communities.curl.com)
+-- Forum: Discussions (https://communities.curl.com/forumdisplay.php?fid=1)
+--- Forum: General Curl questions (https://communities.curl.com/forumdisplay.php?fid=2)
+--- Thread: ScrollBox間のスクロール連動 (/showthread.php?tid=1453)



ScrollBox間のスクロール連動 - Yudai-s - 05-09-2017

複数の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}
    }
}



RE: ScrollBox間のスクロール連動 - tdeng - 05-10-2017

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}
    }
}



RE: ScrollBox間のスクロール連動 - Yudai-s - 05-10-2017

>tdeng様
ご教示いただきありがとうございます。
こちらのソースを参考にし、期待通りの動作をすることを確認できました。