This is a tutorial for a simple, yet feature-rich, calendar.
It uses overlap groups inside stack groups and creates the correct numbers based on the cell positions (all data has the same index).
The calendar is modular, meaning you can pick which features you want to use, remove or add more later, or just make a barebones number table.
The Days of the Week
Calculation is based on a table of 1x7. You will need a horizontal stack group containing 7 overlap groups, indexed 0 to 6.
To have the days reflect the first day of the week selected in the settings, create a global text with this formula:
Making the Table
Additionally, you can highlight the current day text by using this formula to show a different text color:Replace COLOR0 and COLOR1 with the preferred HEX values (I suggest you use globals).
You can also change the color of the weekend days by using this formula to show a different text color:Replace COLOR0 and COLOR1 with the preferred HEX values (I suggest you use globals). Keep si(mindex ,1) the same as the index in gv(weekday).
The Days of the Month
Calculation is based on a table of 6x7, so you will have a vertical stack group containing 6 horizontal stack groups, each will have 7 overlap groups. Therefore a total of 42 overlap groups indexed 0 to 41.
To find the index position of the day 1 of this month based on the settings (index 0 - 6), create a global text with this formula:
To find the index position of the current day of this month, create a global text with this formula:
To get the index position of each cell, create a global text with this formula:
gv(index)You can increase/decrease the index, depending on how many parent groups the day number text has.NOTE: Instead of 7, si(mcount,1) could be used. But this is a rare case of "a variable that doesn't change" because calendars have seven days in a week, so that really is not necessary.
To get the number for each day of the calendar, create a global text with this formula:Use df(dd to get the leading zero: 01, 02.
Making the Calendar Table
You can also change the color of the weekend days by using this formula to show a different text color:Replace COLOR0 and COLOR1 with the preferred HEX values (I suggest you use globals). Keep si(mindex ,1) the same as the first part of gv(index).
Make the Days of the Previous/Next Month Different
We need another global for the position of the last day, to compare the days' positions according to it.
To find the index position of the last day of this month based on the settings, create a global text with this formula:
Assigning a Different Color to the Numbers
Hiding the Groups
To hide the day groups of the previous month and the next month, use this formula for the visibility of the day groups:
It's easy to display the monthly progress (by changing the color of the past days). We need a simple switch and to change the color formula for the day.
For the user-controllable switch, create a simple global switch called Progress.
Changing the Color formula for the Numbers
Take the color formula from the previous section and add a condition that will change the color based on the progress switch:
color formulaReplace COLOR0, COLOR1, COLOR2 and COLOR3 with the preferred HEX values (I suggest you use globals).
Add Event Indicators
We already know the day of each cell. To calculate the number of events on each day we also need the month (different in the first and last rows) and year (can change if the calendar is displaying December or January) of that day. We will also add a full date global for convenience.
To get the month of each cell, create a global text with this formula:
To get the year of each cell, create a global text with this formula:
To get the date of each cell, create a global text with this formula:
To calculate the number of events on each day, create a global text with this formula:
Making the Indicator
Add a shape (or a number) in the same group as the day number text.
If you chose a number, make it show $gv(dayevent)$.
If you chose a shape, change its color like so:Replace COLOR with the preferred HEX value (I suggest you use globals).
Scroll Through Events for a Chosen Day
We will need more globals, more specifically globals from the Events blueprint. First a blank text global for the chosen date, a global that calculates the number of events on that date and another global for a chosen event. Then we also need globals for events' info.
To hold the chosen date, add a text global:
gv(date)Leave it blank, it will be set by the touch action.
To calculate the number of events on the chosen date, add a text global:
To hold the index number of the chosen event, add a text global:
gv(event)Leave it blank, it will be set by the touch action.
To pick the chosen date you could simply use gv(daydate), but then that date will remain set until you pick another one, even when the day changes (displayed events in agenda will be from past days). So I suggest you go one step further and make it reset every time you tap on today's group. For that add a text global:
Adding Touch Actions
Make sure the base of the Day group has the same index as the other data and add a touch action to it:
Action = Toggle Globlal Switch
Switch = gv(date)
Text = $gv(touchday)$
Add another touch action to reset gv(event) to 0 every time you switch dates:
Action = Toggle Global Switch
Switch = gv(event)
Text = 0
Making the Event Group
Like in the Events blueprint add two buttons and a stack of data.
The index of the objects in the stack doesn't matter here, but it is suggested that it has the same structure as the agenda.
Add a text item in the stack and make it show $gv(title)$.
Add touch actions to the buttons that will switch between previous and next events:
Action = Toggle Global Switch
Switch = gv(event)
Text Text =
List All Events for a Chosen Day
This part is the same as before with a few key differences.
Making the Event Group
Like in the Agenda blueprint add a stack of multiple event groups.
Apply HideEvnt as the visibility formula for each group.
Every event group contains more groups, each holding a piece of event's information.
Add a text item in its own group inside the Event stack group and make it show $gv(title)$.
Do the same for all other agenda globals.
Add a Forecast
This calendar can also have forecast globals and display the weather forecast for the next few days. What type of content to display is up to you - you can even choose to display the condition wi(cond) (but idk where you'd put it).
For reference we'll change the layout of the structure - tree (look in the app for more examples). This is to have certain contents grouped together while keeping the index identical across all formulas. It is relatively easy to do by putting the day and indicators inside more parent groups and then changing the gv(index) formula.
We'll also hide the weather groups after the forecast data ends - usually after max 14 days (why that is you can read somewhere else - calculating data further into the future is pointless).
Because we'll move the data in day cells into two more groups, change the index global like so:
To get the weather icon on each day, create a global text with this formula:
gv(wicon)Returns the equivalent of $wi(icon)+ai(isday)$. Change based on the weather icon pack.
To get the average temperature on each day, create a global text with this formula (I suggest you skip this one and use the maximum temperature instead):
To get the maximum temperature on each day, create a global text with this formula:
To get the minimum temperature on each day, create a global text with this formula:
To hide the weather data on days with no forecast data, create a global text with this formula:
Changing Day Group Contents
Cut the day number text and move it inside two more groups (overlap or stack).
Then create a new stack group inside the parent day group and set its visibility to gv(hidewthr).
Inside that stack group add another stack group (for temperatures) and an overlap group (for the icon).
Inside the stack group add two text objects and link them to gv(tempmax) and gv(tempmin), respectively.
Inside the overlap group add a fonticon or a bitmap (depending on what weather icons you use) and set it to display gv(wicon).
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
Kustom formatted version