ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Fabrice Couvreur <fabrice1.couvreur@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Lua code and table
Date: Wed, 17 Feb 2021 18:40:54 +0100	[thread overview]
Message-ID: <CACyK-eo9=7wLiud6c1sbkVtNLWbwbgwqVBM8COw=0VOh24KQXg@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 3315 bytes --]

Hi, The code works, but is it possible to make it shorter ?
Thank you
Fabrice


\startuseMPgraphic{DiagonalRule}
   rulethickness := \frameddimension{rulethickness};

   drawoptions(
     withpen pencircle scaled rulethickness
     withcolor \MPcolor{\framedparameter{framecolor}});

   pair leftcorner, rightcorner, Leftcorner, Rightcorner;
   leftcorner  := (rulethickness, \overlayheight-rulethickness);
   rightcorner := (\overlaywidth-rulethickness, rulethickness);
   Leftcorner  := ( rulethickness, rulethickness);
   Rightcorner :=
(\overlaywidth-rulethickness,\overlayheight-rulethickness);

   draw leftcorner -- rightcorner;
   draw Leftcorner -- Rightcorner;
 \stopuseMPgraphic

\defineoverlay
  [DiagonalRule]
  [\useMPgraphic{DiagonalRule}]

\define[2]\DiagonalLabel{%
  \setuptabulate [after={\blank[\frameddimension{offset}]}]
  \starttabulate [|p|r|]
    \NC    \NC \bf #2 \NC\NR
    \NC \bf #1 \NC    \NC\NR
  \stoptabulate
}
\starttext
\startluacode
  local background_one = {
   align = "middle",
   style = "type",
   background = "DiagonalRule",
  }

  local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H" }
  context.startxtable({"align={middle,lohi},
width=0.8cm,offset=0.8ex,bodyfont=9pt,framecolor=cyan"})
  context.startxrow()
  context.startxcell({"frame=off"})
  context()
  context.stopxcell()
  for _, letter in ipairs(letters_1) do
    context.startxcell()
    context(letter) context.stopxcell()
  end
  context.stopxrow()
   for _, letter in ipairs(letters_1) do
  context.startxrow()
    context.startxcell()
    context(letter)
    context.stopxcell()
  for j = 0, 7 do
  context.startxcell(  j == 0 and letter == "B" and background_one
  or j == 0 and letter == "C" and background_one
  or j == 0 and letter == "D" and background_one
  or j == 0 and letter == "G" and background_one
  or j == 0 and letter == "H" and background_one
  or j == 1 and letter == "A" and background_one
  or j == 1 and letter == "E" and background_one
  or j == 1 and letter == "F" and background_one
  or j == 1 and letter == "G" and background_one
  or j == 2 and letter == "A" and background_one
  or j == 2 and letter == "D" and background_one
  or j == 2 and letter == "F" and background_one
  or j == 2 and letter == "G" and background_one
  or j == 2 and letter == "H" and background_one
  or j == 3 and letter == "A" and background_one
  or j == 3 and letter == "C" and background_one
  or j == 3 and letter == "E" and background_one
  or j == 3 and letter == "H" and background_one
  or j == 4 and letter == "B" and background_one
  or j == 4 and letter == "D" and background_one
  or j == 4 and letter == "F" and background_one
  or j == 4 and letter == "G" and background_one
  or j == 5 and letter == "B" and background_one
  or j == 5 and letter == "C" and background_one
  or j == 5 and letter == "E" and background_one
  or j == 6 and letter == "A" and background_one
  or j == 6 and letter == "B" and background_one
  or j == 6 and letter == "C" and background_one
  or j == 6 and letter == "E" and background_one
  or j == 7 and letter == "A" and background_one
  or j == 7 and letter == "C" and background_one
  or j == 7 and letter == "D" and background_one
  )
  context()
  context.stopxcell()
  end
  context.stopxrow()
  end
  context.stopxtable()
\stopluacode
\stoptext

[-- Attachment #1.2: Type: text/html, Size: 5546 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

             reply	other threads:[~2021-02-17 17:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 17:40 Fabrice Couvreur [this message]
2021-02-17 21:13 ` Tomas Hala
2021-02-17 21:26 ` Wolfgang Schuster
2021-02-17 22:52   ` Hans Hagen
2021-02-17 23:22 ` Bruce Horrocks
2021-02-18  9:06   ` Hans Hagen
2021-02-18 15:14     ` Fabrice Couvreur
2021-02-18 15:26       ` Jano Kula
2021-02-18 15:28         ` Fabrice Couvreur
2021-02-19 11:42           ` Fabrice Couvreur
2021-02-19 12:06             ` Hans Hagen
2021-02-19 13:12               ` Jano Kula
2021-02-19 13:26                 ` Hans Hagen
2021-02-20 17:21                   ` Fabrice Couvreur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACyK-eo9=7wLiud6c1sbkVtNLWbwbgwqVBM8COw=0VOh24KQXg@mail.gmail.com' \
    --to=fabrice1.couvreur@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).