PreviousUpNext

15.4.1500  src/lib/x-kit/widget/old/layout/widget-with-scrollbars.pkg

## widget-with-scrollbars.pkg
#
# Wrapper for putting scrollbars around a widget.

# Compare with:
#     scrolled_widget, designed to be easier to use but less flexible:
#         src/lib/x-kit/widget/old/layout/scrolled-widget.pkg
#
# See also:
#     viewport, which provides a window onto a larger widget,
#     typically panned using scrollbars:
#         src/lib/x-kit/widget/old/layout/viewport.pkg

# Compiled by:
#     src/lib/x-kit/widget/xkit-widget.sublib






###             "When you draw a nude, sketch the whole figure
###              and nicely fit the members to it and to each other.
###
###              Even though you may only finish one portion of the drawing,
###              just make certain that all the parts hang together,
###              so that the study will be useful to you in the future."
###
###                                    -- Leonardo da Vinci


stipulate
    include package   threadkit;                                                # threadkit                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    package low =  line_of_widgets;                                             # line_of_widgets               is from   src/lib/x-kit/widget/old/layout/line-of-widgets.pkg
    package wg  =  widget;                                                      # widget                        is from   src/lib/x-kit/widget/old/basic/widget.pkg
herein

    package   widget_with_scrollbars
    : (weak)  Widget_With_Scrollbars                                            # Widget_With_Scrollbars        is from   src/lib/x-kit/widget/old/layout/widget-with-scrollbars.api
    {
        Hsb_Desc =   {   scrollbar: wg::Widget,   pad: Int,   top:  Bool   };
        Vsb_Desc =   {   scrollbar: wg::Widget,   pad: Int,   left: Bool   };

        fun fix_glue pad
            =
            low::SPACER { min_size=>pad, best_size=>pad, max_size=>THE pad };


        fun make_widget_with_scrollbars  root_window  { scrolled_widget, horizontal_scrollbar=>NULL, vertical_scrollbar=>NULL }
                =>
                low::make_line_of_widgets root_window (low::WIDGET scrolled_widget);

            make_widget_with_scrollbars  root_window  { scrolled_widget, horizontal_scrollbar=> THE (hdesc:  Hsb_Desc), vertical_scrollbar=>NULL }
                =>
                {   screen = wg::screen_of root_window;

                    hdesc ->  { scrollbar, pad, top };

                    case (top, pad)   
                        #
                        (TRUE, 0) => low::make_line_of_widgets root_window 
                           (low::VT_CENTER [low::WIDGET scrollbar, low::WIDGET scrolled_widget]);

                        (FALSE, 0) => low::make_line_of_widgets root_window
                           (low::VT_CENTER [low::WIDGET scrolled_widget, low::WIDGET scrollbar]);

                        (TRUE, pad) => low::make_line_of_widgets root_window
                           (low::VT_CENTER [
                              low::WIDGET scrollbar,
                              fix_glue pad,
                              low::WIDGET scrolled_widget
                           ]);

                        (FALSE, pad) => low::make_line_of_widgets root_window
                           (low::VT_CENTER [
                              low::WIDGET scrolled_widget,
                              fix_glue pad,
                              low::WIDGET scrollbar
                           ]);
                    esac;
                };

            make_widget_with_scrollbars  root_window  { scrolled_widget, vertical_scrollbar => THE (vdesc:  Vsb_Desc), horizontal_scrollbar=>NULL }
                =>
                {   screen = wg::screen_of  root_window;

                    vdesc ->  { scrollbar, left, pad };

                    case (left, pad)   
                        #
                        (TRUE,    0) => low::make_line_of_widgets  root_window 
                                            (low::HZ_CENTER [low::WIDGET scrollbar, low::WIDGET scrolled_widget]);

                        (FALSE,   0) => low::make_line_of_widgets  root_window
                                            (low::HZ_CENTER [low::WIDGET scrolled_widget, low::WIDGET scrollbar]);

                        (TRUE,  pad) => low::make_line_of_widgets  root_window
                                            (low::HZ_CENTER [
                                               low::WIDGET scrollbar,
                                               fix_glue pad,
                                               low::WIDGET scrolled_widget
                                            ]);

                        (FALSE, pad) => low::make_line_of_widgets  root_window
                                            (low::HZ_CENTER [
                                               low::WIDGET scrolled_widget,
                                               fix_glue pad,
                                               low::WIDGET scrollbar
                                            ]);
                    esac;
                };

            make_widget_with_scrollbars  root_window  { scrolled_widget, horizontal_scrollbar => THE hdesc, vertical_scrollbar => THE vdesc }
                =>
                {   screen =  wg::screen_of  root_window;

                    hpad = hdesc.pad;   hsb  = hdesc.scrollbar;
                    vpad = vdesc.pad;   vsb  = vdesc.scrollbar;

                    my { col_preference, ... }
                        =
                        wg::size_preference_of  vsb;

                    vsz = wg::preferred_length  col_preference;


                    case (hdesc.top, vdesc.left)   
                        #
                        (TRUE, TRUE) => low::make_line_of_widgets  root_window 
                                            (low::VT_CENTER [
                                               low::HZ_CENTER [
                                                 fix_glue (vsz+vpad),
                                                 low::WIDGET hsb 
                                               ],
                                               fix_glue hpad,
                                               low::HZ_CENTER [
                                                 low::WIDGET vsb, 
                                                 fix_glue vpad,
                                                 low::WIDGET scrolled_widget
                                               ]
                                            ]);

                       (FALSE, TRUE) => low::make_line_of_widgets  root_window 
                                            (low::VT_CENTER [
                                               low::HZ_CENTER [
                                                 low::WIDGET vsb, 
                                                 fix_glue vpad,
                                                 low::WIDGET scrolled_widget
                                               ],
                                               fix_glue hpad,
                                               low::HZ_CENTER [
                                                 fix_glue (vsz+vpad),
                                                 low::WIDGET hsb 
                                               ]
                                            ]);

                       (TRUE, FALSE) => low::make_line_of_widgets  root_window 
                                            (low::VT_CENTER [
                                               low::HZ_CENTER [
                                                 low::WIDGET hsb,
                                                 fix_glue (vsz+vpad)
                                               ],
                                               fix_glue hpad,
                                               low::HZ_CENTER [
                                                 low::WIDGET scrolled_widget,
                                                 fix_glue vpad,
                                                 low::WIDGET vsb
                                               ]
                                            ]);

                       (FALSE, FALSE) => low::make_line_of_widgets  root_window 
                                             (low::VT_CENTER [
                                                low::HZ_CENTER [
                                                  low::WIDGET scrolled_widget,
                                                  fix_glue vpad,
                                                  low::WIDGET vsb
                                                ],
                                                fix_glue hpad,
                                                low::HZ_CENTER [
                                                  low::WIDGET hsb,
                                                  fix_glue (vsz+vpad)
                                                ]
                                             ]);

                    esac;
                };
        end;                            # fun make_widget_with_scrollbars

    };                                  # package widget_with_scrollbars

end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext