[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I equally space?
From: |
Valeriy E. Ushakov |
Subject: |
Re: How do I equally space? |
Date: |
Tue, 26 Oct 1999 02:06:43 +0400 |
On Thu, Oct 21, 1999 at 01:23:49PM -0700, address@hidden wrote:
> Ideally I'd like to write this up as a def which somehow can take a
> parameters like:
>
> def @SmallMonth
> named title {}
> named firstDayOfWeek {}
> named lastDayOfMonth {}
> ...
>
> Then I could do @SmallMonth title {December 1999} firstDayOfWeek {3}
> lastDayOfMonth{31}. What I can't really do is figure out how to use galleys
> to create a new row every seven days. Note that there can be either five or
> six rows depending on the firstDayOfWeek and number of days in the month.
> I'm not sure how to stop the recursion at the ending day either.
Here's a rough prototype:
# "meta-galley", helps to get rid of hordes of
# trivial galley definitions
def @Send
left @Target
named @
right @Component
{ @Component }
right galley
{
def @Enclose right component { @ component }
galley
}
import @BasicSetup # for standard.ld
def @MonthCalendar
left month # month number
named skip { 0 } # number of empty cells in the first week row
@Begin
def @CellPlace { @Galley }
def @MonthGrid
named hgap {}
named vgap {}
{
def @WeekRow {
@CellPlace |hgap @CellPlace |hgap @CellPlace
|hgap @CellPlace |hgap @CellPlace |hgap @CellPlace
|hgap @CellPlace
}
@WeekRow # The first row is for weekday names
//vgap @WeekRow //vgap @WeekRow //vgap @WeekRow
//vgap @WeekRow //vgap @WeekRow //vgap @WeekRow
}
def @Dates
named skip { 0 }
named compulsory last {}
{
def @Skip
named count { 1 }
{
count @Case {
skip @Yield {}
else @Yield { /1.1b @Skip count { @Next count } }
}
}
def @DateList
named first { 1 }
named compulsory last {}
{
first @Case {
last @Yield { last ^& }
else @Yield { first ^&
/1.1b @DateList first { @Next first } last { last }
}
}
}
# @Dates body
skip @Case {
0 @Yield { @Null }
else @Yield { @Skip }
}
/1.1b
@DateList first { 1 } last { last }
}
def @WeekDayTitles
{
def @WeekDay right num
{ 0.8w @HShift @ShortWeekDays&&num }
@WeekDay 1
/1.1b @WeekDay 2
/1.1b @WeekDay 3
/1.1b @WeekDay 4
/1.1b @WeekDay 5
/1.1b @WeekDay 6
/1.1b @WeekDay 7
}
# Body of @MonthCalendar
# Fake target skipped by initial /1.1b below
# Need this to force lout to attach the galley
# The paragraph concatenation is necesary to prevent
# lout from considering incoming components as components
# of the surrounding galley
@CellPlace &
// { @CellPlace&&preceding } @Send {
/1.1b # skip preceding target and force lout
# to search for the following targets
@WeekDayTitles
/1.1b
@Dates skip { skip } last { 31 }
}
// @HContract {
|0.5rt @Months&&month
//1v
@MonthGrid hgap { 1s } vgap { 1v }
}
@End @MonthCalendar
Invoking this like 12 @MonthCalendar skip { 3 } will produce (with -p):
December
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
The trickiest part is getting galleys right. Slightly simplified
version of the above is:
@CellPlace &
// { @CellPlace&&preceding } @Send {
/1.1b
@WeekDayTitles
/1.1b
@Dates skip { skip } last { 31 }
}
// @MonthGrid hgap { 1s } vgap { 1v }
See section 2.7 of the expert's guide for background information.
@MonthGrid sets up a grid of @Galley's. The body of @Send provides a
list of vertically concatenated numbers. This implies that they have
equal width (pp27-28). Separating components with /1.1b ensures that
each goes into new @Galley. First /1.1b skips the fake @CellPlace
that's necessary to force lout to attach the galley(p31).
Paragraph concatenation after the fake @CellPlace ensures that
incoming components can not become components of enclosing galley.
Otherwise, since fake @CellPlace would be a component of enclosing
galley, all the incoming components could be made a components of
their new home (p27) and your calendar will be spread over a bunch of
pages one date on a page ;-).
So the fake @CellPlace consumed by the first /1.1b puts the lout on
the right track and the rest of material within @Send finds its way to
the @MonthGrid.
Of course this definition has plenty of room for improvements, but
it should demonstrate the idea.
PS: Re @Send "meta-galley". When you use galleys you will find
yourself repeatedly writing stuff like:
def @SomePlace { @Galley }
def @SendSome into { @SomePlace&&preceding } right x { x }
You can get rid of all those trivial @Send* symbols using the @Send
symbol above. I find this especially useful when experimenting with
galleys. You just write
{ @SomePlace&&preceding } @Send { some stuff }
instead of the definition for @SendStuff and:
@SendStuff { some stuff }
You can specify @Enclose using the "@" named parameter:
{ @SomePlace&&preceding } @Send @address@hidden @Component} { some stuff }
Hope this helps.
SY, Uwe
--
address@hidden | Zu Grunde kommen
http://www.ptc.spbu.ru/~uwe/ | Ist zu Grunde gehen