Files
breeze/apps/habits/table_layout.zi
waozi a687881c94 Habits and Practices draw their screens in their own packages
Habits' list with each habit's week and calendar, its day with the entry
dialog, the editor and the statistics now come from the Habits package, and
Practices' home, the Wim Hof, Meditation, Patterns and Astral Projection
manuals, Meditation's and Astral Projection's Customize pages and the
results after a practice come from the Practices package, so they can change
without an app update. The host keeps the data, the rules and the storage,
gives each page its frame and does what the page asks. The pages draw
exactly as before.

Kryon now hosts segmented controls, form sections, toggle sizes, lines,
circles, rings, triangles, sliders and progress bars for bundles and lets a
bundle import up to 256 host calls; plot hosts its band chart. Host
interface 30; Habits 1.3.0 and Practices 1.4.0.
2026-10-24 23:17:45 -03:00

82 lines
2.3 KiB
Ziran

// The habit table has a name column and then up to seven day columns. The
// days share the width the name column leaves, within their limits, and the
// name column takes the rest.
HabitTableDayWidth :: (width: s32, name_min: s32, day_min: s32,
day_max: s32) -> s32 {
day := (width - name_min) / 7
if day > day_max {
day = day_max
}
if day < day_min {
day = day_min
}
return day
}
// Rows keep their order; only the rows below an open row move down by its
// details.
HabitRowOffset :: (position: s32, open: s32, row_height: s32,
detail_height: s32) -> s32 {
offset := position * row_height
if open >= 0 && position > open {
offset += detail_height
}
return offset
}
// The table's columns for its inner width.
HabitTableLayout :: struct {
// The column before the days: an icon and a name, or the icon alone.
name_width: s32
day_width: s32
// Today and the days before it that fit, at most seven.
days: s32
names: bool
}
// Four days are the smallest useful week: names stay visible while they fit,
// then give way to icons. Below that, the four days shrink only when the table
// itself is too narrow to hold their readable minimum.
HabitTableLayoutFor :: (width: s32, name_preferred: s32, name_min: s32,
icon_column: s32, day_min: s32, day_max: s32) -> HabitTableLayout {
layout: HabitTableLayout
layout.names = true
days: s32 = 7
while days > 4 && width - name_preferred < days * day_min {
days -= 1
}
layout.days = days
layout.day_width = (width - name_preferred) / days
if layout.day_width > day_max {
layout.day_width = day_max
}
if layout.day_width < day_min && width >= day_min * 4 {
layout.day_width = day_min
}
layout.name_width = width - layout.day_width * days
if layout.name_width >= name_min {
return layout
}
layout.names = false
space := width - icon_column
days = space / day_min
if days > 7 {
days = 7
}
if days < 4 {
days = 4
}
layout.days = days
layout.day_width = space / days
if layout.day_width > day_max {
layout.day_width = day_max
}
if layout.day_width < 1 {
layout.day_width = 1
}
layout.name_width = width - layout.day_width * days
return layout
}