1188 lines
53 KiB
Ziran
1188 lines
53 KiB
Ziran
#import "geometry"
|
|
#import "drawing_props"
|
|
#import "layout"
|
|
#import "image_props"
|
|
#import "image_widget"
|
|
#import "text_props"
|
|
#import "text_widget"
|
|
#import "text_align"
|
|
#import "text_input_props"
|
|
#import "text_area_widget"
|
|
#import "button_props"
|
|
#import "button_widget"
|
|
#import "control_props"
|
|
#import "box_props"
|
|
#import "box_widget"
|
|
#import "loading_indicator"
|
|
#import "checkbox_props"
|
|
#import "checkbox_widget"
|
|
#import "context_menu_widget"
|
|
#import "press_props"
|
|
#import "press_widget"
|
|
#import "scroll_props"
|
|
#import "scroll_widget"
|
|
#import "title_bar_props"
|
|
#import "title_bar_widget"
|
|
#import "dropdown_props"
|
|
#import "tree"
|
|
#import "text"
|
|
#import "byte_text_linux"
|
|
#import "c_string"
|
|
#import "vec"
|
|
#import "math"
|
|
#import, file "../../src/apps/lumi_types.zi";
|
|
#import, file "../../src/apps/lumi_ui_types.zi";
|
|
#import, file "../../src/apps/lumi_chart.zi";
|
|
#import, file "command_text.zi";
|
|
#import, file "engine.zi";
|
|
#import, file "message_text.zi";
|
|
ConnectedIcon :: #import "mingcute/mingcute_regular_wifi";
|
|
DisconnectedIcon :: #import "mingcute/mingcute_regular_wifi_off";
|
|
ConfigureIcon :: #import "mingcute/mingcute_regular_tool";
|
|
|
|
using ImageFit;
|
|
using TextWrap;
|
|
using TextAlign;
|
|
using ButtonTone;
|
|
using ButtonEmphasis;
|
|
host_api :: #system_library "host_api";
|
|
ReadLumiUiHost :: () -> LumiUiFrame #foreign host_api;
|
|
WriteLumiUiHost :: (frame: LumiUiFrame) #foreign host_api;
|
|
ReadLumiChatRowHost :: (index: s32) -> LumiChatRow #foreign host_api;
|
|
ReadLumiSuggestionTaskHost :: (index: s32) -> LumiTask #foreign host_api;
|
|
ReadLumiSuggestionHabitHost :: (index: s32) -> LumiTask #foreign host_api;
|
|
LumiViewLocaleHost :: (key: string) -> string #foreign host_api;
|
|
LumiFeedbackChoiceHost :: (id: string, action: s32) -> bool #foreign host_api;
|
|
LumiLoadOlderHost :: () -> bool #foreign host_api;
|
|
LumiDeleteRowHost :: (index: s32) -> bool #foreign host_api;
|
|
LumiFirstVisibleRowHost :: (scroll: s32) -> s32 #foreign host_api;
|
|
LumiRowOffsetHost :: (index: s32) -> s32 #foreign host_api;
|
|
SetLumiOnlineHost :: (online: bool) -> s32 #foreign host_api;
|
|
LumiAgreementHost :: (choice: s32) -> bool #foreign host_api;
|
|
SmoothFramesHost :: (frames: s32) -> bool #foreign host_api;
|
|
OpenLumiSettingsHost :: () -> bool #foreign host_api;
|
|
OpenLinkHost :: (url: string) -> bool #foreign host_api;
|
|
frame: LumiUiFrame;
|
|
// The terms panel's scroll and its formatted text.
|
|
agreement_scroll: s32;
|
|
agreement_bytes: [8192]u8;
|
|
agreement_strong: [32]TextRange;
|
|
chart_selected_key: u64;
|
|
chart_selected_point: s32;
|
|
|
|
// Visible rows are unchanged between frames, and formatting a row or finding
|
|
// its links reads every byte. Each keeps a bounded copy of its source, so
|
|
// scrolling, account changes and edited rows cannot reuse borrowed host text.
|
|
LumiRowText :: struct {
|
|
source: [LUMI_INPUT_MAX]u8
|
|
count: s32
|
|
formatted: bool
|
|
text: LumiMessageText
|
|
links: LumiLinks
|
|
}
|
|
|
|
row_text: [8]LumiRowText;
|
|
draft_intent_source: [LUMI_INPUT_MAX]u8;
|
|
draft_intent_count: s32;
|
|
draft_intent_revision: s64 = -1;
|
|
draft_intent: LumiAction;
|
|
draft_intent_title_count: s32;
|
|
candidate_revision: s64 = -1;
|
|
candidate_actions: [20]LumiAction;
|
|
// Suggestion commands read for the current command set, in order.
|
|
candidate_ready: s32;
|
|
// Reading a command takes many text matches, so typing reads one per frame.
|
|
LUMI_CANDIDATES_PER_FRAME :: 1
|
|
|
|
// Typing "/" lists Lumi's commands as in Telegram. The list matches the
|
|
// command menu of Lumi's Telegram bot, without its Telegram-only commands.
|
|
LumiMenuCommand :: struct {
|
|
name: string
|
|
description: string
|
|
// These commands insert "/name " for the text instead of sending.
|
|
needs_text: bool
|
|
requirement: s32
|
|
// Shown only while Lumi waits for a Diary text or a habit name.
|
|
choice_only: bool
|
|
}
|
|
|
|
LUMI_MENU_COMMANDS :: 15
|
|
menu_revision: s64 = -1;
|
|
menu_commands: [LUMI_MENU_COMMANDS]LumiMenuCommand;
|
|
menu_scroll: s32;
|
|
focus_request: s32;
|
|
// Telegram-style selection: hold a message to select it, then tap messages
|
|
// or drag across them; dragging near the chat's top or bottom scrolls it.
|
|
// Rows are counted from the newest message, which older messages loading
|
|
// above do not change, so a sweep can keep going up through the history.
|
|
// The greeting above every message is kept apart.
|
|
LUMI_SELECT_MAX :: 4096
|
|
selecting: bool;
|
|
selected: [LUMI_SELECT_MAX]bool;
|
|
greeting_selected: bool;
|
|
selected_count: s32;
|
|
sweeping: bool;
|
|
// The row the sweep began on, counted from the newest message; -1 is the
|
|
// greeting.
|
|
sweep_anchor: s32;
|
|
sweep_value: bool;
|
|
// Where the pointer is during a sweep, for scrolling at the chat's edges.
|
|
sweep_pointer_y: float32;
|
|
sweep_seen: bool;
|
|
confirm_delete: bool;
|
|
// Copied text waits until the composer has written its own clipboard state.
|
|
pending_copy: string;
|
|
// Right-clicking a message opens its menu where the pointer was, as in
|
|
// Telegram. The row is kept by its slot, which older history loading above
|
|
// does not change.
|
|
LUMI_MENU_COPY :: 1
|
|
row_menu_open: bool;
|
|
row_menu_slot: s32;
|
|
row_menu_x: float32;
|
|
row_menu_y: float32;
|
|
copy_pending: bool;
|
|
LUMI_CLOSE_ICON :: "S1.8rr:M6 6L18 18M18 6L6 18"
|
|
LUMI_COPY_ICON :: "S1.6rr:M9 9H20V20H9ZM15 5V4H4V15H5"
|
|
LUMI_DELETE_ICON :: "S1.6rr:M3 6H21M9 6V3H15V6M5 6L6 21H18L19 6M10 10V17M14 10V17"
|
|
|
|
// A row's place counted from the newest message; the greeting is -1.
|
|
RowSlot :: (index: s32) -> s32 {
|
|
if index <= 0 {
|
|
return -1
|
|
}
|
|
return frame.chat_count - 1 - index
|
|
}
|
|
|
|
SlotRow :: (slot: s32) -> s32 {
|
|
if slot < 0 {
|
|
return 0
|
|
}
|
|
return frame.chat_count - 1 - slot
|
|
}
|
|
|
|
IsSelected :: (index: s32) -> bool {
|
|
slot := RowSlot(index)
|
|
if slot < 0 {
|
|
return greeting_selected
|
|
}
|
|
return slot < LUMI_SELECT_MAX && selected[slot]
|
|
}
|
|
|
|
SelectionClear :: () {
|
|
for index: cast(s32)0..LUMI_SELECT_MAX - 1 {
|
|
selected[index] = false
|
|
}
|
|
greeting_selected = false
|
|
selected_count = 0
|
|
selecting = false
|
|
sweeping = false
|
|
confirm_delete = false
|
|
}
|
|
|
|
SelectionSet :: (index: s32, value: bool) {
|
|
if index < 0 || index >= frame.chat_count || IsSelected(index) == value {
|
|
return
|
|
}
|
|
slot := RowSlot(index)
|
|
if slot < 0 {
|
|
greeting_selected = value
|
|
} else if slot < LUMI_SELECT_MAX {
|
|
selected[slot] = value
|
|
} else {
|
|
return
|
|
}
|
|
selected_count += ifx value then 1 else -1
|
|
}
|
|
|
|
// A press began on a row: it selects or clears that row, and dragging then
|
|
// gives every row it sweeps over the same state.
|
|
SweepStart :: (index: s32, value: bool) {
|
|
sweeping = true
|
|
sweep_anchor = RowSlot(index)
|
|
sweep_value = value
|
|
SelectionSet(index, value)
|
|
}
|
|
|
|
SweepTo :: (index: s32) {
|
|
if index < 0 {
|
|
index = 0
|
|
}
|
|
if index >= frame.chat_count {
|
|
index = frame.chat_count - 1
|
|
}
|
|
anchor := SlotRow(sweep_anchor)
|
|
first := ifx index < anchor then index else anchor
|
|
last := ifx index < anchor then anchor else index
|
|
for row: first..last {
|
|
SelectionSet(row, sweep_value)
|
|
}
|
|
}
|
|
|
|
// The template with its %d replaced by the count.
|
|
CountText :: (template: string, count: s32) -> string {
|
|
out: Vec(u8)
|
|
at: s64 = 0
|
|
while at < template.count {
|
|
if at + 1 < template.count && template[at] == cast(u8)37 && template[at + 1] == cast(u8)100 {
|
|
BuilderPrint(*out, "%", count)
|
|
at += 2
|
|
} else {
|
|
BuilderPrint(*out, "%", template[at:at + 1])
|
|
at += 1
|
|
}
|
|
}
|
|
return BuilderFinish(out)
|
|
}
|
|
|
|
SelectedText :: () -> string {
|
|
out: Vec(u8)
|
|
written: s32 = 0
|
|
for index: cast(s32)0..frame.chat_count - 1 {
|
|
if !IsSelected(index) {
|
|
continue
|
|
}
|
|
if written > 0 {
|
|
BuilderPrint(*out, "\n\n")
|
|
}
|
|
BuilderPrint(*out, "%", ReadLumiChatRowHost(index).text)
|
|
written += 1
|
|
}
|
|
return BuilderFinish(out)
|
|
}
|
|
|
|
// The bar replacing the top of the chat while messages are selected: close,
|
|
// the count, then copy and delete, with delete asking first.
|
|
SelectionBar :: (x: s32, top: s32, width: s32) {
|
|
control := Scale(44)
|
|
Box(frame.session, BoxProps.{.key = cast(u64)300369,
|
|
.bounds = Bounds(0, 0, frame.width, top + control + Scale(8)),
|
|
.fill = frame.background})
|
|
if confirm_delete {
|
|
Text(frame.session, TextProps.{.key = cast(u64)300370,
|
|
.bounds = Bounds(x, top, width - Scale(216), control),
|
|
.text = LumiViewLocaleHost("lumi_delete_confirm"), .font = frame.font,
|
|
.wrap = cast(TextWrap)TextWrapAuto, .vertical_align = cast(TextAlign)TextAlignCenter})
|
|
if Button(frame.session, ButtonProps.{.id = 30020,
|
|
.bounds = Bounds(x + width - Scale(208), top, Scale(100), control),
|
|
.label = LumiViewLocaleHost("cancel_button"), .fit_content = true,
|
|
.tone = cast(ButtonTone)ButtonToneNeutral, .emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
|
|
confirm_delete = false
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 30021,
|
|
.bounds = Bounds(x + width - Scale(100), top, Scale(100), control),
|
|
.label = LumiViewLocaleHost("delete_button"), .fit_content = true,
|
|
.tone = cast(ButtonTone)ButtonToneDanger, .emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled}) != 0 {
|
|
// From the last row back, so earlier rows keep their indices.
|
|
index := frame.chat_count - 1
|
|
while index >= 0 {
|
|
if IsSelected(index) {
|
|
unused LumiDeleteRowHost(index)
|
|
}
|
|
index -= 1
|
|
}
|
|
SelectionClear()
|
|
}
|
|
return
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 30022, .bounds = Bounds(x, top, control, control),
|
|
.label = LumiViewLocaleHost("lumi_cancel_selection"), .icon_shape = LUMI_CLOSE_ICON, .icon_only = true,
|
|
.tone = cast(ButtonTone)ButtonToneNeutral, .emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0 {
|
|
SelectionClear()
|
|
return
|
|
}
|
|
Box(frame.session, BoxProps.{.key = cast(u64)300371,
|
|
.bounds = Bounds(x + control + Scale(8), top + Scale(6), Scale(150), control - Scale(12)),
|
|
.fill = Color.{156, 188, 143, 48}, .radius = cast(float32)(control - Scale(12)) / 2.0})
|
|
Text(frame.session, TextProps.{.key = cast(u64)300372,
|
|
.bounds = Bounds(x + control + Scale(8), top, Scale(150), control),
|
|
.text = CountText(LumiViewLocaleHost("lumi_selected_count"), selected_count), .font = frame.font,
|
|
.wrap = cast(TextWrap)TextWrapNone, .align = cast(TextAlign)TextAlignCenter,
|
|
.vertical_align = cast(TextAlign)TextAlignCenter})
|
|
if Button(frame.session, ButtonProps.{.id = 30023,
|
|
.bounds = Bounds(x + width - 2 * control - Scale(4), top, control, control),
|
|
.label = LumiViewLocaleHost("lumi_copy"), .icon_shape = LUMI_COPY_ICON, .icon_only = true,
|
|
.tone = cast(ButtonTone)ButtonToneNeutral, .emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0 {
|
|
pending_copy = SelectedText()
|
|
copy_pending = true
|
|
SelectionClear()
|
|
return
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 30024,
|
|
.bounds = Bounds(x + width - control, top, control, control),
|
|
.label = LumiViewLocaleHost("delete_button"), .icon_shape = LUMI_DELETE_ICON, .icon_only = true,
|
|
.tone = cast(ButtonTone)ButtonToneDanger, .emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0 {
|
|
confirm_delete = true
|
|
}
|
|
}
|
|
// A rounded square with a slash, and a paper plane, in Kryon's 24 x 24 icon
|
|
// shape format.
|
|
LUMI_COMMANDS_ICON :: "S1.8rr:M7 3H17C19.2091 3 21 4.79086 21 7V17C21 19.2091 19.2091 21 17 21H7C4.79086 21 3 19.2091 3 17V7C3 4.79086 4.79086 3 7 3Z|S1.8rr:M14.5 7.5L9.5 16.5"
|
|
LUMI_SEND_ICON :: "F:M3.4 20.6L21.2 12.9C21.94 12.58 21.94 11.42 21.2 11.1L3.4 3.4C2.66 3.08 1.9 3.8 2.14 4.57L4.2 11L13 12L4.2 13L2.14 19.43C1.9 20.2 2.66 20.92 3.4 20.6Z"
|
|
|
|
MenuCommands :: (revision: s64) -> []LumiMenuCommand {
|
|
if revision != menu_revision {
|
|
menu_revision = revision
|
|
table: [LUMI_MENU_COMMANDS]LumiMenuCommand = .[
|
|
LumiMenuCommand.{.name = "/help", .description = LumiViewLocaleHost("lumi_command_help")},
|
|
LumiMenuCommand.{.name = "/todo", .description = LumiViewLocaleHost("lumi_add"),
|
|
.needs_text = true, .requirement = LUMI_LISTS},
|
|
LumiMenuCommand.{.name = "/done", .description = LumiViewLocaleHost("lumi_complete"),
|
|
.needs_text = true, .requirement = LUMI_LISTS},
|
|
LumiMenuCommand.{.name = "/reopen", .description = LumiViewLocaleHost("lumi_reopen"),
|
|
.needs_text = true, .requirement = LUMI_LISTS},
|
|
LumiMenuCommand.{.name = "/lists", .description = LumiViewLocaleHost("lumi_open_lists"),
|
|
.requirement = LUMI_LISTS},
|
|
LumiMenuCommand.{.name = "/habit", .description = LumiViewLocaleHost("lumi_complete_habit"),
|
|
.requirement = LUMI_HABITS},
|
|
LumiMenuCommand.{.name = "/habits", .description = LumiViewLocaleHost("lumi_open_habits"),
|
|
.requirement = LUMI_HABITS},
|
|
LumiMenuCommand.{.name = "/journal", .description = LumiViewLocaleHost("lumi_write_diary"),
|
|
.requirement = LUMI_DIARY},
|
|
LumiMenuCommand.{.name = "/diary", .description = LumiViewLocaleHost("lumi_open_diary"),
|
|
.requirement = LUMI_DIARY},
|
|
LumiMenuCommand.{.name = "/meditate", .description = LumiViewLocaleHost("lumi_start_meditation"),
|
|
.requirement = LUMI_PRACTICES},
|
|
LumiMenuCommand.{.name = "/whm", .description = LumiViewLocaleHost("lumi_start_whm"),
|
|
.requirement = LUMI_PRACTICES},
|
|
LumiMenuCommand.{.name = "/practices", .description = LumiViewLocaleHost("lumi_open_practices"),
|
|
.requirement = LUMI_PRACTICES},
|
|
LumiMenuCommand.{.name = "/progress", .description = LumiViewLocaleHost("lumi_show_progress"),
|
|
.requirement = LUMI_PRACTICES},
|
|
LumiMenuCommand.{.name = "/feedback", .description = LumiViewLocaleHost("lumi_command_feedback"),
|
|
.needs_text = true},
|
|
LumiMenuCommand.{.name = "/cancel", .description = LumiViewLocaleHost("cancel_button"),
|
|
.choice_only = true}]
|
|
menu_commands = table
|
|
}
|
|
return menu_commands[:]
|
|
}
|
|
|
|
// A draft of "/" and a command name opens the list; a space closes it,
|
|
// since the command then takes its text.
|
|
MenuOpen :: (value: string) -> bool {
|
|
if value.count == 0 || value[0] != cast(u8)47 {
|
|
return false
|
|
}
|
|
for byte: value {
|
|
if CommandSpace(byte) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
CommandText :: (command: LumiMenuCommand) -> string {
|
|
if !command.needs_text {
|
|
return command.name
|
|
}
|
|
out: Vec(u8)
|
|
BuilderPrint(*out, "% ", command.name)
|
|
return BuilderFinish(out)
|
|
}
|
|
|
|
FillDraft :: (text: string) {
|
|
frame.value = text
|
|
frame.cursor = cast(s32)text.count
|
|
frame.anchor = frame.cursor
|
|
frame.input_scroll = 0
|
|
frame.selecting = false
|
|
frame.preferred_x_valid = false
|
|
frame.focused = true
|
|
}
|
|
|
|
// Interpretation depends on the draft and translated command set. Cursor
|
|
// blinking, scrolling and unchanged frames reuse the result, while sending
|
|
// still validates the request against the current tools in LumiRespond.
|
|
DraftIntent :: (value: string, commands: LumiCommands, revision: s64) -> LumiAction {
|
|
if revision != draft_intent_revision ||
|
|
value != TextFromBytes(draft_intent_source[:draft_intent_count]) {
|
|
draft_intent_count = 0
|
|
if CopyCString(value, draft_intent_source[:]) {
|
|
draft_intent_count = cast(s32)value.count
|
|
}
|
|
draft_intent_revision = revision
|
|
action := LumiIntent(value, commands)
|
|
draft_intent = LumiAction.{.kind = action.kind, .route = action.route, .practice = action.practice}
|
|
draft_intent_title_count = cast(s32)action.title.count
|
|
}
|
|
action := draft_intent
|
|
// Intent titles are suffixes of the trimmed request. Retain their length,
|
|
// then return a view of this frame's value rather than a cached text view.
|
|
action.title = value[value.count - draft_intent_title_count:]
|
|
return action
|
|
}
|
|
|
|
// A row's words as drawn, Lumi's formatted and a person's as written, with
|
|
// the web links in them.
|
|
RowText :: (index: s32, value: string, formatted: bool) -> *LumiRowText {
|
|
slot := *row_text[index % cast(s32)row_text.count]
|
|
if slot.formatted != formatted || value != TextFromBytes(slot.source[:slot.count]) {
|
|
slot.formatted = formatted
|
|
slot.text = LumiFormatMessage(value, formatted)
|
|
slot.links = LumiMessageLinks(TextFromBytes(slot.text.bytes[:slot.text.count]))
|
|
slot.count = 0
|
|
if CopyCString(value, slot.source[:]) {
|
|
slot.count = cast(s32)value.count
|
|
}
|
|
}
|
|
return slot
|
|
}
|
|
|
|
Scale :: (value: s32) -> s32 {
|
|
return cast(s32)(cast(float32)value * frame.scale)
|
|
}
|
|
|
|
Bounds :: (x: s32, y: s32, width: s32, height: s32) -> Rectangle {
|
|
return Rectangle.{cast(float32)x, cast(float32)y, cast(float32)width, cast(float32)height}
|
|
}
|
|
|
|
Suggestion :: (id: s32, text: string, bounds: Rectangle, label: string = "") -> bool {
|
|
if Button(frame.session, ButtonProps.{.id = id, .bounds = bounds,
|
|
.label = ifx label.count > 0 then label else text, .pill = true, .tone = cast(ButtonTone)ButtonToneNeutral,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
|
|
FillDraft(text)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
ChartDate :: (date: s32) -> string {
|
|
out: Vec(u8)
|
|
month := date / 100 % 100
|
|
day := date % 100
|
|
BuilderPrint(*out, "%-", date / 10000)
|
|
BuilderPrint(*out, "%", ifx month < 10 then "0" else "")
|
|
BuilderPrint(*out, "%-", month)
|
|
BuilderPrint(*out, "%", ifx day < 10 then "0" else "")
|
|
BuilderPrint(*out, "%", day)
|
|
// Keep date labels independent of the host's locale and timezone.
|
|
text := BuilderFinish(out)
|
|
return text
|
|
}
|
|
|
|
ProgressCard :: (row: LumiChatRow, index: s32, x: s32, y: s32, width: s32) {
|
|
chart := LumiChartRead(row.payload)
|
|
if !chart.valid {
|
|
return
|
|
}
|
|
key := 330000 + index * 64
|
|
selection_key := KeyHash(row.payload)
|
|
selected := ifx chart_selected_key == selection_key then chart_selected_point else 0
|
|
if selected < 0 || selected >= chart.count {
|
|
selected = 0
|
|
}
|
|
plot_y := y + Scale(30)
|
|
plot_height := Scale(130)
|
|
step := cast(float32)width / cast(float32)chart.count
|
|
for point: cast(s32)0..chart.count - 1 {
|
|
left := x + cast(s32)(cast(float32)point * step)
|
|
bar_width := cast(s32)step - Scale(2)
|
|
if bar_width < 1 {
|
|
bar_width = 1
|
|
}
|
|
bar_height: s32 = 0
|
|
if chart.maximum > 0 {
|
|
bar_height = cast(s32)(cast(float64)chart.values[point] / cast(float64)chart.maximum * cast(float64)plot_height)
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 310000 + index * 32 + point,
|
|
.bounds = Bounds(left, plot_y, cast(s32)step, plot_height), .invisible = true}) != 0 {
|
|
selected = point
|
|
chart_selected_key = selection_key
|
|
chart_selected_point = point
|
|
}
|
|
Box(frame.session, BoxProps.{.key = cast(u64)(key + point),
|
|
.bounds = Bounds(left, plot_y + plot_height - bar_height, bar_width, bar_height),
|
|
.fill = ifx selected == point then Color.{93, 148, 110, 255} else Color.{156, 188, 143, 200},
|
|
.radius = cast(float32)Scale(2)})
|
|
}
|
|
Box(frame.session, BoxProps.{.key = cast(u64)(key + 31),
|
|
.bounds = Bounds(x, plot_y + plot_height, width, Scale(1)), .fill = Color.{156, 156, 156, 120}})
|
|
summary: Vec(u8)
|
|
BuilderPrint(*summary, "% · %", ChartDate(chart.dates[selected]), chart.values[selected])
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 32),
|
|
.bounds = Bounds(x, y, width, Scale(24)), .text = BuilderFinish(summary), .font = Scale(14)})
|
|
half := width / 2
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 33),
|
|
.bounds = Bounds(x, plot_y + plot_height + Scale(6), half, Scale(22)),
|
|
.text = ChartDate(chart.dates[0]), .font = Scale(12)})
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 34),
|
|
.bounds = Bounds(x + half, plot_y + plot_height + Scale(6), width - half, Scale(22)),
|
|
.text = ChartDate(chart.dates[chart.count - 1]), .font = Scale(12)})
|
|
if chart.maximum == 0 {
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 35),
|
|
.bounds = Bounds(x, y + Scale(196), width, Scale(40)),
|
|
.text = LumiViewLocaleHost("lumi_chart_empty"), .font = Scale(14)})
|
|
}
|
|
}
|
|
|
|
// Like a Telegram reply, the developer's reply quotes the feedback it
|
|
// answers: a green bar beside "Your feedback" and the feedback's title.
|
|
FeedbackQuote :: (row: LumiChatRow, index: s32, x: s32, y: s32, width: s32) {
|
|
key := 440000 + index * 4
|
|
quote_height := Scale(LUMI_QUOTE_HEIGHT - 8)
|
|
Box(frame.session, BoxProps.{.key = cast(u64)key,
|
|
.bounds = Bounds(x + Scale(12), y, width - Scale(24), quote_height),
|
|
.fill = Color.{93, 148, 110, 40}, .radius = cast(float32)Scale(6)})
|
|
Box(frame.session, BoxProps.{.key = cast(u64)(key + 1),
|
|
.bounds = Bounds(x + Scale(12), y, Scale(3), quote_height),
|
|
.fill = Color.{93, 148, 110, 255}, .radius = cast(float32)Scale(2)})
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 2),
|
|
.bounds = Bounds(x + Scale(24), y + Scale(3), width - Scale(40), Scale(16)),
|
|
.text = LumiViewLocaleHost("lumi_your_feedback"), .font = Scale(12),
|
|
.wrap = cast(TextWrap)TextWrapEllipsis})
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 3),
|
|
.bounds = Bounds(x + Scale(24), y + Scale(20), width - Scale(40), Scale(18)),
|
|
.text = row.quote, .font = Scale(13),
|
|
.wrap = cast(TextWrap)TextWrapEllipsis})
|
|
}
|
|
|
|
// Lumi's bubble with three dots that brighten and rise in turn, where its
|
|
// answer will appear.
|
|
TypingDots :: (x: s32, top: s32) {
|
|
left := x + Scale(48)
|
|
Image(frame.session, ImageProps.{.key = cast(u64)300380,
|
|
.asset_path = "assets/lumi/mascot.webp", .alt_text = "Lumi",
|
|
.bounds = Bounds(x, top + Scale(16), Scale(40), Scale(40)),
|
|
.source = Rectangle.{0.0, 0.0, -1254.0, 1254.0},
|
|
.fit = cast(ImageFit)ImageFitContain})
|
|
Box(frame.session, BoxProps.{.key = cast(u64)300381,
|
|
.bounds = Bounds(left, top, Scale(96), Scale(60)),
|
|
.fill = Color.{156, 156, 156, 24}, .radius = cast(float32)Scale(16)})
|
|
Text(frame.session, TextProps.{.key = cast(u64)300382,
|
|
.bounds = Bounds(left + Scale(14), top + Scale(8), Scale(68), Scale(20)),
|
|
.text = "Lumi", .font = Scale(12)})
|
|
// Kryon's loading dots, the same animation every app shows.
|
|
LoadingIndicator(frame.session, LoadingIndicatorProps.{.key = cast(u64)300383,
|
|
.bounds = Bounds(left + Scale(16), top + Scale(34), Scale(36), Scale(12)),
|
|
.now = frame.now, .scale = frame.scale})
|
|
}
|
|
|
|
// Tapped, Lumi swirls twice around her place beside her message, for fun:
|
|
// the loops widen and settle back where she sits.
|
|
LUMI_SWIRL_SECONDS :: 1.2
|
|
swirl_row: s32 = -1;
|
|
swirl_started: float64;
|
|
|
|
LumiAvatar :: (index: s32, x: s32, y: s32) {
|
|
bounds := Bounds(x, y, Scale(40), Scale(40))
|
|
if swirl_row == index {
|
|
t := (frame.now - swirl_started) / LUMI_SWIRL_SECONDS
|
|
if t < 0.0 || t >= 1.0 {
|
|
swirl_row = -1
|
|
} else {
|
|
eased := t * t * (3.0 - 2.0 * t)
|
|
angle := cast(float32)(eased * 720.0)
|
|
radius := cast(float32)Scale(14) * SineDegrees(cast(float32)(t * 180.0))
|
|
bounds.x += radius * SineDegrees(angle)
|
|
bounds.y -= radius - radius * CosineDegrees(angle)
|
|
}
|
|
}
|
|
Image(frame.session, ImageProps.{.key = cast(u64)(300400 + index * 4),
|
|
.asset_path = "assets/lumi/mascot.webp", .alt_text = "Lumi",
|
|
.bounds = bounds, .source = Rectangle.{0.0, 0.0, -1254.0, 1254.0},
|
|
.fit = cast(ImageFit)ImageFitContain})
|
|
press := Press(frame.session, PressProps.{.key = cast(u64)(430000 + RowSlot(index) + 1),
|
|
.bounds = Bounds(x, y, Scale(40), Scale(40)), .label = "Lumi", .now = frame.now})
|
|
if press.clicked {
|
|
swirl_row = index
|
|
swirl_started = frame.now
|
|
unused SmoothFramesHost(80)
|
|
}
|
|
}
|
|
|
|
// A row's press: a hold starts selecting, and while selecting a press starts
|
|
// a sweep that follows the pointer, even off the row and past the chat.
|
|
RowPress :: (index: s32, bounds: Rectangle, content_y: float32) -> PressResult {
|
|
key := ifx index == 0 then 0 else RowSlot(index) + 1
|
|
press := Press(frame.session, PressProps.{.key = cast(u64)(410000 + key), .bounds = bounds,
|
|
.label = LumiViewLocaleHost("lumi_message"), .now = frame.now, .capture = selecting})
|
|
if !selecting && press.held {
|
|
selecting = true
|
|
confirm_delete = false
|
|
SweepStart(index, true)
|
|
} else if selecting && press.down && !sweeping {
|
|
SweepStart(index, !IsSelected(index))
|
|
}
|
|
if sweeping && press.down {
|
|
sweep_seen = true
|
|
sweep_pointer_y = press.y
|
|
SweepTo(LumiFirstVisibleRowHost(cast(s32)(press.y - content_y)))
|
|
}
|
|
if press.released {
|
|
sweeping = false
|
|
}
|
|
if press.right_clicked && !selecting {
|
|
row_menu_open = true
|
|
row_menu_slot = RowSlot(index)
|
|
row_menu_x = press.x
|
|
row_menu_y = press.y
|
|
}
|
|
return press
|
|
}
|
|
|
|
// The menu a right click opens on a message. Returns the row whose words
|
|
// Copy puts on the clipboard, or -1.
|
|
RowMenu :: () -> s32 {
|
|
if !row_menu_open {
|
|
return -1
|
|
}
|
|
index := SlotRow(row_menu_slot)
|
|
if selecting || index < 0 || index >= frame.chat_count {
|
|
row_menu_open = false
|
|
return -1
|
|
}
|
|
items: [1]ContextMenuItem = .[ContextMenuItem.{.id = LUMI_MENU_COPY, .label = LumiViewLocaleHost("lumi_copy")}]
|
|
menu := ContextMenu(frame.session, ContextMenuProps.{.key = cast(u64)380000, .open = true,
|
|
.x = row_menu_x, .y = row_menu_y, .scale = frame.scale}, items[:])
|
|
if !menu.open {
|
|
row_menu_open = false
|
|
}
|
|
return ifx menu.activated_id == LUMI_MENU_COPY then index else -1
|
|
}
|
|
|
|
// Lumi's title bar: its name, a connection button that switches between
|
|
// offline and online, and a wrench that opens Lumi's settings. Returns the
|
|
// bar's height.
|
|
LumiTitleBar :: () -> s32 {
|
|
height := Scale(52)
|
|
button := Scale(40)
|
|
gap := Scale(4)
|
|
trailing := ifx frame.connection then 2 * button + gap else 0
|
|
options: [1]DropdownOption
|
|
bar := TitleBar(frame.session, TitleBarProps.{.key = cast(u64)300400, .title = "Lumi",
|
|
.bounds = Bounds(0, 0, frame.width, height), .height = height, .scale = frame.scale,
|
|
.trailing_width = trailing}, options[0:0])
|
|
if !frame.connection || bar.trailing_bounds.width <= 0.0 {
|
|
return height
|
|
}
|
|
area := bar.trailing_bounds
|
|
top := area.y + (area.height - cast(float32)button) / 2.0
|
|
size := cast(float32)button
|
|
// Its label says whether Lumi is online now.
|
|
state := ifx frame.online then "lumi_toggle_online" else "lumi_toggle_offline"
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)300401, .id = 30040,
|
|
.bounds = Rectangle.{area.x + area.width - 2.0 * size - cast(float32)gap, top, size, size},
|
|
.label = LumiViewLocaleHost(state), .selected = frame.online,
|
|
.icon_shape = ifx frame.online then ConnectedIcon.Shape else DisconnectedIcon.Shape,
|
|
.icon_only = true, .tone = cast(ButtonTone)ButtonToneNeutral,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0 {
|
|
// Going online without the agreement opens the terms instead.
|
|
unused SetLumiOnlineHost(!frame.online)
|
|
}
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)300390, .id = 30043,
|
|
.bounds = Rectangle.{area.x + area.width - size, top, size, size},
|
|
.label = LumiViewLocaleHost("settings_title"), .icon_shape = ConfigureIcon.Shape,
|
|
.icon_only = true, .tone = cast(ButtonTone)ButtonToneNeutral,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0 {
|
|
unused OpenLumiSettingsHost()
|
|
}
|
|
return height
|
|
}
|
|
|
|
// The terms Lumi asks to agree to before going online, or shows again from
|
|
// Settings with a way to withdraw.
|
|
LumiAgreementView :: (top: s32) {
|
|
column := CenteredColumnFor(frame.width, Scale(720), Scale(16))
|
|
buttons_top := frame.height - frame.bottom - Scale(16) - Scale(48)
|
|
area_height := buttons_top - Scale(12) - top
|
|
if area_height < Scale(60) {
|
|
area_height = Scale(60)
|
|
}
|
|
counts := LumiFormatInto(frame.agreement_text, true, agreement_bytes[:], agreement_strong[:])
|
|
panel := Scroll(frame.session, ScrollProps.{.key = cast(u64)300410,
|
|
.bounds = Bounds(column.x, top, column.width, area_height),
|
|
.content_height = frame.agreement_height, .scroll_offset = agreement_scroll,
|
|
.scale = frame.scale})
|
|
agreement_scroll = panel.scroll_offset
|
|
if panel.opened {
|
|
// The host measured the terms at this width, clear of the scroll bar.
|
|
Text(frame.session, TextProps.{.key = cast(u64)300411,
|
|
.bounds = Rectangle.{panel.content.x, panel.content.y,
|
|
cast(float32)(column.width - Scale(24)), cast(float32)frame.agreement_height},
|
|
.text = TextFromBytes(agreement_bytes[:counts.count]), .font = frame.font,
|
|
.strong = agreement_strong[:counts.strong_count], .wrap = cast(TextWrap)TextWrapAuto})
|
|
unused End(frame.session)
|
|
}
|
|
reading := frame.agreement == 2
|
|
half := (column.width - Scale(12)) / 2
|
|
first := ifx reading then "lumi_agreement_withdraw" else "lumi_agreement_agree"
|
|
second := ifx reading then "close_button" else "lumi_agreement_later"
|
|
if Button(frame.session, ButtonProps.{.id = 30041,
|
|
.bounds = Bounds(column.x, buttons_top, half, Scale(48)),
|
|
.label = LumiViewLocaleHost(first),
|
|
.tone = cast(ButtonTone)(ifx reading then ButtonToneDanger else ButtonToneAccent),
|
|
.emphasis = cast(ButtonEmphasis)(ifx reading then ButtonEmphasisSoft else ButtonEmphasisFilled)}) != 0 {
|
|
agreement_scroll = 0
|
|
unused LumiAgreementHost(ifx reading then 3 else 1)
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 30042,
|
|
.bounds = Bounds(column.x + half + Scale(12), buttons_top, half, Scale(48)),
|
|
.label = LumiViewLocaleHost(second), .tone = cast(ButtonTone)ButtonToneNeutral,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
|
|
agreement_scroll = 0
|
|
unused LumiAgreementHost(ifx reading then 4 else 2)
|
|
}
|
|
}
|
|
|
|
LumiView :: (message: LumiMessage, commands: LumiCommands, revision: s64) -> LumiMessage {
|
|
frame = ReadLumiUiHost()
|
|
title_height := LumiTitleBar()
|
|
if frame.agreement != 0 {
|
|
LumiAgreementView(title_height + Scale(8))
|
|
WriteLumiUiHost(frame)
|
|
return message
|
|
}
|
|
column := CenteredColumnFor(frame.width, Scale(720), Scale(16))
|
|
x := column.x
|
|
width := column.width
|
|
input_height := Scale(48)
|
|
measured_height := frame.draft_height + Scale(24)
|
|
if measured_height > input_height {
|
|
input_height = measured_height
|
|
}
|
|
if input_height > Scale(144) {
|
|
input_height = Scale(144)
|
|
}
|
|
footer := frame.height - frame.bottom - Scale(16) - input_height
|
|
suggestions_top := footer - Scale(ifx LumiTrim(frame.value).count > 0 then 46 else 0)
|
|
history_top := title_height + Scale(8)
|
|
menu := MenuCommands(revision)
|
|
menu_matches: [LUMI_MENU_COMMANDS]s32
|
|
menu_count: s32 = 0
|
|
// Enter chooses the exact command, otherwise the first one listed.
|
|
menu_target: s32 = -1
|
|
if MenuOpen(frame.value) {
|
|
for index: cast(s32)0..LUMI_MENU_COMMANDS - 1 {
|
|
command := menu[index]
|
|
if (command.requirement != 0 && (frame.available_apps & command.requirement) == 0) ||
|
|
(command.choice_only && !frame.choosing_habit && !frame.choosing_diary) ||
|
|
!LumiStarts(command.name, frame.value) {
|
|
continue
|
|
}
|
|
if menu_target < 0 || LumiEqual(command.name, frame.value) {
|
|
menu_target = menu_count
|
|
}
|
|
menu_matches[menu_count] = index
|
|
menu_count += 1
|
|
}
|
|
}
|
|
menu_row := Scale(44)
|
|
menu_height := menu_count * menu_row
|
|
// Four and a half rows show that a longer list scrolls.
|
|
if menu_height > menu_row * 9 / 2 {
|
|
menu_height = menu_row * 9 / 2
|
|
}
|
|
if menu_count > 0 && footer - Scale(8) - menu_height - history_top < Scale(68) {
|
|
menu_height = footer - Scale(8) - history_top - Scale(68)
|
|
if menu_height < menu_row {
|
|
menu_height = menu_row
|
|
}
|
|
}
|
|
menu_top := footer - Scale(8) - menu_height
|
|
if menu_count > 0 {
|
|
suggestions_top = menu_top
|
|
} else {
|
|
menu_scroll = 0
|
|
}
|
|
chat_height := suggestions_top - history_top - Scale(8)
|
|
if chat_height < Scale(60) {
|
|
chat_height = Scale(60)
|
|
}
|
|
if frame.follow_end {
|
|
frame.scroll = 1000000
|
|
}
|
|
// While Lumi answers, its typing dots follow the last message after a
|
|
// short pause.
|
|
typing := frame.waiting && !frame.typing_pause
|
|
typing_height := ifx typing then Scale(70) else 0
|
|
history := Scroll(frame.session, ScrollProps.{.key = cast(u64)300100,
|
|
.bounds = Bounds(x, history_top, width, chat_height),
|
|
.content_height = frame.history_height + typing_height, .scroll_offset = frame.scroll, .scale = frame.scale})
|
|
frame.scroll = history.scroll_offset
|
|
frame.follow_end = history.scroll_offset == history.max_scroll
|
|
// Older messages load when the chat reaches its top, and at once while
|
|
// the loaded ones do not fill the chat, which then cannot scroll.
|
|
load_older := frame.has_older &&
|
|
(history.max_scroll <= 0 || (!frame.follow_end && frame.scroll <= Scale(96)))
|
|
anchor_drawn := false
|
|
if history.opened {
|
|
first := LumiFirstVisibleRowHost(history.scroll_offset)
|
|
top := cast(s32)history.content.y + LumiRowOffsetHost(first)
|
|
for index: first..frame.chat_count - 1 {
|
|
if top > history_top + chat_height {
|
|
break
|
|
}
|
|
row := ReadLumiChatRowHost(index)
|
|
row_height := row.height
|
|
bubble_width := width - Scale(ifx row.user then 60 else 80)
|
|
left := x + Scale(48)
|
|
// The whole row takes holds and sweeps; its buttons sit above it.
|
|
row_press := RowPress(index, Bounds(x, top, width, row_height - Scale(10)), history.content.y)
|
|
if RowSlot(index) == sweep_anchor {
|
|
anchor_drawn = true
|
|
}
|
|
if selecting {
|
|
checked := IsSelected(index)
|
|
toggled := Checkbox(frame.session, CheckboxProps.{.key = cast(u64)(420000 + RowSlot(index) + 1),
|
|
.bounds = Bounds(x + Scale(8), top + (row_height - Scale(10)) / 2 - Scale(12), Scale(24), Scale(24)),
|
|
.label = LumiViewLocaleHost("lumi_message"), .checked = checked})
|
|
if toggled.changed {
|
|
SelectionSet(index, toggled.checked)
|
|
}
|
|
} else if !row.user && !row.developer {
|
|
LumiAvatar(index, x, top + row_height - Scale(54))
|
|
}
|
|
Box(frame.session, BoxProps.{.key = cast(u64)(300401 + index * 4),
|
|
.bounds = Bounds(left, top, bubble_width, row_height - Scale(10)),
|
|
.fill = ifx row.user then Color.{156, 188, 143, 48} else Color.{156, 156, 156, 24},
|
|
.radius = cast(float32)Scale(16)})
|
|
if !row.user {
|
|
Text(frame.session, TextProps.{.key = cast(u64)(300402 + index * 4),
|
|
.bounds = Bounds(left + Scale(14), top + Scale(8),
|
|
bubble_width - Scale(28), Scale(20)),
|
|
.text = ifx row.developer then LumiViewLocaleHost("lumi_developer") else "Lumi",
|
|
.font = Scale(12)})
|
|
}
|
|
from_telegram := row.user && row.kind == LUMI_CHAT_TEXT && row.payload == "telegram"
|
|
if from_telegram {
|
|
Text(frame.session, TextProps.{.key = cast(u64)(300408 + index * 4),
|
|
.bounds = Bounds(left + Scale(14), top + Scale(8),
|
|
bubble_width - Scale(28), Scale(16)),
|
|
.text = LumiViewLocaleHost("lumi_from_telegram"), .font = Scale(11)})
|
|
}
|
|
text_top := Scale(ifx row.user then (ifx from_telegram then 30 else 12) else 32)
|
|
if row.developer && row.quote.count > 0 {
|
|
FeedbackQuote(row, index, left, top + text_top, bubble_width)
|
|
text_top += Scale(LUMI_QUOTE_HEIGHT)
|
|
}
|
|
card_height := Scale(ifx row.kind == LUMI_CHAT_PROGRESS then 242 else
|
|
ifx row.kind == LUMI_CHAT_FEEDBACK then 54 else 0)
|
|
text_height := row_height - text_top - Scale(16) - card_height
|
|
props := TextProps.{.key = cast(u64)(300403 + index * 4),
|
|
.bounds = Bounds(left + Scale(14), top + text_top,
|
|
bubble_width - Scale(28), text_height),
|
|
.text = row.text, .font = frame.font,
|
|
.selectable = !selecting,
|
|
.wrap = cast(TextWrap)TextWrapAuto}
|
|
drawn := RowText(index, row.text, !row.user)
|
|
props.text = TextFromBytes(drawn.text.bytes[:drawn.text.count])
|
|
props.strong = drawn.text.strong[:drawn.text.strong_count]
|
|
// Web links are part of the words, in the theme's link color,
|
|
// and a tap on one opens it, as in a chat app.
|
|
links := drawn.links
|
|
link_ranges: [LUMI_LINKS_MAX]TextRange
|
|
for link: cast(s32)0..links.count - 1 {
|
|
link_ranges[link] = TextRange.{links.items[link].start, links.items[link].end}
|
|
}
|
|
props.links = link_ranges[:links.count]
|
|
Text(frame.session, props)
|
|
if row_press.clicked && !selecting && links.count > 0 {
|
|
tapped := TextLinkAt(frame.session, props, row_press.x, row_press.y)
|
|
if tapped >= 0 {
|
|
unused OpenLinkHost(props.text[link_ranges[tapped].start:link_ranges[tapped].end])
|
|
}
|
|
}
|
|
card_top := top + text_top + text_height + Scale(8)
|
|
if row.kind == LUMI_CHAT_PROGRESS {
|
|
ProgressCard(row, index, left + Scale(14), card_top, bubble_width - Scale(28))
|
|
} else if row.kind == LUMI_CHAT_FEEDBACK {
|
|
pending := LumiFeedbackChoiceHost(row.payload, 0)
|
|
if Button(frame.session, ButtonProps.{.id = 351000 + index * 2,
|
|
.bounds = Bounds(left + Scale(14), card_top, Scale(88), Scale(44)),
|
|
.label = LumiViewLocaleHost("lumi_feedback_yes"), .disabled = !pending}) != 0 {
|
|
unused LumiFeedbackChoiceHost(row.payload, 1)
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 351001 + index * 2,
|
|
.bounds = Bounds(left + Scale(108), card_top, Scale(88), Scale(44)),
|
|
.label = LumiViewLocaleHost("lumi_feedback_no"), .disabled = !pending}) != 0 {
|
|
unused LumiFeedbackChoiceHost(row.payload, 2)
|
|
}
|
|
}
|
|
top += row_height
|
|
}
|
|
if typing {
|
|
TypingDots(x, cast(s32)history.content.y + frame.history_height)
|
|
}
|
|
// Scrolling can carry the row the sweep began on out of view; its
|
|
// press stays registered so the sweep goes on.
|
|
if sweeping && !anchor_drawn {
|
|
anchor := SlotRow(sweep_anchor)
|
|
if anchor >= 0 && anchor < frame.chat_count {
|
|
anchor_top := cast(s32)history.content.y + LumiRowOffsetHost(anchor)
|
|
unused RowPress(anchor, Bounds(x, anchor_top, width,
|
|
ReadLumiChatRowHost(anchor).height - Scale(10)), history.content.y)
|
|
}
|
|
}
|
|
End(frame.session)
|
|
}
|
|
// Dragging near the chat's top or bottom scrolls it, faster nearer the
|
|
// edge, so a sweep can reach every message.
|
|
if sweeping && sweep_seen {
|
|
edge := cast(float32)Scale(56)
|
|
top_edge := cast(float32)Scale(60) + edge
|
|
bottom_edge := cast(float32)(history_top + chat_height) - edge
|
|
if sweep_pointer_y < top_edge {
|
|
step := cast(s32)((top_edge - sweep_pointer_y) / 3.0) + Scale(4)
|
|
if step > Scale(40) {
|
|
step = Scale(40)
|
|
}
|
|
frame.scroll -= step
|
|
if frame.scroll < 0 {
|
|
frame.scroll = 0
|
|
}
|
|
frame.follow_end = false
|
|
} else if sweep_pointer_y > bottom_edge {
|
|
step := cast(s32)((sweep_pointer_y - bottom_edge) / 3.0) + Scale(4)
|
|
if step > Scale(40) {
|
|
step = Scale(40)
|
|
}
|
|
frame.scroll += step
|
|
}
|
|
}
|
|
sweep_seen = false
|
|
if selecting && selected_count <= 0 && !sweeping {
|
|
SelectionClear()
|
|
}
|
|
if selecting {
|
|
SelectionBar(x, Scale(12), width)
|
|
// Like Telegram, the selection bar covers the title bar while
|
|
// messages are selected.
|
|
}
|
|
typed := LumiTrim(frame.value)
|
|
candidates: [20]string = .[commands.start_whm, commands.complete_habit,
|
|
commands.start_meditation, commands.start_sun, commands.start_patterns,
|
|
commands.add, commands.complete, commands.reopen,
|
|
commands.lists, commands.habits, commands.practices, commands.diary,
|
|
commands.settings, commands.appearance, commands.dark, commands.light, commands.system, commands.write_diary,
|
|
commands.progress, commands.start_taichi]
|
|
requirements: [20]s32 = .[LUMI_PRACTICES, LUMI_HABITS, LUMI_PRACTICES,
|
|
LUMI_PRACTICES, LUMI_PRACTICES, LUMI_LISTS, LUMI_LISTS, LUMI_LISTS,
|
|
LUMI_LISTS, LUMI_HABITS, LUMI_PRACTICES, LUMI_DIARY, 0, 0, 0, 0, 0, LUMI_DIARY, LUMI_PRACTICES, LUMI_PRACTICES]
|
|
suggestion_count: s32 = 0
|
|
selected: bool
|
|
// The command list replaces the suggestion chips while it is open.
|
|
limit: s32 = ifx menu_count > 0 then 0 else 2
|
|
chip_width := (width - Scale(8)) / 2
|
|
action := DraftIntent(typed, commands, revision)
|
|
if action.kind == 0 && frame.choosing_habit {
|
|
action = LumiAction.{.kind = LUMI_COMPLETE_HABIT, .title = typed}
|
|
}
|
|
if typed.count > 0 && !frame.choosing_diary && LumiActionAvailable(action, frame.available_apps) &&
|
|
(action.kind == LUMI_COMPLETE_TODO || action.kind == LUMI_REOPEN_TODO || action.kind == LUMI_COMPLETE_HABIT) {
|
|
count := ifx action.kind == LUMI_COMPLETE_HABIT then frame.habit_count else frame.task_count
|
|
for index: cast(s32)0..count - 1 {
|
|
if suggestion_count >= limit {
|
|
break
|
|
}
|
|
task := ifx action.kind == LUMI_COMPLETE_HABIT then ReadLumiSuggestionHabitHost(index) else ReadLumiSuggestionTaskHost(index)
|
|
eligible := action.kind == LUMI_COMPLETE_HABIT || (action.kind == LUMI_COMPLETE_TODO && !task.done) ||
|
|
(action.kind == LUMI_REOPEN_TODO && task.done)
|
|
if !eligible || !LumiStarts(task.title, action.title) || suggestion_count >= limit {
|
|
continue
|
|
}
|
|
out: Vec(u8)
|
|
command := commands.reopen
|
|
if action.kind == LUMI_COMPLETE_HABIT {
|
|
command = commands.complete_habit
|
|
} else if action.kind == LUMI_COMPLETE_TODO {
|
|
command = commands.complete
|
|
}
|
|
BuilderPrint(*out, "% %", command, task.title)
|
|
completion := BuilderFinish(out)
|
|
selected = Suggestion(30020 + suggestion_count, completion,
|
|
Bounds(x + suggestion_count * (chip_width + Scale(8)), suggestions_top, chip_width, Scale(36)), task.title) || selected
|
|
suggestion_count += 1
|
|
}
|
|
}
|
|
// Suggestions are offered only for typed text, so their commands are read
|
|
// once typing starts and opening Lumi never waits for them.
|
|
if revision != candidate_revision {
|
|
candidate_revision = revision
|
|
candidate_ready = 0
|
|
}
|
|
if typed.count > 0 {
|
|
prepared: s32 = 0
|
|
while candidate_ready < cast(s32)candidates.count && prepared < LUMI_CANDIDATES_PER_FRAME {
|
|
candidate_actions[candidate_ready] = LumiIntent(candidates[candidate_ready], commands)
|
|
candidate_ready += 1
|
|
prepared += 1
|
|
}
|
|
}
|
|
for index: cast(s32)0..cast(s32)candidates.count - 1 {
|
|
if typed.count == 0 || frame.choosing_diary || action.kind == LUMI_COMPLETE_HABIT || suggestion_count >= limit ||
|
|
index >= candidate_ready {
|
|
break
|
|
}
|
|
candidate_action := candidate_actions[index]
|
|
practice_match := action.kind == LUMI_START_PRACTICE && candidate_action.kind == LUMI_START_PRACTICE &&
|
|
action.practice == candidate_action.practice
|
|
// A practice this build does not offer, such as paid ones on Google Play, is not suggested.
|
|
hidden_practice := candidate_action.kind == LUMI_START_PRACTICE &&
|
|
(frame.practices_hidden & (1 << candidate_action.practice)) != 0
|
|
if hidden_practice || (requirements[index] != 0 && (frame.available_apps & requirements[index]) == 0) || suggestion_count >= limit ||
|
|
(typed.count > 0 && !LumiSuggests(candidates[index], typed) && !practice_match) {
|
|
continue
|
|
}
|
|
text := candidates[index]
|
|
if index == 1 || (index >= 5 && index <= 7) {
|
|
out: Vec(u8)
|
|
BuilderPrint(*out, "% ", text)
|
|
text = BuilderFinish(out)
|
|
}
|
|
selected = Suggestion(30030 + index, text,
|
|
Bounds(x + suggestion_count * (chip_width + Scale(8)), suggestions_top, chip_width, Scale(36))) || selected
|
|
suggestion_count += 1
|
|
}
|
|
chosen: s32 = -1
|
|
if menu_count > 0 {
|
|
Box(frame.session, BoxProps.{.key = cast(u64)360000,
|
|
.bounds = Bounds(x, menu_top, width, menu_height),
|
|
.fill = Color.{156, 156, 156, 24}, .radius = cast(float32)Scale(12)})
|
|
menu_list := Scroll(frame.session, ScrollProps.{.key = cast(u64)360001,
|
|
.bounds = Bounds(x, menu_top, width, menu_height),
|
|
.content_height = menu_count * menu_row, .scroll_offset = menu_scroll, .scale = frame.scale})
|
|
menu_scroll = menu_list.scroll_offset
|
|
if menu_list.opened {
|
|
name_width := Scale(104)
|
|
for row: cast(s32)0..menu_count - 1 {
|
|
top := cast(s32)menu_list.content.y + row * menu_row
|
|
if top + menu_row < menu_top || top > menu_top + menu_height {
|
|
continue
|
|
}
|
|
index := menu_matches[row]
|
|
command := menu[index]
|
|
key := 360100 + index * 4
|
|
if row == menu_target {
|
|
Box(frame.session, BoxProps.{.key = cast(u64)key,
|
|
.bounds = Bounds(x, top, width, menu_row),
|
|
.fill = Color.{156, 188, 143, 48}, .radius = cast(float32)Scale(12)})
|
|
}
|
|
if Button(frame.session, ButtonProps.{.id = 360200 + index,
|
|
.bounds = Bounds(x, top, width, menu_row), .invisible = true,
|
|
.label = command.description}) != 0 {
|
|
chosen = index
|
|
}
|
|
strong: [1]TextRange = .[TextRange.{.start = 0, .end = cast(s32)command.name.count}]
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 1),
|
|
.bounds = Bounds(x + Scale(16), top, name_width, menu_row),
|
|
.text = command.name, .font = frame.font, .strong = strong[:],
|
|
.wrap = cast(TextWrap)TextWrapNone, .vertical_align = cast(TextAlign)TextAlignCenter})
|
|
// Long translations wrap to a second line on narrow phones.
|
|
Text(frame.session, TextProps.{.key = cast(u64)(key + 2),
|
|
.bounds = Bounds(x + Scale(16) + name_width, top,
|
|
width - Scale(32) - name_width, menu_row),
|
|
.text = command.description, .font = Scale(14),
|
|
.wrap = cast(TextWrap)TextWrapAuto, .vertical_align = cast(TextAlign)TextAlignCenter})
|
|
}
|
|
End(frame.session)
|
|
}
|
|
}
|
|
// As in Telegram, an empty draft offers the command button and a draft
|
|
// offers Send. A pending answer keeps Send visible as its progress.
|
|
show_commands := LumiTrim(frame.value).count == 0 && !frame.waiting
|
|
if show_commands && Button(frame.session, ButtonProps.{.id = 30012,
|
|
.bounds = Bounds(x + width - Scale(48), footer, Scale(48), Scale(48)),
|
|
.label = LumiViewLocaleHost("lumi_commands"), .icon_shape = LUMI_COMMANDS_ICON, .icon_only = true,
|
|
.tone = cast(ButtonTone)ButtonToneNeutral, .emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0 {
|
|
FillDraft("/")
|
|
selected = true
|
|
}
|
|
// The command button and the list keep typing in the draft, as Telegram
|
|
// does, rather than leaving the focus on the pressed button. Apps built
|
|
// before Kryon's focus fix give the focus back to that button on the
|
|
// next frame, so the request lasts two frames.
|
|
if selected || chosen >= 0 {
|
|
focus_request = 2
|
|
}
|
|
field_input := frame.input
|
|
if focus_request > 0 {
|
|
field_input.focus = true
|
|
focus_request -= 1
|
|
}
|
|
field := TextArea(frame.session, TextAreaProps.{.key = cast(u64)300200, .focus_id = 30010,
|
|
.bounds = Bounds(x, footer, width - Scale(56), input_height),
|
|
.value = frame.value, .placeholder = LumiViewLocaleHost("lumi_placeholder"), .label = "Lumi",
|
|
.cursor = frame.cursor, .anchor = frame.anchor, .scroll_y = frame.input_scroll,
|
|
.selecting = frame.selecting, .preferred_x = frame.preferred_x,
|
|
.preferred_x_valid = frame.preferred_x_valid, .wrap = true,
|
|
.focused = frame.focused, .input = field_input, .max_bytes = LUMI_INPUT_MAX - 1,
|
|
.max_codepoints = LUMI_INPUT_MAX - 1})
|
|
if !selected {
|
|
if field.edit.changed && field.edit.start >= 0 && field.edit.end >= field.edit.start &&
|
|
field.edit.end <= frame.value.count {
|
|
out: Vec(u8)
|
|
BuilderPrint(*out, "%", frame.value[:field.edit.start])
|
|
BuilderPrint(*out, "%", field.edit.replacement)
|
|
BuilderPrint(*out, "%", frame.value[field.edit.end:])
|
|
replacement := BuilderFinish(out)
|
|
if replacement.count < LUMI_INPUT_MAX {
|
|
frame.value = replacement
|
|
}
|
|
}
|
|
frame.cursor = field.cursor
|
|
frame.anchor = field.anchor
|
|
frame.input_scroll = field.scroll_y
|
|
frame.selecting = field.selecting
|
|
frame.preferred_x = field.preferred_x
|
|
frame.preferred_x_valid = field.preferred_x_valid
|
|
frame.focused = field.focused
|
|
}
|
|
// The message menu is an overlay, so it sits above the page.
|
|
copy_row := RowMenu()
|
|
frame.clipboard_write = field.clipboard_write
|
|
frame.clipboard_text = field.clipboard_text
|
|
if copy_pending {
|
|
frame.clipboard_write = true
|
|
frame.clipboard_text = pending_copy
|
|
copy_pending = false
|
|
}
|
|
if copy_row >= 0 {
|
|
words: Vec(u8)
|
|
BuilderPrint(*words, "%", ReadLumiChatRowHost(copy_row).text)
|
|
frame.clipboard_write = true
|
|
frame.clipboard_text = BuilderFinish(words)
|
|
}
|
|
send := !show_commands && Button(frame.session, ButtonProps.{.id = 30011,
|
|
.bounds = Bounds(x + width - Scale(48), footer, Scale(48), Scale(48)),
|
|
.label = LumiViewLocaleHost("lumi_send"), .icon_shape = LUMI_SEND_ICON, .icon_only = true,
|
|
.disabled = frame.waiting, .loading = frame.waiting, .tone = cast(ButtonTone)ButtonToneNeutral,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0
|
|
if chosen < 0 && field.committed && !send && menu_target >= 0 && !frame.waiting && !selected {
|
|
chosen = menu_matches[menu_target]
|
|
}
|
|
submit := ""
|
|
if chosen >= 0 {
|
|
// A command that needs text, or one chosen while Lumi is answering,
|
|
// waits in the draft.
|
|
text := CommandText(menu[chosen])
|
|
if menu[chosen].needs_text || frame.waiting {
|
|
FillDraft(text)
|
|
} else {
|
|
submit = text
|
|
}
|
|
} else if !frame.waiting && (send || field.committed) && LumiTrim(frame.value).count > 0 && !selected {
|
|
submit = frame.value
|
|
}
|
|
if submit.count > 0 {
|
|
message.action = LUMI_SEND
|
|
// The host owns the draft buffer. Keep the submitted text before
|
|
// WriteLumiUiHost clears that buffer for the next message.
|
|
submitted: Vec(u8)
|
|
BuilderPrint(*submitted, "%", submit)
|
|
message.input = BuilderFinish(submitted)
|
|
frame.value = ""
|
|
frame.cursor = 0
|
|
frame.anchor = 0
|
|
frame.input_scroll = 0
|
|
frame.selecting = false
|
|
frame.preferred_x_valid = false
|
|
frame.scroll = 1000000
|
|
frame.follow_end = true
|
|
}
|
|
WriteLumiUiHost(frame)
|
|
if message.action != LUMI_SEND && load_older {
|
|
unused LumiLoadOlderHost()
|
|
}
|
|
return message
|
|
}
|