ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Perfecting my checkbox functionalities
@ 2010-09-10  8:05 Cecil Westerhof
  2010-09-10 16:00 ` Wolfgang Schuster
  0 siblings, 1 reply; 2+ messages in thread
From: Cecil Westerhof @ 2010-09-10  8:05 UTC (permalink / raw)
  To: NTG ConTeXt mailing list

I am learning to work with ConTeXt. At the moment I have the following
defined:
    \newdimen\CheckBoxMargin
    \CheckBoxMargin=2em
    \newdimen\CheckBoxWidth
    \CheckBoxWidth=2.5em
    \newdimen\CheckBoxDistance
    \CheckBoxDistance=.5em
    \definesymbol[CheckBox][{[~~~]}]
    \def\startcheckbox[#1]{
      \blank
      \leftaligned{#1}
      \startitemize[packed, intro, joinedup][margin=\CheckBoxMargin,
                    symbol=CheckBox, width=\CheckBoxWidth,
                    distance=\CheckBoxDistance]
    }

    \def\stopcheckbox{
      \stopitemize
      \blank
      \crlf
    }

    \def\GetNiveauOfService[#1]{
      \blank
      #1 {\switchtobodyfont[0.5em](1 = low, 9 = high)}
      \startitemize[packed, intro, joinedup, columns][n=9,
                    symbol=CheckBox, width=\CheckBoxWidth,
                    distance=\CheckBoxDistance]
      \dorecurse{9}{
        \item \recurselevel
      }
      \stopcheckbox
    }

I have a few questions about this.

In GetNiveauOfService 9 is used three times. I like DRY, so I was
wondering if there would be a better way to do this?

Next step would be that the number of checkboxes could be a parameter.
The default would be nine and if given, the given value would be used.
How would I do this?

Then the 'normal' checkboxes. The default is one column. But I would
like to have the possibility to use a parameter to for example make
checkboxes in three columns. How would I do this?

Lastly, in GetNiveauOfService there is text. How can I make this
language dependent. For example in English I want:
    (1 = low, 9 = high)
but in Dutch:
    (1 = weinig, 9 = veel)
and properly it would be a good idea to have two optional parameters
when you want other descriptions.
How would I do this?

-- 
Cecil Westerhof
M CLDWesterhof@gmail.com

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Please do not send me Microsoft Office/Apple iWork documents.
Send OpenDocument instead! http://fsf.org/campaigns/opendocument/
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Perfecting my checkbox functionalities
  2010-09-10  8:05 Perfecting my checkbox functionalities Cecil Westerhof
@ 2010-09-10 16:00 ` Wolfgang Schuster
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Schuster @ 2010-09-10 16:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 10.09.2010 um 10:05 schrieb Cecil Westerhof:

> I am learning to work with ConTeXt. At the moment I have the following
> defined:


I guess we need a context programmers guide.

>    \newdimen\CheckBoxMargin
>    \CheckBoxMargin=2em
>    \newdimen\CheckBoxWidth
>    \CheckBoxWidth=2.5em
>    \newdimen\CheckBoxDistance
>    \CheckBoxDistance=.5em

Get rid of this stuff and use a setup command:

\def\setupCheckBox
  {\dodoubleargument\getrawparameters[CheckBox]}

\setupCheckBox
  [Margin=2em,
   Width=2.5em,
   Distance=.5em]


>    \definesymbol[CheckBox][{[~~~]}]
>    \def\startcheckbox[#1]{
>      \blank
>      \leftaligned{#1}
>      \startitemize[packed, intro, joinedup][margin=\CheckBoxMargin,
>                    symbol=CheckBox, width=\CheckBoxWidth,
>                    distance=\CheckBoxDistance]
>    }
> 
>    \def\stopcheckbox{
>      \stopitemize
>      \blank
>      \crlf
>    } 

Brr, latex style. Why \crlf at the end of \stopcheckbox, to get a bigger space use \blank[...].

>    \def\GetNiveauOfService[#1]{
>      \blank
>      #1 {\switchtobodyfont[0.5em](1 = low, 9 = high)}
>      \startitemize[packed, intro, joinedup, columns][n=9,
>                    symbol=CheckBox, width=\CheckBoxWidth,
>                    distance=\CheckBoxDistance]
>      \dorecurse{9}{
>        \item \recurselevel
>      }
>      \stopcheckbox
>    }

\def\GetNiveauOfService
  {\dodoubleempty\doGetNiveauOfService}

\def\doGetNiveauOfService[#1][#2]%
  {\blank
   #1 {\switchtobodyfont[0.5em]\doifsomethingelse{#2}{#2}{(1 = \translate[en=low,nl=weinig], 9 = \translate[en=high,nl=veel])}}
  \startitemize[packed,intro,joinedup,columns][n=9,symbol=CheckBox, width=\CheckBoxWidth,distance=\CheckBoxDistance]
  \dorecurse{9}{\item \recurselevel}
  \stopitemize}


> I have a few questions about this.
> 
> In GetNiveauOfService 9 is used three times. I like DRY, so I was
> wondering if there would be a better way to do this?

???

(Note: I switched your following two questions)

> Lastly, in GetNiveauOfService there is text. How can I make this
> language dependent. For example in English I want:
>    (1 = low, 9 = high)
> but in Dutch:
>    (1 = weinig, 9 = veel)
> and properly it would be a good idea to have two optional parameters
> when you want other descriptions.
> How would I do this?

See my version of the command, there is a second optional argument which
can be used to set a alternative text.

> Next step would be that the number of checkboxes could be a parameter.
> The default would be nine and if given, the given value would be used.
> How would I do this?
> 
> Then the 'normal' checkboxes. The default is one column. But I would
> like to have the possibility to use a parameter to for example make
> checkboxes in three columns. How would I do this?

For the last question i showed you how you can use a optional parameter
to set alternative text but as you want more and more parameter you
should first think about the interface for you commands (e.g. key-value
makes more sense than lots of text arguments because you can’t make
all of them optional in this case.

Wolfgang


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-10 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-10  8:05 Perfecting my checkbox functionalities Cecil Westerhof
2010-09-10 16:00 ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).