Share, Edit and New list move beside the Open/All filter, so the tabs use the full width. A tab is scrolled into view only when the selection changes, so swiping back to the first lists no longer jumps to the selected one. Undo takes a line under the items while it is offered.
921 lines
39 KiB
Ziran
921 lines
39 KiB
Ziran
// Lists owns its complete screen composition; the host supplies saved rows,
|
|
// device input and ordinary Kryon widget effects.
|
|
#import "session"
|
|
#import "geometry"
|
|
#import "text"
|
|
#import "vec"
|
|
#import "c_string"
|
|
#import "text_buffer"
|
|
#import "layout"
|
|
#import "dropdown_props"
|
|
#import "dropdown_widget"
|
|
#import "context_menu_widget"
|
|
#import "text_props"
|
|
#import "text_align"
|
|
#import "text_widget"
|
|
#import "text_input_props"
|
|
#import "text_field_widget"
|
|
#import "button_props"
|
|
#import "button_widget"
|
|
#import "control_props"
|
|
#import "swipe_row_props"
|
|
#import "swipe_row"
|
|
#import "tab_bar_props"
|
|
#import "tab_bar_widget"
|
|
#import "scroll_props"
|
|
#import "scroll_widget"
|
|
#import "modal_props"
|
|
#import "modal_frame_widget"
|
|
#import "box_props"
|
|
#import "box_widget"
|
|
#import "drawing_props"
|
|
#import "tree"
|
|
#import "icon"
|
|
EditIcon :: #import "mingcute/mingcute_regular_edit_2";
|
|
#import, file "../../src/cells/lists_ui_types.zi";
|
|
#import, file "../../src/cells/lists_types.zi";
|
|
|
|
using ButtonTone;
|
|
using ButtonEmphasis;
|
|
using TextAlign;
|
|
using TextWrap;
|
|
using IconType;
|
|
host_api :: #system_library "host_api";
|
|
ReadListsUiHost :: () -> ListsUiFrame #foreign host_api;
|
|
WriteListsUiHost :: (frame: ListsUiFrame) #foreign host_api;
|
|
ReadListsRowHost :: (index: s32, item: bool) -> ListsUiRow #foreign host_api;
|
|
ReadListsSharingRowHost :: (index: s32, invitation: bool) -> ListsUiPerson #foreign host_api;
|
|
PrepareListsCommandHost :: (request: ListsUiRequest) -> string #foreign host_api;
|
|
ListsLocaleHost :: (key: string) -> string #foreign host_api;
|
|
frame: ListsUiFrame;
|
|
state: ListsMessage;
|
|
// The open Share or Invitations dialog's scroll offset.
|
|
sharing_scroll: s32;
|
|
SharingAccessControl :: struct {
|
|
target: [65]u8
|
|
bounds: Rectangle
|
|
role: s32
|
|
disabled: bool
|
|
}
|
|
sharing_controls: Vec(SharingAccessControl);
|
|
sharing_viewport: Rectangle;
|
|
invite_text: string;
|
|
invite_target: [65]u8;
|
|
invite_cursor: s32;
|
|
invite_anchor: s32;
|
|
invite_scroll: s32;
|
|
invite_focused: bool;
|
|
invite_suggestions: bool;
|
|
// Delete lives inside Edit and asks first; this is true once it has asked.
|
|
delete_confirm: bool;
|
|
// The last deleted item, kept briefly so Undo can bring it back.
|
|
undo_item: ListsUiRow;
|
|
undo_account: string;
|
|
undo_until: float64;
|
|
// The list whose tab was last scrolled into view. Only a new selection
|
|
// scrolls the tabs again, so a swipe through them stays where it stops.
|
|
revealed_list: s32 = -1;
|
|
// Share, as in a document: a person with a plus.
|
|
SHARE_ICON :: "S1.8rr:M9 4.5C10.93 4.5 12.5 6.07 12.5 8C12.5 9.93 10.93 11.5 9 11.5C7.07 11.5 5.5 9.93 5.5 8C5.5 6.07 7.07 4.5 9 4.5ZM3 20C3 16.7 5.7 14 9 14C12.3 14 15 16.7 15 20M19 8V14M16 11H22"
|
|
// The same trash can as Photos and Lumi.
|
|
TRASH_ICON :: "S1.6rr:M3 6H21M9 6V3H15V6M5 6L6 21H18L19 6M10 10V17M14 10V17"
|
|
// As in 1List, a tap on an item finishes it, a swipe right edits it and a
|
|
// swipe left deletes it; Undo brings a deleted item back.
|
|
row_swipe: SwipeRowState;
|
|
|
|
EditSwipe :: () -> SwipeRowAction {
|
|
return SwipeRowAction.{.fill = Color.{58, 110, 165, 255},
|
|
.icon_shape = EditIcon.Shape, .icon_color = Color.{255, 255, 255, 255}}
|
|
}
|
|
|
|
DeleteSwipe :: () -> SwipeRowAction {
|
|
return SwipeRowAction.{.fill = Color.{198, 52, 52, 255},
|
|
.icon_shape = TRASH_ICON, .icon_color = Color.{255, 255, 255, 255}, .removes = true}
|
|
}
|
|
|
|
Scale :: (pixels: s32) -> s32 {
|
|
return cast(s32)(cast(float32)pixels * 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}
|
|
}
|
|
|
|
BeginInput :: (item: s32, value: string) {
|
|
state.editing_item = item
|
|
state.input_error = 0
|
|
frame.value = value
|
|
frame.cursor = cast(s32)value.count
|
|
frame.anchor = frame.cursor
|
|
frame.scroll_x = 0
|
|
frame.focused = true
|
|
}
|
|
|
|
// Remembers a deleted item's name for a few seconds so Undo can restore it.
|
|
RememberDeleted :: (row: ListsUiRow) {
|
|
undo_item = row
|
|
undo_item.id = Copied(row.id)
|
|
undo_item.parent_id = Copied(row.parent_id)
|
|
undo_item.title = Copied(row.title)
|
|
undo_item.comment = Copied(row.comment)
|
|
undo_account = Copied(frame.public_id)
|
|
undo_until = state.now + 10.0
|
|
}
|
|
|
|
// A copy that survives the next host call. Rows read from the host share one
|
|
// text buffer, so a second read overwrites the strings of the first.
|
|
Copied :: (value: string) -> string {
|
|
text: Vec(u8)
|
|
BuilderPrint(*text, "%", value)
|
|
return BuilderFinish(text)
|
|
}
|
|
|
|
Finish :: () -> ListsMessage {
|
|
WriteListsUiHost(frame)
|
|
state.succeeded = true
|
|
return state
|
|
}
|
|
|
|
Mutation :: (action: s32, index: s32) {
|
|
state.action = action
|
|
state.index = index
|
|
if state.selected_list >= 0 && state.selected_list < state.list_count {
|
|
row := ReadListsRowHost(state.selected_list, false)
|
|
state.id = row.id
|
|
state.selected_id = row.id
|
|
state.sort_order = row.sort_order
|
|
}
|
|
item := ifx action == LISTS_COMMIT then state.editing_item else index
|
|
if item >= 0 && item < state.item_count {
|
|
row := ReadListsRowHost(item, true)
|
|
state.id = row.id
|
|
state.parent_id = row.parent_id
|
|
state.title = row.title
|
|
state.comment = row.comment
|
|
if action != LISTS_SET_DONE {
|
|
state.done = row.done
|
|
}
|
|
state.sort_order = row.sort_order
|
|
}
|
|
if action == LISTS_COMMIT {
|
|
state.title = frame.value
|
|
}
|
|
if state.selected_list >= 0 && state.selected_list < state.list_count &&
|
|
state.editing_item != -2 && ReadListsRowHost(state.selected_list, false).shared {
|
|
Remote(action)
|
|
}
|
|
}
|
|
|
|
Field :: (bounds: Rectangle, placeholder: string, read_only: bool = false) -> bool {
|
|
edited := TextField(frame.session, TextFieldProps.{.key = cast(u64)6501,
|
|
.bounds = bounds, .value = frame.value, .placeholder = placeholder, .cursor = frame.cursor,
|
|
.anchor = frame.anchor, .scroll_x = frame.scroll_x,
|
|
.focused = frame.focused, .focus_id = 6501,
|
|
.max_bytes = 127, .max_codepoints = 127, .input = frame.input,
|
|
.disabled = frame.sharing_busy || frame.sharing_pending || read_only})
|
|
if edited.edit.changed {
|
|
start := edited.edit.start
|
|
end := edited.edit.end
|
|
if start >= 0 && end >= start && end <= frame.value.count {
|
|
value: Vec(u8)
|
|
BuilderPrint(*value, "%", frame.value[:start])
|
|
BuilderPrint(*value, "%", edited.edit.replacement)
|
|
BuilderPrint(*value, "%", frame.value[end:])
|
|
replacement := BuilderFinish(value)
|
|
if replacement.count <= 127 {
|
|
frame.value = replacement
|
|
}
|
|
}
|
|
}
|
|
frame.cursor = edited.cursor
|
|
frame.anchor = edited.anchor
|
|
frame.scroll_x = edited.scroll_x
|
|
frame.focused = edited.focused
|
|
frame.clipboard_write = edited.clipboard_write
|
|
frame.clipboard_text = edited.clipboard_text
|
|
return edited.committed
|
|
}
|
|
|
|
Remote :: (action: s32, target: string = "", invitation: string = "",
|
|
invitation_list: string = "", access: string = "") {
|
|
state.action = action
|
|
state.remote = true
|
|
list: ListsUiRow
|
|
if state.selected_list >= 0 && state.selected_list < state.list_count {
|
|
list = ReadListsRowHost(state.selected_list, false)
|
|
}
|
|
if invitation_list.count > 0 {
|
|
list.id = invitation_list
|
|
}
|
|
state.selected_id = list.id
|
|
state.request_body = PrepareListsCommandHost(ListsUiRequest.{
|
|
.action = action, .index = state.index, .editing_item = state.editing_item,
|
|
.selected_list = state.selected_list, .done = state.done,
|
|
.value = ifx action == LISTS_RESTORE_ITEM then state.title else frame.value,
|
|
.next_id = frame.next_id, .item_id = state.id, .comment = state.comment,
|
|
.target = target, .invitation = invitation, .list_id = list.id, .access = access})
|
|
}
|
|
|
|
// Cells cannot measure text, so a paragraph's height allows a generous
|
|
// average character width; wide characters count twice.
|
|
ParagraphHeight :: (text: string, width: s32) -> s32 {
|
|
if text.count == 0 {
|
|
return 0
|
|
}
|
|
columns: s32 = 0
|
|
for index: cast(s32)0..cast(s32)text.count - 1 {
|
|
byte := text[index]
|
|
if byte >= cast(u8)224 {
|
|
columns += 2
|
|
} else if byte < cast(u8)128 || byte >= cast(u8)192 {
|
|
columns += 1
|
|
}
|
|
}
|
|
per_line := width / Scale(8)
|
|
if per_line < 1 {
|
|
per_line = 1
|
|
}
|
|
lines := (columns + per_line - 1) / per_line
|
|
return lines * Scale(22)
|
|
}
|
|
|
|
// Active and pending collaborators, independent of this account's friends.
|
|
SharingMemberShown :: (row: ListsUiPerson, list_id: string) -> bool {
|
|
return row.list_id == list_id && (row.status == "accepted" || row.status == "pending")
|
|
}
|
|
|
|
InvitationAvailable :: (friend: string, list_id: string, owner: string) -> bool {
|
|
if friend == frame.public_id || friend == owner {
|
|
return false
|
|
}
|
|
for index: cast(s32)0..frame.invitation_count - 1 {
|
|
if SharingMemberShown(ReadListsSharingRowHost(index, true), list_id) {
|
|
if ReadListsSharingRowHost(index, true).target == friend {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
ResetInvite :: () {
|
|
invite_text = ""
|
|
invite_target[0] = cast(u8)0
|
|
invite_cursor = 0
|
|
invite_anchor = 0
|
|
invite_scroll = 0
|
|
invite_focused = false
|
|
invite_suggestions = false
|
|
}
|
|
|
|
// An explicit invitation follows selection from the name suggestions.
|
|
InviteField :: (x: s32, y: s32, width: s32, disabled: bool) -> bool {
|
|
button_width := Scale(96)
|
|
previous_bytes: [128]u8
|
|
unused CopyCString(invite_text, previous_bytes[:])
|
|
previous := TextUntilNul(previous_bytes[:])
|
|
edited := TextField(frame.session, TextFieldProps.{.key = cast(u64)6540,
|
|
.bounds = Bounds(x, y, width - button_width - Scale(8), Scale(44)),
|
|
.value = previous, .placeholder = ListsLocaleHost("elist_invite_by_name"),
|
|
.cursor = invite_cursor, .anchor = invite_anchor, .scroll_x = invite_scroll,
|
|
.focused = invite_focused, .focus_id = 6540, .scale = frame.scale,
|
|
.max_bytes = 127, .max_codepoints = 127, .input = frame.input, .disabled = disabled})
|
|
if edited.edit.changed {
|
|
value := previous
|
|
if edited.edit.start >= 0 && edited.edit.end >= edited.edit.start && edited.edit.end <= value.count {
|
|
text: Vec(u8)
|
|
BuilderPrint(*text, "%", value[:edited.edit.start])
|
|
BuilderPrint(*text, "%", edited.edit.replacement)
|
|
BuilderPrint(*text, "%", value[edited.edit.end:])
|
|
invite_text = BuilderFinish(text)
|
|
invite_target[0] = cast(u8)0
|
|
invite_suggestions = true
|
|
}
|
|
}
|
|
invite_cursor = edited.cursor
|
|
invite_anchor = edited.anchor
|
|
invite_scroll = edited.scroll_x
|
|
invite_focused = edited.focused
|
|
frame.focused = invite_focused
|
|
if edited.clipboard_write {
|
|
frame.clipboard_write = true
|
|
frame.clipboard_text = edited.clipboard_text
|
|
}
|
|
if edited.escaped {
|
|
invite_suggestions = false
|
|
}
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6541,
|
|
.bounds = Bounds(x + width - button_width, y, button_width, Scale(44)),
|
|
.label = ListsLocaleHost("elist_invite"),
|
|
.tone = cast(ButtonTone)ButtonToneAccent,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled,
|
|
.disabled = disabled || invite_target[0] == cast(u8)0}) != 0 {
|
|
Remote(LISTS_INVITE, TextUntilNul(invite_target[:]))
|
|
ResetInvite()
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Suggestions float below the input while typing and only select a person.
|
|
InviteSuggestions :: (x: s32, y: s32, list_id: string, owner: string) {
|
|
if !invite_suggestions || invite_text.count == 0 {
|
|
return
|
|
}
|
|
options: [8]ContextMenuItem
|
|
names: [8][128]u8
|
|
targets: [8][65]u8
|
|
count: s32 = 0
|
|
for index: cast(s32)0..frame.friend_count - 1 {
|
|
friend := ReadListsSharingRowHost(index, false)
|
|
id: [65]u8
|
|
alias: [128]u8
|
|
unused CopyCString(friend.id, id[:])
|
|
unused CopyCString(friend.alias, alias[:])
|
|
if !ContainsFoldASCII(TextUntilNul(alias[:]), invite_text) ||
|
|
!InvitationAvailable(TextUntilNul(id[:]), list_id, owner) {
|
|
continue
|
|
}
|
|
names[count] = alias
|
|
targets[count] = id
|
|
options[count] = ContextMenuItem.{.id = count + 1, .label = TextUntilNul(names[count][:])}
|
|
count += 1
|
|
if count == 8 {
|
|
break
|
|
}
|
|
}
|
|
if count == 0 {
|
|
options[0] = ContextMenuItem.{.id = 1, .label = ListsLocaleHost("elist_no_matches"), .disabled = true}
|
|
count = 1
|
|
}
|
|
result := ContextMenu(frame.session, ContextMenuProps.{.key = cast(u64)6542,
|
|
.open = true, .x = cast(float32)x, .y = cast(float32)y,
|
|
.escape = frame.input.escape, .scale = frame.scale}, options[:count])
|
|
if result.activated_id > 0 && result.activated_id <= count && !options[result.activated_id - 1].disabled {
|
|
selected := result.activated_id - 1
|
|
invite_text = Copied(TextUntilNul(names[selected][:]))
|
|
invite_target = targets[selected]
|
|
invite_cursor = cast(s32)invite_text.count
|
|
invite_anchor = invite_cursor
|
|
invite_suggestions = false
|
|
} else if result.closed {
|
|
invite_suggestions = false
|
|
}
|
|
}
|
|
|
|
// Each owner has the same edit, deletion, invitation and permission controls.
|
|
MemberRow :: (row: ListsUiPerson, x: s32, y: s32, width: s32, manages: bool,
|
|
original_owner: bool, disabled: bool) {
|
|
target: [65]u8
|
|
unused CopyCString(row.target, target[:])
|
|
name := row.target_alias
|
|
if name.count == 0 {
|
|
name = row.target[:ifx row.target.count > 8 then 8 else row.target.count]
|
|
}
|
|
if row.target == frame.public_id {
|
|
name = ListsLocaleHost("elist_you")
|
|
}
|
|
narrow := width < Scale(360)
|
|
role_width := ifx narrow then width else Scale(168)
|
|
name_width := ifx narrow then width else width - role_width - Scale(12)
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, name_width, Scale(28)),
|
|
.text = name, .wrap = cast(TextWrap)TextWrapEllipsis})
|
|
if row.status == "pending" {
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y + Scale(28), name_width, Scale(24)),
|
|
.text = ListsLocaleHost("elist_invited"), .font = Scale(13)})
|
|
}
|
|
role: s32 = ifx original_owner || row.access == "owner" then 0 else ifx row.access == "viewer" then 2 else 1
|
|
role_y := y + ifx narrow then Scale(52) else 0
|
|
role_x := ifx narrow then x else x + width - role_width
|
|
labels: [3]string = .[ListsLocaleHost("elist_owner"), ListsLocaleHost("elist_can_edit"), ListsLocaleHost("elist_read_only")]
|
|
bounds := Bounds(role_x, role_y, role_width, Scale(44))
|
|
if manages && !original_owner && bounds.y >= sharing_viewport.y &&
|
|
bounds.y + bounds.height <= sharing_viewport.y + sharing_viewport.height {
|
|
// Submit after Scroll ends: its viewport must not crop the menu.
|
|
unused VecPush(sharing_controls, SharingAccessControl.{.target = target,
|
|
.bounds = bounds, .role = role, .disabled = disabled})
|
|
} else {
|
|
Text(frame.session, TextProps.{.bounds = bounds,
|
|
.text = labels[role], .vertical_align = cast(TextAlign)TextAlignCenter})
|
|
}
|
|
}
|
|
|
|
SharingAccessControls :: () -> bool {
|
|
labels: [3]string = .[ListsLocaleHost("elist_owner"), ListsLocaleHost("elist_can_edit"), ListsLocaleHost("elist_read_only")]
|
|
options: [4]DropdownOption
|
|
for index: cast(s32)0..2 {
|
|
options[index] = DropdownOption.{.key = cast(u64)(index + 1), .label = labels[index]}
|
|
}
|
|
options[3] = DropdownOption.{.key = cast(u64)4, .label = ListsLocaleHost("elist_remove_access"), .separator_before = true}
|
|
for control: sharing_controls {
|
|
target := TextUntilNul(control.target[:])
|
|
changed := Dropdown(frame.session, DropdownProps.{.key = KeyHash(target),
|
|
.bounds = control.bounds, .selected_index = control.role,
|
|
.disabled = control.disabled, .scale = frame.scale}, options[:4])
|
|
if changed.changed {
|
|
if changed.selected_index == 3 {
|
|
Remote(LISTS_REMOVE_ACCESS, target)
|
|
} else {
|
|
access: [3]string = .["owner", "editor", "viewer"]
|
|
Remote(LISTS_SET_ACCESS, target, "", "", access[changed.selected_index])
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Share and Invitations update automatically while the dialog is open.
|
|
SharingDialog :: () {
|
|
VecClear(sharing_controls)
|
|
share := frame.panel == 1
|
|
list: ListsUiRow
|
|
if share && state.selected_list >= 0 && state.selected_list < state.list_count {
|
|
list = ReadListsRowHost(state.selected_list, false)
|
|
}
|
|
width := frame.width - Scale(32)
|
|
if width > Scale(520) {
|
|
width = Scale(520)
|
|
}
|
|
detail := ListsLocaleHost("elist_connect")
|
|
if frame.connected {
|
|
detail = ListsLocaleHost(ifx share then "elist_people_with_access" else "elist_invitations_detail")
|
|
}
|
|
count: s32 = ifx share then 1 else 0
|
|
for index: cast(s32)0..frame.invitation_count - 1 {
|
|
row := ReadListsSharingRowHost(index, true)
|
|
if (share && SharingMemberShown(row, list.id)) ||
|
|
(!share && row.target == frame.public_id && row.status == "pending") {
|
|
count += 1
|
|
}
|
|
}
|
|
row_height := Scale(ifx !share then 160 else ifx width - Scale(36) < Scale(360) then 104 else 64)
|
|
shown := ifx count > 4 then 4 else count
|
|
height := Scale(120) + shown * row_height
|
|
if share && frame.connected {
|
|
height += Scale(64)
|
|
}
|
|
if height > frame.height - frame.bottom - Scale(32) {
|
|
height = frame.height - frame.bottom - Scale(32)
|
|
}
|
|
dialog := ModalFrame(frame.session, ModalFrameProps.{.key = cast(u64)6520,
|
|
.title = ListsLocaleHost(ifx share then "elist_share" else "elist_invitations"),
|
|
.width = width, .height = height, .scale = frame.scale,
|
|
.has_right_action = true, .right_label = ListsLocaleHost("close_button")})
|
|
if dialog.dismissed || dialog.right_clicked {
|
|
frame.panel = 0
|
|
frame.focused = false
|
|
sharing_scroll = 0
|
|
ResetInvite()
|
|
return
|
|
}
|
|
if !dialog.opened {
|
|
return
|
|
}
|
|
x := cast(s32)dialog.layout.content.x
|
|
y := cast(s32)dialog.layout.content.y
|
|
content_width := cast(s32)dialog.layout.content.width
|
|
bottom := cast(s32)(dialog.layout.content.y + dialog.layout.content.height)
|
|
disabled := frame.sharing_busy || frame.sharing_pending
|
|
suggestions_y := y + Scale(48)
|
|
if share && frame.connected && !list.read_only {
|
|
if InviteField(x, y, content_width, disabled || list.incomplete) {
|
|
End(frame.session)
|
|
return
|
|
}
|
|
y += Scale(60)
|
|
} else if share && frame.connected {
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, content_width, Scale(44)),
|
|
.text = ListsLocaleHost("elist_read_only"), .vertical_align = cast(TextAlign)TextAlignCenter})
|
|
y += Scale(52)
|
|
}
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, content_width, Scale(32)),
|
|
.text = detail, .wrap = cast(TextWrap)TextWrapAuto})
|
|
y += Scale(40)
|
|
if !frame.connected {
|
|
End(frame.session)
|
|
return
|
|
}
|
|
if count == 0 {
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, content_width, Scale(44)),
|
|
.text = ListsLocaleHost("elist_no_invitations"), .wrap = cast(TextWrap)TextWrapAuto})
|
|
} else {
|
|
scroll := Scroll(frame.session, ScrollProps.{.key = cast(u64)6512,
|
|
.bounds = Bounds(x, y, content_width, bottom - y),
|
|
.content_height = count * row_height, .scroll_offset = sharing_scroll})
|
|
sharing_scroll = scroll.scroll_offset
|
|
sharing_viewport = scroll.viewport
|
|
if scroll.opened {
|
|
row_y := cast(s32)scroll.content.y
|
|
changed: bool
|
|
if share {
|
|
name := ifx list.owner_alias.count > 0 then list.owner_alias else list.owner_id
|
|
if !list.shared || list.owner_id == frame.public_id {
|
|
name = ListsLocaleHost("elist_you")
|
|
}
|
|
MemberRow(ListsUiPerson.{.target = list.owner_id, .target_alias = name, .access = "owner"},
|
|
x, row_y, content_width - Scale(14), false, true, disabled)
|
|
row_y += row_height
|
|
}
|
|
for index: cast(s32)0..frame.invitation_count - 1 {
|
|
row := ReadListsSharingRowHost(index, true)
|
|
if (share && !SharingMemberShown(row, list.id)) ||
|
|
(!share && (row.target != frame.public_id || row.status != "pending")) {
|
|
continue
|
|
}
|
|
if row_y + row_height > cast(s32)scroll.viewport.y && row_y < cast(s32)(scroll.viewport.y + scroll.viewport.height) {
|
|
if share {
|
|
MemberRow(row, x, row_y, content_width - Scale(14), list.owner, false, disabled)
|
|
} else {
|
|
changed = InvitationRow(row, index, x, row_y, content_width - Scale(14), disabled)
|
|
}
|
|
if changed {
|
|
break
|
|
}
|
|
}
|
|
row_y += row_height
|
|
}
|
|
End(frame.session)
|
|
if changed {
|
|
End(frame.session)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
if SharingAccessControls() {
|
|
End(frame.session)
|
|
return
|
|
}
|
|
// Emit the floating menu last so it sits above all collaborator rows.
|
|
if share && !list.read_only && !disabled {
|
|
InviteSuggestions(x, suggestions_y, list.id, list.owner_id)
|
|
}
|
|
End(frame.session)
|
|
}
|
|
|
|
// An invitation to a list, who sent it, and Accept and Decline. True once
|
|
// one is chosen.
|
|
InvitationRow :: (row: ListsUiPerson, index: s32, x: s32, y: s32, width: s32, disabled: bool) -> bool {
|
|
alias := row.alias
|
|
if alias.count == 0 {
|
|
alias = row.owner
|
|
}
|
|
Box(frame.session, BoxProps.{.key = cast(u64)(7800 + index),
|
|
.bounds = Bounds(x, y + Scale(4), width, Scale(144)),
|
|
.border = Color.{128, 128, 128, 64}, .radius = cast(float32)Scale(12)})
|
|
x += Scale(16)
|
|
width -= Scale(32)
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y + Scale(14), width, Scale(44)),
|
|
.text = row.title, .font = Scale(18), .wrap = cast(TextWrap)TextWrapAuto})
|
|
sender: Vec(u8)
|
|
BuilderPrint(*sender, "%: %", ListsLocaleHost("elist_invitation_from"), alias)
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y + Scale(60), width, Scale(24)),
|
|
.text = BuilderFinish(sender), .font = Scale(13), .wrap = cast(TextWrap)TextWrapEllipsis})
|
|
button_width := (width - Scale(12)) / 2
|
|
accept := Button(frame.session, ButtonProps.{.key = cast(u64)(7600 + index * 2),
|
|
.bounds = Bounds(x, y + Scale(92), button_width, Scale(44)),
|
|
.label = ListsLocaleHost("profile_friend_accept_button"),
|
|
.tone = cast(ButtonTone)ButtonToneAccent, .emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled,
|
|
.disabled = disabled || state.list_count >= 32}) != 0
|
|
decline := Button(frame.session, ButtonProps.{.key = cast(u64)(7601 + index * 2),
|
|
.bounds = Bounds(x + button_width + Scale(12), y + Scale(92), button_width, Scale(44)),
|
|
.label = ListsLocaleHost("profile_friend_decline_button"), .disabled = disabled,
|
|
.tone = cast(ButtonTone)ButtonToneNeutral,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost}) != 0
|
|
if accept || decline {
|
|
Remote(ifx accept then LISTS_ACCEPT else LISTS_DECLINE, "", row.id, row.list_id)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
ListsView :: (message: ListsMessage) -> ListsMessage {
|
|
frame = ReadListsUiHost()
|
|
state = message
|
|
input := frame.input
|
|
if frame.panel != 0 {
|
|
frame.input = TextFieldInput.{}
|
|
frame.focused = false
|
|
}
|
|
ListsPage()
|
|
frame.input = input
|
|
if frame.panel != 0 {
|
|
SharingDialog()
|
|
}
|
|
return Finish()
|
|
}
|
|
|
|
// The selected list: its tabs, actions, new item field and items.
|
|
ListsPage :: () {
|
|
x := Scale(16)
|
|
width := frame.width - x * 2
|
|
y := Scale(12)
|
|
blocked := frame.sharing_busy || frame.sharing_pending
|
|
current: ListsUiRow
|
|
if state.selected_list >= 0 && state.selected_list < state.list_count {
|
|
current = ReadListsRowHost(state.selected_list, false)
|
|
}
|
|
// The tabs have the whole first row to themselves, so names have room
|
|
// and a swipe anywhere along the row scrolls them.
|
|
if state.list_count > 0 {
|
|
tabs: [32]Tab
|
|
for index: cast(s32)0..state.list_count - 1 {
|
|
row := ReadListsRowHost(index, false)
|
|
tabs[index] = Tab.{.key = cast(u64)(6800 + index), .label = row.title}
|
|
}
|
|
selected := TabBar(frame.session, TabBarProps.{.id = 6500,
|
|
.bounds = Bounds(x, y, width, Scale(44)),
|
|
.selected_index = state.selected_list, .min_tab_width = Scale(88),
|
|
.max_tab_width = Scale(220), .content_sized = true,
|
|
.scroll_offset = frame.tab_scroll, .scale = frame.scale,
|
|
.focus_selected = state.selected_list != revealed_list}, tabs[:state.list_count])
|
|
frame.tab_scroll = selected.scroll_offset
|
|
revealed_list = state.selected_list
|
|
if selected.selected_index != state.selected_list {
|
|
state.action = LISTS_SELECT
|
|
state.index = selected.selected_index
|
|
undo_until = 0.0
|
|
delete_confirm = false
|
|
frame.panel = 0
|
|
return
|
|
}
|
|
y += Scale(56)
|
|
}
|
|
if (frame.sharing_status != 0 && frame.sharing_status != 2) || frame.sharing_pending {
|
|
key := "elist_saving"
|
|
if frame.sharing_pending && !frame.sharing_busy {
|
|
key = "elist_unconfirmed"
|
|
} else if frame.sharing_status == 3 {
|
|
key = "elist_share_failed"
|
|
} else if frame.sharing_status == 4 {
|
|
key = "elist_conflict"
|
|
} else if frame.sharing_status == 5 {
|
|
key = "elist_unavailable"
|
|
}
|
|
notice_width := ifx frame.sharing_pending && !frame.sharing_busy then width - Scale(104) else width
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, notice_width, Scale(64)),
|
|
.text = ListsLocaleHost(key), .wrap = cast(TextWrap)TextWrapAuto})
|
|
if frame.sharing_pending && !frame.sharing_busy {
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6513,
|
|
.bounds = Bounds(x + width - Scale(96), y, Scale(96), Scale(44)),
|
|
.label = ListsLocaleHost("retry_button")}) != 0 {
|
|
state.action = LISTS_RETRY
|
|
state.remote = true
|
|
return
|
|
}
|
|
}
|
|
y += Scale(72)
|
|
}
|
|
if current.shared && current.incomplete {
|
|
blocked = true
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, width, Scale(64)),
|
|
.text = ListsLocaleHost("elist_capacity"), .wrap = cast(TextWrap)TextWrapAuto})
|
|
y += Scale(72)
|
|
}
|
|
if current.read_only && state.editing_item != -2 {
|
|
blocked = true
|
|
}
|
|
editing_list := state.editing_item == -2 || state.editing_item == -3
|
|
if !editing_list {
|
|
// Invitations to other people's lists appear only while some wait.
|
|
if frame.pending_count_text != "0" && frame.pending_count_text != "" {
|
|
label: Vec(u8)
|
|
BuilderPrint(*label, "% (%)", ListsLocaleHost("elist_invitations"), frame.pending_count_text)
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6509,
|
|
.bounds = Bounds(x, y, width, Scale(44)),
|
|
.label = BuilderFinish(label),
|
|
.tone = cast(ButtonTone)ButtonToneAccent}) != 0 {
|
|
frame.panel = 2
|
|
frame.focused = false
|
|
sharing_scroll = 0
|
|
}
|
|
y += Scale(52)
|
|
}
|
|
}
|
|
if state.input_error != 0 {
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y, width, Scale(48)),
|
|
.text = ListsLocaleHost("results_write_failed"), .wrap = cast(TextWrap)TextWrapAuto})
|
|
y += Scale(56)
|
|
}
|
|
if editing_list {
|
|
owner := !current.shared || current.owner
|
|
committed := Field(Bounds(x, y, width, Scale(44)),
|
|
ListsLocaleHost(ifx state.editing_item == -3 then "elist_list_name_placeholder" else "elist_new_list_placeholder"), blocked)
|
|
button_width := (width - Scale(8)) / 2
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6506,
|
|
.label = ListsLocaleHost(ifx state.editing_item == -3 then "done_button" else "elist_create_list"),
|
|
.bounds = Bounds(x, y + Scale(56), button_width, Scale(44)),
|
|
.tone = cast(ButtonTone)ButtonToneAccent, .emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled,
|
|
.disabled = frame.value.count == 0 || blocked}) != 0 || (committed && !blocked) {
|
|
Mutation(LISTS_COMMIT, -1)
|
|
}
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6514,
|
|
.label = ListsLocaleHost("cancel_button"),
|
|
.bounds = Bounds(x + button_width + Scale(8), y + Scale(56), button_width, Scale(44)),
|
|
.disabled = blocked}) != 0 {
|
|
delete_confirm = false
|
|
state.editing_item = -1
|
|
state.reset_input = true
|
|
}
|
|
// Delete is only here, inside Edit, and asks before it removes anything.
|
|
if state.editing_item == -3 {
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6515,
|
|
.label = ListsLocaleHost(ifx delete_confirm then "elist_delete_list_confirm" else "elist_delete_list"),
|
|
.bounds = Bounds(x, y + Scale(112), width, Scale(44)),
|
|
.tone = cast(ButtonTone)ButtonToneDanger,
|
|
.emphasis = cast(ButtonEmphasis)(ifx delete_confirm then ButtonEmphasisFilled else ButtonEmphasisGhost),
|
|
.disabled = current.id.count == 0 || !owner || blocked}) != 0 {
|
|
if delete_confirm {
|
|
delete_confirm = false
|
|
Mutation(LISTS_DELETE_LIST, -1)
|
|
return
|
|
}
|
|
delete_confirm = true
|
|
}
|
|
}
|
|
return
|
|
}
|
|
if state.list_count == 0 {
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y + Scale(32), width, Scale(30)),
|
|
.text = ListsLocaleHost("elist_empty_title"), .align = cast(TextAlign)TextAlignCenter})
|
|
Text(frame.session, TextProps.{.bounds = Bounds(x, y + Scale(72), width, Scale(64)),
|
|
.text = ListsLocaleHost("elist_empty_detail"), .align = cast(TextAlign)TextAlignCenter,
|
|
.wrap = cast(TextWrap)TextWrapAuto})
|
|
create_width := Scale(200)
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6505,
|
|
.bounds = Bounds(x + (width - create_width) / 2, y + Scale(148), create_width, Scale(44)),
|
|
.label = ListsLocaleHost("elist_new_list"), .icon_type = cast(s32)IconPlus,
|
|
.tone = cast(ButtonTone)ButtonToneAccent,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled, .disabled = blocked}) != 0 {
|
|
BeginInput(-2, "")
|
|
frame.panel = 0
|
|
}
|
|
return
|
|
}
|
|
committed := Field(Bounds(x, y, width - Scale(96), Scale(44)),
|
|
ListsLocaleHost(ifx state.editing_item >= 0 then "elist_item_name_placeholder" else "elist_add_item_placeholder"), blocked)
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6507,
|
|
.label = ListsLocaleHost(ifx state.editing_item >= 0 then "done_button" else "elist_add_item"),
|
|
.bounds = Bounds(x + width - Scale(88), y, Scale(88), Scale(44)),
|
|
.tone = cast(ButtonTone)ButtonToneAccent, .emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled,
|
|
.disabled = frame.value.count == 0 || blocked}) != 0 || (committed && !blocked) {
|
|
Mutation(LISTS_COMMIT, -1)
|
|
return
|
|
}
|
|
y += Scale(56)
|
|
// One line under the field: the filter on the left, and on the right
|
|
// the selected list's Share, Edit and New list.
|
|
button_size := Scale(44)
|
|
button_gap := Scale(4)
|
|
new_x := x + width - button_size
|
|
edit_x := new_x - button_gap - button_size
|
|
share_x := edit_x - button_gap - button_size
|
|
filter_width := share_x - Scale(12) - x
|
|
if filter_width > Scale(190) {
|
|
filter_width = Scale(190)
|
|
}
|
|
filters: [2]Tab
|
|
filters[0] = Tab.{.key = cast(u64)6840, .label = ListsLocaleHost("elist_filter_open")}
|
|
filters[1] = Tab.{.key = cast(u64)6841, .label = ListsLocaleHost("elist_filter_all")}
|
|
chosen := TabBar(frame.session, TabBarProps.{.id = 6530,
|
|
.bounds = Bounds(x, y + Scale(2), filter_width, Scale(40)),
|
|
.selected_index = state.show_completed, .min_tab_width = Scale(80),
|
|
.max_tab_width = Scale(120), .content_sized = true, .scale = frame.scale},
|
|
filters[:2])
|
|
if chosen.selected_index != state.show_completed {
|
|
state.show_completed = chosen.selected_index
|
|
frame.scroll = 0
|
|
}
|
|
// Share is one clear button, as in a document: it opens who has access.
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6508,
|
|
.bounds = Bounds(share_x, y, button_size, button_size),
|
|
.label = ListsLocaleHost("elist_share"), .icon_shape = SHARE_ICON, .icon_only = true,
|
|
.tone = cast(ButtonTone)ButtonToneAccent,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisFilled,
|
|
.disabled = current.id.count == 0}) != 0 {
|
|
frame.panel = 1
|
|
frame.focused = false
|
|
sharing_scroll = 0
|
|
ResetInvite()
|
|
}
|
|
// Edit opens the name; Delete is inside it, behind a question.
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6503,
|
|
.bounds = Bounds(edit_x, y, button_size, button_size),
|
|
.label = ListsLocaleHost("elist_rename"), .icon_only = true,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost,
|
|
.icon_type = cast(s32)IconEdit,
|
|
.disabled = current.id.count == 0 || current.read_only || blocked}) != 0 {
|
|
delete_confirm = false
|
|
BeginInput(-3, current.title)
|
|
return
|
|
}
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6505,
|
|
.bounds = Bounds(new_x, y, button_size, button_size),
|
|
.label = ListsLocaleHost("elist_new_list"), .icon_type = cast(s32)IconPlus,
|
|
.icon_only = true, .disabled = blocked || state.list_count >= 32}) != 0 {
|
|
BeginInput(-2, "")
|
|
frame.panel = 0
|
|
return
|
|
}
|
|
y += Scale(52)
|
|
// The items fill what is left above the bottom bar, never past it. Undo
|
|
// takes a line under them for the few seconds it is offered.
|
|
list_height := frame.height - frame.bottom - y - Scale(12)
|
|
undo_shown := undo_item.title.count > 0 && state.now < undo_until &&
|
|
undo_item.parent_id == current.id && undo_account == frame.public_id
|
|
if undo_shown {
|
|
list_height -= Scale(52)
|
|
}
|
|
if list_height < Scale(72) {
|
|
list_height = Scale(72)
|
|
}
|
|
if undo_shown {
|
|
if Button(frame.session, ButtonProps.{.key = cast(u64)6517,
|
|
.label = ListsLocaleHost("elist_undo"),
|
|
.bounds = Bounds(x, y + list_height + Scale(8), width, Scale(44)),
|
|
.tone = cast(ButtonTone)ButtonToneAccent,
|
|
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost, .disabled = blocked}) != 0 {
|
|
state.action = LISTS_RESTORE_ITEM
|
|
state.id = undo_item.id
|
|
state.parent_id = undo_item.parent_id
|
|
state.title = undo_item.title
|
|
state.comment = undo_item.comment
|
|
state.done = undo_item.done
|
|
state.sort_order = undo_item.sort_order
|
|
state.index = undo_item.sort_order
|
|
if current.shared {
|
|
Remote(LISTS_RESTORE_ITEM)
|
|
}
|
|
undo_until = 0.0
|
|
return
|
|
}
|
|
}
|
|
visible: [256]bool
|
|
count: s32 = 0
|
|
for index: cast(s32)0..state.item_count - 1 {
|
|
row := ReadListsRowHost(index, true)
|
|
visible[index] = row.parent_id == current.id && (row.done == 0 ||
|
|
state.show_completed != 0 || (row.id == state.completing_id && state.now < state.completing_until))
|
|
if visible[index] {
|
|
count += 1
|
|
}
|
|
}
|
|
scroll := Scroll(frame.session, ScrollProps.{.key = cast(u64)6600,
|
|
.bounds = Bounds(x, y, width, list_height),
|
|
.content_height = count * Scale(72), .scroll_offset = frame.scroll})
|
|
frame.scroll = scroll.scroll_offset
|
|
if scroll.opened {
|
|
row_y := cast(s32)scroll.content.y
|
|
// Rows stop short of the right edge so the scroll bar has room.
|
|
row_right := x + width - Scale(14)
|
|
for index: cast(s32)0..state.item_count - 1 {
|
|
if !visible[index] {
|
|
continue
|
|
}
|
|
if row_y + Scale(64) > cast(s32)scroll.viewport.y &&
|
|
row_y < cast(s32)(scroll.viewport.y + scroll.viewport.height) {
|
|
row := ReadListsRowHost(index, true)
|
|
swiped := SwipeRow(frame.session, SwipeRowProps.{.key = cast(u64)(7000 + index * 4),
|
|
.bounds = Bounds(x, row_y, row_right - x, Scale(64)),
|
|
.label = row.title, .now = state.now, .scale = frame.scale,
|
|
.start = EditSwipe(), .end = DeleteSwipe(), .disabled = blocked},
|
|
row_swipe)
|
|
row_swipe = swiped.state
|
|
text_x := x + Scale(12) + cast(s32)swiped.offset
|
|
text_width := row_right - x - Scale(24)
|
|
Text(frame.session, TextProps.{.bounds = Bounds(text_x, row_y,
|
|
text_width, ifx row.comment.count > 0 then Scale(30) else Scale(64)),
|
|
.text = row.title, .vertical_align = cast(TextAlign)TextAlignCenter,
|
|
.strikethrough = row.done != 0})
|
|
if row.comment.count > 0 {
|
|
Text(frame.session, TextProps.{.bounds = Bounds(text_x, row_y + Scale(34),
|
|
text_width, Scale(24)), .text = row.comment})
|
|
}
|
|
if swiped.clicked {
|
|
state.done = ifx row.done != 0 then 0 else 1
|
|
Mutation(LISTS_SET_DONE, index)
|
|
End(frame.session)
|
|
return
|
|
}
|
|
if swiped.swiped_start {
|
|
BeginInput(index, row.title)
|
|
}
|
|
if swiped.swiped_end {
|
|
// Deleting leaves Edit, since the items after it move up.
|
|
RememberDeleted(row)
|
|
Mutation(LISTS_DELETE_ITEM, index)
|
|
if state.editing_item >= 0 {
|
|
state.editing_item = -1
|
|
state.reset_input = true
|
|
}
|
|
End(frame.session)
|
|
return
|
|
}
|
|
}
|
|
row_y += Scale(72)
|
|
}
|
|
End(frame.session)
|
|
}
|
|
}
|