From 9745514c1833bee05ce0a2ee28cd92d62fd4a8dc Mon Sep 17 00:00:00 2001 From: John Denker Date: Thu, 11 Nov 2021 08:40:48 -0700 Subject: fix it so that the set of "allowed functions" shows up in even rows and almost-even columns --- edit_algebra_form.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'edit_algebra_form.php') diff --git a/edit_algebra_form.php b/edit_algebra_form.php index e091418..3ab31ac 100644 --- a/edit_algebra_form.php +++ b/edit_algebra_form.php @@ -89,18 +89,32 @@ class qtype_algebra_edit_form extends question_edit_form { // Create an array which will store the function checkboxes. $funcgroup = array(); +// KLUDGE: illogical, but works better than the alternative: +//
doesn't separate rows the way you want; try a full-width div instead: + $rowSep = '
'; + +// FIXME: +// Trying to align columns using flexbox + spacers is an unsound design. +// It fails in ways the server cannot anticipate, because of variable-width fonts. +// Such things should be aligned using an html table or css grid, +// or by wrapping each checkbox in a fixed-width wrapper: +// https://stackoverflow.com/questions/257505/css-fixed-width-in-a-span // Create an array to add spacers between the boxes. - $spacers = array('
'); + $spacers = array($rowSep); + $itemsPerRow = 6; // Add the initial all functions box to the list of check boxes. $funcgroup[] =& $mform->createElement('checkbox', 'all', '', get_string('allfunctions', 'qtype_algebra')); // Create a checkbox element for each function understood by the parser. +// FIXME: why do the function names show up on the page in some weird order??? for ($i = 0; $i < count(qtype_algebra_parser::$functions); $i++) { $func = qtype_algebra_parser::$functions[$i]; $funcgroup[] =& $mform->createElement('checkbox', $func, '', $func); - if (($i % 6) == 5) { - $spacers[] = '
'; + if (((1+$i) % $itemsPerRow) == 0) { + $spacers[] = $rowSep; } else { - $spacers[] = str_repeat(' ', 8 - strlen($func)); +// KLUDGE: far from perfect, but +// usable approximation for typical variable-width fonts: + $spacers[] = str_repeat(' ', 2.0*(8 - strlen($func))); } } // Create and add the group of function controls to the form. -- cgit v1.2.3