PreviousUpNext

15.4.1411  src/lib/x-kit/widget/leaf/toggleswitches.pkg

## toggleswitches.pkg
#
# Common toggleswitches.
#
# Compare to:
#     src/lib/x-kit/widget/leaf/pushbuttons.pkg

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







#                "The programmer, like the poet, works only slightly removed from pure thought-stuff. 
#                 He builds his castles in the air, from air, creating by exertion of the imagination.
#                 Few media of creation are so flexible, so easy to polish and rework, so readily
#                 capable of realizing grand conceptual structures.
#
#                                           - Frederick Brooks, Jr., The Mythical Man Month


stipulate
    package wg =  widget;                                                                       # widget                        is from   src/lib/x-kit/widget/basic/widget.pkg
    package wa =  widget_attribute;                                                             # widget_attribute              is from   src/lib/x-kit/widget/lib/widget-attribute.pkg
    package wy =  widget_style;                                                                 # widget_style                  is from   src/lib/x-kit/widget/lib/widget-style.pkg
    package wt =  widget_types;                                                                 # widget_types                  is from   src/lib/x-kit/widget/basic/widget-types.pkg
herein

    package toggleswitches: (weak)  Toggleswitches      {                                       # Toggleswitches                is from   src/lib/x-kit/widget/leaf/toggleswitches.api

        # The Toggleswitches api re-exports
        # basicallly all of toggle_type:
        #
        include toggle_type;                                                                    # toggle_type                   is from   src/lib/x-kit/widget/leaf/toggle-type.pkg

                                                                                                # toggleswitch_behavior_g       is from   src/lib/x-kit/widget/leaf/toggleswitch-behavior-g.pkg

        package  check_toggle =  toggleswitch_behavior_g( checkbutton_look  );          # checkbutton_look      is from   src/lib/x-kit/widget/leaf/checkbutton-look.pkg
        package   text_toggle =  toggleswitch_behavior_g( textbutton_look   );          # textbutton_look               is from   src/lib/x-kit/widget/leaf/textbutton-look.pkg
        package  round_toggle =  toggleswitch_behavior_g( roundbutton_look  );          # roundbutton_look      is from   src/lib/x-kit/widget/leaf/roundbutton-look.pkg
        package  label_toggle =  toggleswitch_behavior_g( labelbutton_look  );          # labelbutton_look      is from   src/lib/x-kit/widget/leaf/labelbutton-look.pkg
        package rocker_toggle =  toggleswitch_behavior_g( rockerbutton_look );          # rockerbutton_look             is from   src/lib/x-kit/widget/leaf/rockerbutton-look.pkg

        make_checkbox_toggleswitch' =  check_toggle::make_toggleswitch_with_click_callback;
        make_text_toggleswitch'     =   text_toggle::make_toggleswitch_with_click_callback;
        make_round_toggleswitch'    =  round_toggle::make_toggleswitch_with_click_callback;
        make_rocker_toggleswitch'   = rocker_toggle::make_toggleswitch_with_click_callback;

        label_button  =  label_toggle::make_toggleswitch_with_click_callback;

        fun check_button (root, view, args)
                =
                label_button (root, view, args @ [(wa::type, wa::STRING_VAL "check")]);

        fun radio_button (root, view, args)
                =
                label_button (root, view, args @ [(wa::type, wa::STRING_VAL "radio")]);



        fun add_state (s, l)
            =
            {   fun set a
                    =
                    (wa::state, wa::BOOL_VAL a);

                case s 
                    #
                    wt::ACTIVE   a => (set a) ! (wa::active, wa::BOOL_VAL TRUE) ! l;
                    wt::INACTIVE a => (set a) ! (wa::active, wa::BOOL_VAL FALSE) ! l;
                esac;
            };

        fun make_rocker_toggleswitch root { click_callback, state, foreground, background }
            =
            {   name = wy::make_view
                         { name=> wy::style_name ["toggleSwitch"],
                           aliases => []
                         };

                args = add_state (state,[]);

                args = case foreground   
                           #    
                           THE c => (wa::foreground, wa::COLOR_VAL c) ! args;
                           NULL  => args;
                       esac;

                args = case background   
                           #    
                           THE c => (wa::background, wa::COLOR_VAL c) ! args;
                           NULL => args;
                       esac;

                make_rocker_toggleswitch' (root, (name, wg::style_of root), args) click_callback;
            };

        fun make_checkbox_toggleswitch root { state, size, click_callback, color }
            =
            {   name = wy::make_view
                         { name    => wy::style_name ["toggleCheck"],
                           aliases => []
                         };

                args = add_state (state,[(wa::width, wa::INT_VAL size)]);

                args = case color   
                           THE c => (wa::color, wa::COLOR_VAL c) ! args;
                           NULL => args;
                       esac;

                make_checkbox_toggleswitch' (root, (name, wg::style_of root), args) click_callback;
            };


        fun make_round_toggleswitch root { state, radius, click_callback, foreground, background }
            =
            {   name = wy::make_view { name=> wy::style_name ["toggleCircle"],
                                       aliases => [] };

                args = add_state (state,[(wa::width, wa::INT_VAL (2*radius))]);

                args = case foreground   
                           THE c => (wa::foreground, wa::COLOR_VAL c) ! args;
                           NULL  => args;
                       esac;

                args = case background   
                           THE c => (wa::background, wa::COLOR_VAL c) ! args;
                           NULL  => args;
                       esac;

                make_round_toggleswitch' (root, (name, wg::style_of root), args) click_callback;
            };

        fun make_icon_toggleswitch root { state, icon, click_callback, foreground, background }
            =
            {   name = wy::make_view { name    =>  wy::style_name ["toggleIcon"],
                                       aliases =>  []
                                     };

                args = add_state (state,[(wa::tile, wa::TILE_VAL icon)]);

                args = case foreground   
                           #
                           THE c =>  (wa::foreground, wa::COLOR_VAL c) ! args;
                           NULL  =>  args;
                       esac;

                args = case background   
                           #
                           THE c =>  (wa::background, wa::COLOR_VAL c) ! args;
                           NULL  =>  args;
                       esac;

                label_button (root, (name, wg::style_of root), args) click_callback;
            };

        fun make_text_toggleswitch root { state, rounded, label, click_callback, foreground, background }
            =
            {   name = wy::make_view { name=> wy::style_name ["toggleIcon"],
                                       aliases => []
                                     };

                args = [ (wa::label, wa::STRING_VAL label),
                         (wa::rounded, wa::BOOL_VAL rounded)
                       ];

                args = add_state (state, args);

                args = case foreground   
                           THE c => (wa::foreground, wa::COLOR_VAL c) ! args;
                           NULL  => args;
                       esac;

                args = case background   
                           THE c => (wa::background, wa::COLOR_VAL c) ! args;
                           NULL  => args;
                       esac;

                make_text_toggleswitch' (root, (name, wg::style_of root), args) click_callback;
            };

    };                          # package toggleswitch 

end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext