## toggleswitches.pkg
#
# Common toggleswitches.
#
# Compare to:
#
src/lib/x-kit/widget/old/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/old/basic/widget.pkg package wa = widget_attribute_old; # widget_attribute_old is from
src/lib/x-kit/widget/old/lib/widget-attribute-old.pkg package wy = widget_style_old; # widget_style_old is from
src/lib/x-kit/widget/old/lib/widget-style-old.pkg package wt = widget_types; # widget_types is from
src/lib/x-kit/widget/old/basic/widget-types.pkgherein
# This package is referenced in:
#
#
src/lib/x-kit/tut/calculator/calculator.pkg #
src/lib/x-kit/tut/colormixer/colormixer-app.pkg #
src/lib/x-kit/widget/old/menu/pulldown-menu-button.pkg #
package toggleswitches
: (weak) Toggleswitches # Toggleswitches is from
src/lib/x-kit/widget/old/leaf/toggleswitches.api {
# The Toggleswitches api re-exports
# basicallly all of toggle_type:
#
include package toggle_type; # toggle_type is from
src/lib/x-kit/widget/old/leaf/toggle-type.pkg # toggleswitch_behavior_g is from
src/lib/x-kit/widget/old/leaf/toggleswitch-behavior-g.pkg package check_toggle = toggleswitch_behavior_g( checkbutton_look ); # checkbutton_look is from
src/lib/x-kit/widget/old/leaf/checkbutton-look.pkg package text_toggle = toggleswitch_behavior_g( textbutton_look ); # textbutton_look is from
src/lib/x-kit/widget/old/leaf/textbutton-look.pkg package round_toggle = toggleswitch_behavior_g( roundbutton_look ); # roundbutton_look is from
src/lib/x-kit/widget/old/leaf/roundbutton-look.pkg package label_toggle = toggleswitch_behavior_g( labelbutton_look ); # labelbutton_look is from
src/lib/x-kit/widget/old/leaf/labelbutton-look.pkg package rocker_toggle = toggleswitch_behavior_g( rockerbutton_look ); # rockerbutton_look is from
src/lib/x-kit/widget/old/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)
=
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
where
fun set a = (wa::state, wa::BOOL_VAL a);
end;
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;