2042 lines
103 KiB
Ziran
2042 lines
103 KiB
Ziran
// One profile UI. Hosts supply entity.json through the ordinary scoped store
|
||
// interface; extension replies name only routes supplied by that host.
|
||
#import "model"
|
||
#import "picture_image"
|
||
#import "achievement_view"
|
||
#import "telegram_view"
|
||
#import "leaderboard_view"
|
||
#import "leaderboard_model"
|
||
#import "friends_model"
|
||
#import "management"
|
||
#import "alias_model"
|
||
#import "dew_model"
|
||
#import "dew_play_pricing"
|
||
#import "dew_packs"
|
||
#import "dew_view"
|
||
#import "std/json_scan"
|
||
#import "std/number_text"
|
||
#import "node_url"
|
||
#import "qrcode/qrcode"
|
||
#import "std/c_string"
|
||
#import "std/text_buffer"
|
||
#import "std/vec"
|
||
#import "kryon/app_context"
|
||
#import "profile_theme"
|
||
#import "kryon/app_protocol"
|
||
#import "session"
|
||
#import "geometry"
|
||
#import "text_props"
|
||
#import "text_align"
|
||
#import "text_widget"
|
||
#import "kryon/text_measure"
|
||
#import "text_input_props"
|
||
#import "text_field_widget"
|
||
#import "button_props"
|
||
#import "button_widget"
|
||
#import "control_props"
|
||
#import "scroll_props"
|
||
#import "scroll_widget"
|
||
#import "tree"
|
||
#import "image_props"
|
||
#import "image_widget"
|
||
#import "drawing_props"
|
||
#import "box_props"
|
||
#import "box_widget"
|
||
#import "toggle_widget"
|
||
#import "toggle_props"
|
||
#import "kryon/svg_icon_props"
|
||
#import "kryon/svg_icon_widget"
|
||
#import "kryon/modal_props"
|
||
#import "kryon/modal_frame_widget"
|
||
|
||
Field :: struct { cursor: s32; anchor: s32; scroll_x: s32; focused: bool }
|
||
state: EntityState;
|
||
loaded: bool;
|
||
fields: [8]Field;
|
||
node_text: [256]u8;
|
||
scroll_offset: s32;
|
||
choosing_picture: bool;
|
||
picture_tab: s32;
|
||
picture_scroll: s32;
|
||
notice: string;
|
||
session: Session;
|
||
scale: float32;
|
||
asset_root: [4096]u8;
|
||
management: Management;
|
||
management_tick: s32;
|
||
management_waiting: s32;
|
||
management_seen: s32;
|
||
management_page: s32;
|
||
management_scroll: s32;
|
||
account_alias: [40]u8;
|
||
account_passphrase: [512]u8;
|
||
account_passphrase_repeat: [512]u8;
|
||
sign_in_account: [80]u8;
|
||
// The account Google last found, so the field fills once and can then be edited.
|
||
sign_in_found: [65]u8;
|
||
// "Back up key" on the sign-out warning comes back to it.
|
||
sign_out_after_backup: bool;
|
||
// A new account goes on to its backup once it exists.
|
||
management_creating: bool;
|
||
account_code: [1024]u8;
|
||
account_short_id: [16]u8;
|
||
qr_code: QrCode;
|
||
qr_text: [1024]u8;
|
||
qr_valid: bool;
|
||
public_id_open: bool;
|
||
public_id_owner: [65]u8;
|
||
public_id_copied: bool;
|
||
public_id_scroll: s32;
|
||
public_id_display: [129]u8;
|
||
#load "alias_view.zi";
|
||
|
||
Label :: (key: string, fallback: string) -> string {
|
||
value := AppLocale(key)
|
||
return ifx value == "" || value == key then fallback else value
|
||
}
|
||
|
||
TextLine :: (key: u64, text: string, x: float32, y: float32, width: float32, font: s32 = 16) {
|
||
Text(session, TextProps.{.key = key, .text = text,
|
||
.bounds = Rectangle.{x, y, width, (ifx font > 20 then cast(float32)font * 1.4 else 28.0) * scale}, .font = cast(s32)(cast(float32)font * scale),
|
||
.wrap = TextWrap.TextWrapEllipsis})
|
||
}
|
||
|
||
Action :: (id: s32, label: string, bounds: Rectangle, selected: bool = false, danger: bool = false) -> bool {
|
||
return Button(session, ButtonProps.{.key = cast(u64)id, .id = id,
|
||
.bounds = bounds, .label = label, .selected = selected,
|
||
.tone = ifx danger then ButtonTone.ButtonToneDanger else ifx selected then ButtonTone.ButtonToneAccent else ButtonTone.ButtonToneNeutral,
|
||
.emphasis = ifx selected then ButtonEmphasis.ButtonEmphasisFilled else ButtonEmphasis.ButtonEmphasisSoft,
|
||
.fit_content = true}) != 0
|
||
}
|
||
|
||
Save :: () -> bool {
|
||
document := EntityEncode(state)
|
||
if !WriteStore("entity.json", document) {
|
||
notice = Label("entity.save_error", "Could not save changes")
|
||
return false
|
||
} else {
|
||
notice = ""
|
||
}
|
||
return true
|
||
}
|
||
|
||
EditField :: (index: s32, buffer: []u8, label: string, bounds: Rectangle, maximum: s32, secure: bool = false) -> bool {
|
||
field := *fields[index]
|
||
snapshot: [1024]u8
|
||
for byte: 0..buffer.count - 1 { snapshot[byte] = buffer[byte] }
|
||
props := TextFieldProps.{.key = cast(u64)(100 + index), .focus_id = 100 + index,
|
||
.bounds = bounds, .label = label, .scale = scale,
|
||
.placeholder = ifx index == 0 then Label("entity.name_placeholder", "Your name") else label,
|
||
.value = TextUntilNul(snapshot[:]), .cursor = field.cursor,
|
||
.anchor = field.anchor, .scroll_x = field.scroll_x, .focused = field.focused,
|
||
.max_bytes = cast(s32)buffer.count - 1, .max_codepoints = maximum, .secure = secure}
|
||
if secure && snapshot[0] != cast(u8)0 { props.display_value = "••••••••" }
|
||
if field.focused { props.input = AppFieldInput() }
|
||
result := TextField(session, props)
|
||
if result.edit.changed {
|
||
edit := result.edit
|
||
length: s64 = 0
|
||
while length < buffer.count && buffer[length] != cast(u8)0 { length += 1 }
|
||
new_length := length - (edit.end - edit.start) + edit.replacement.count
|
||
if edit.start >= 0 && edit.end >= edit.start && edit.end <= length && new_length < buffer.count {
|
||
tail := length - edit.end
|
||
if new_length > length {
|
||
for offset: 0..tail { buffer[new_length - offset] = buffer[length - offset] }
|
||
} else {
|
||
for offset: 0..tail { buffer[edit.start + edit.replacement.count + offset] = buffer[edit.end + offset] }
|
||
}
|
||
for offset: 0..edit.replacement.count - 1 { buffer[edit.start + offset] = edit.replacement[offset] }
|
||
buffer[new_length] = cast(u8)0
|
||
}
|
||
}
|
||
if result.clipboard_write { unused ClipboardCopy(result.clipboard_text, 0) }
|
||
finished := result.committed || (field.focused && !result.focused)
|
||
field.* = Field.{result.cursor, result.anchor, result.scroll_x, result.focused && !result.escaped}
|
||
return finished
|
||
}
|
||
|
||
Paragraph :: (key: u64, text: string, x: float32, y: float32, width: float32, height: float32, font: s32 = 14) {
|
||
Text(session, TextProps.{.key = key, .text = text,
|
||
.bounds = Rectangle.{x, y, width, height * scale},
|
||
.font = cast(s32)(cast(float32)font * scale), .wrap = TextWrap.TextWrapAuto})
|
||
}
|
||
|
||
PollManagement :: () {
|
||
management_tick += 1
|
||
if management_tick != 1 && management_tick % 15 != 0 { return }
|
||
next: Management
|
||
if !ManagementDecode(AppService("entity.management", ""), *next) { return }
|
||
result_changed := TextUntilNul(next.result[:]) != TextUntilNul(management.result[:])
|
||
owner_changed := TextUntilNul(next.public_id[:]) != TextUntilNul(management.public_id[:])
|
||
management = next
|
||
if loaded && !choosing_picture && management.account {
|
||
profile: [16384]u8
|
||
count := ReadStore("entity.json", profile[:])
|
||
refreshed: EntityState
|
||
if count > 0 && EntityDecode(TextUntilNul(profile[:]), *refreshed) &&
|
||
TextUntilNul(refreshed.owner_id[:]) == TextUntilNul(management.public_id[:]) {
|
||
state.picture = refreshed.picture
|
||
state.picture_kind = refreshed.picture_kind
|
||
state.abstract_picture = refreshed.abstract_picture
|
||
}
|
||
}
|
||
if owner_changed && loaded {
|
||
loaded = false
|
||
fields = .{}
|
||
public_id_open = false
|
||
public_id_copied = false
|
||
AliasViewReset()
|
||
}
|
||
if !fields[3].focused && management_page != PAGE_ALIAS { account_alias = management.alias }
|
||
if management.completed > management_seen || (result_changed && management.completed > 0) {
|
||
management_seen = management.completed
|
||
AliasManagementFinished()
|
||
message: Vec(u8)
|
||
BuilderPrint(*message, "%", TextUntilNul(management.message[:]))
|
||
notice = BuilderFinish(message)
|
||
if management_waiting <= management.completed {
|
||
management_waiting = 0
|
||
created := management_creating && TextUntilNul(management.result[:]) == "ok"
|
||
if TextUntilNul(management.result[:]) != "switch" { management_creating = false }
|
||
if TextUntilNul(management.result[:]) == "switch" { OpenManagement(PAGE_SWITCH) }
|
||
else if TextUntilNul(management.result[:]) == "ok" {
|
||
loaded = false
|
||
// A finished key, link or alias step returns to the account.
|
||
page := management_page
|
||
// Link steps finish one by one; only an arriving account ends that page.
|
||
if page != 0 && page != PAGE_ACCOUNT && page != PAGE_NODES && page != PAGE_NODE && page != PAGE_ADD_NODE &&
|
||
(page != PAGE_LINK || owner_changed) {
|
||
ManagementHome(PAGE_ACCOUNT)
|
||
}
|
||
// There is no reset, so saving a backup comes first.
|
||
if created && CanManage(ACCOUNT_BACKUP) { ManagementHome(PAGE_BACKUP) }
|
||
if sign_out_after_backup && page == PAGE_BACKUP && CanManage(ACCOUNT_LOGOUT) { OpenManagement(PAGE_LOGOUT) }
|
||
sign_out_after_backup = false
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
CanManage :: (capability: s32) -> bool {
|
||
return management.available && (management.capabilities & capability) != 0
|
||
}
|
||
|
||
PasswordClear :: () {
|
||
for index: 0..account_passphrase.count - 1 {
|
||
account_passphrase[index] = cast(u8)0
|
||
account_passphrase_repeat[index] = cast(u8)0
|
||
}
|
||
fields[1] = Field.{}
|
||
fields[4] = Field.{}
|
||
for index: 0..sign_in_account.count - 1 { sign_in_account[index] = cast(u8)0 }
|
||
fields[7] = Field.{}
|
||
}
|
||
|
||
Manage :: (operation: string, value: string = "", target: string = "", choice: s32 = 0) {
|
||
// Signing out is never held up by other work or by unsaved preferences.
|
||
signing_out := operation == "logout"
|
||
if (!signing_out && management_waiting > management.completed) || !CanManage(ManagementOperation(operation)) { return }
|
||
if !signing_out && TextUntilNul(state.owner_id[:]) != TextUntilNul(management.public_id[:]) {
|
||
loaded = false
|
||
notice = Label("entity.account_changed", "The account changed; open its current profile again")
|
||
return
|
||
}
|
||
if !signing_out && !Save() { return }
|
||
request := ManagementRequest.{.sequence = management.sequence + 1, .choice = choice}
|
||
request.owner_id = management.public_id
|
||
if !CopyCString(operation, request.operation[:]) || !CopyCString(value, request.value[:]) || !CopyCString(target, request.target[:]) { return }
|
||
reply := AppService("entity.management", ManagementRequestEncode(request))
|
||
if reply == "queued" {
|
||
management_waiting = request.sequence
|
||
management.sequence = request.sequence
|
||
management_tick = 0
|
||
notice = ""
|
||
if operation == "create" { management_creating = true }
|
||
PasswordClear()
|
||
} else {
|
||
notice = Label("entity.action_error", "Could not start this action")
|
||
}
|
||
}
|
||
|
||
// Account pages, one short column each. Back returns to the page that
|
||
// opened it; the profile itself is page 0.
|
||
PAGE_ACCOUNT :: 1
|
||
PAGE_IMPORT :: 2
|
||
PAGE_BACKUP :: 3
|
||
PAGE_LOGOUT :: 4
|
||
PAGE_CLEAR :: 5
|
||
PAGE_SWITCH :: 6
|
||
PAGE_LINK :: 7
|
||
PAGE_NODES :: 8
|
||
PAGE_NODE :: 9
|
||
PAGE_ADD_NODE :: 10
|
||
PAGE_ALIAS :: 11
|
||
PAGE_FRIENDS :: 12
|
||
PAGE_APPEARANCE :: 13
|
||
PAGE_SIGN_IN_METHODS :: 20
|
||
root_page: string;
|
||
#load "friends_page.zi";
|
||
|
||
management_stack: [8]s32;
|
||
management_depth: s32;
|
||
node_open: s32;
|
||
// Content heights measured by the previous frame, so every page scrolls
|
||
// over exactly what it drew.
|
||
account_height: float32;
|
||
profile_height: float32;
|
||
|
||
OpenManagement :: (page: s32) {
|
||
if page == PAGE_ALIAS {
|
||
account_alias = management.alias
|
||
AliasViewReset()
|
||
}
|
||
if page == PAGE_FRIENDS { friends_refresh = true; friends_remove = .{} }
|
||
if page == PAGE_SIGN_IN_METHODS { Manage("sign_in_methods") }
|
||
if page == PAGE_ACCOUNT { ManagementHome(0); return }
|
||
if !Save() { return }
|
||
if management_depth < cast(s32)management_stack.count {
|
||
management_stack[management_depth] = management_page
|
||
management_depth += 1
|
||
}
|
||
management_page = page
|
||
management_scroll = 0
|
||
notice = ""
|
||
fields = .{}
|
||
}
|
||
|
||
// Shows page with only the profile behind it.
|
||
ManagementHome :: (page: s32) {
|
||
management_page = ifx page == PAGE_ACCOUNT then 0 else page
|
||
management_depth = 0
|
||
if management_page != 0 {
|
||
management_stack[0] = 0
|
||
management_depth = 1
|
||
}
|
||
management_scroll = 0
|
||
fields = .{}
|
||
}
|
||
|
||
// Returns to the page that opened this one; false on the profile.
|
||
ManagementBack :: () -> bool {
|
||
if alias_modal_open {
|
||
alias_modal_open = false
|
||
return true
|
||
}
|
||
if management_page == 0 { return false }
|
||
// Leaving the link page ends its code and the polling behind it.
|
||
if management_page == PAGE_LINK && management.link_stage != 0 && management.link_stage != 6 { Manage("link_cancel") }
|
||
if management_page == PAGE_IMPORT && management.password_needed { Manage("import_cancel") }
|
||
management_page = 0
|
||
if management_depth > 0 {
|
||
management_depth -= 1
|
||
management_page = management_stack[management_depth]
|
||
}
|
||
management_scroll = 0
|
||
notice = ""
|
||
PasswordClear()
|
||
fields = .{}
|
||
return true
|
||
}
|
||
|
||
Muted :: (key: u64, text: string, x: float32, y: float32, width: float32, font: s32 = 14, align: TextAlign = TextAlign.TextAlignStart) {
|
||
Text(session, TextProps.{.key = key, .text = text, .bounds = Rectangle.{x, y, width, 24.0 * scale},
|
||
.font = cast(s32)(cast(float32)font * scale), .wrap = TextWrap.TextWrapEllipsis,
|
||
.align = align, .disabled = true})
|
||
}
|
||
|
||
// A full-width button: filled for the page's main action, soft otherwise,
|
||
// plain text for quiet and dangerous actions.
|
||
WideButton :: (id: s32, label: string, x: float32, y: *float32, width: float32, filled: bool = false,
|
||
quiet: bool = false, danger: bool = false) -> bool {
|
||
pressed := Button(session, ButtonProps.{.key = cast(u64)id, .id = id,
|
||
.bounds = Rectangle.{x, y.*, width, 48.0 * scale}, .label = label, .selected = filled,
|
||
.tone = ifx danger then ButtonTone.ButtonToneDanger else ifx filled then ButtonTone.ButtonToneAccent else ButtonTone.ButtonToneNeutral,
|
||
.emphasis = ifx filled then ButtonEmphasis.ButtonEmphasisFilled else ifx quiet || danger then ButtonEmphasis.ButtonEmphasisGhost else ButtonEmphasis.ButtonEmphasisSoft}) != 0
|
||
y.* += 60.0 * scale
|
||
return pressed
|
||
}
|
||
|
||
// Profile navigation uses one icon, label, optional detail and arrow row.
|
||
ProfileRowShape :: (id: s32) -> string {
|
||
if id == 551 { return ExtensionShape("friends") }
|
||
if id == 550 { return ExtensionShape("leaderboard") }
|
||
if id == 704 { return "S1.7rr:M12 4V12M5 20V12H19V20M2 20H8M16 20H22M9 4H15" }
|
||
if id == 823 { return "S1.7rr:M12 3V15M7 10L12 15L17 10M4 20H20" }
|
||
if id == 821 || id == 832 { return "S1.7rr:M12 16V4M7 9L12 4L17 9M4 20H20" }
|
||
if id == 822 || id == 824 { return "S1.7rr:M10 14L14 10M8 16L6 18C1 23 -2 16 3 13L7 9M16 8L18 6C23 1 26 8 21 11L17 15" }
|
||
if id == 830 { return "S1.7rr:M10 4H4V20H10M9 12H22M17 7L22 12L17 17" }
|
||
if id == 831 { return "S1.7rr:M4 6H20M9 6V3H15V6M6 6L7 21H17L18 6M10 10V17M14 10V17" }
|
||
if id == 818 { return "S1.7rr:M20 8C19.24 5.06 16.89 2.8 13.93 2.17C10.96 1.53 7.89 2.63 6 5L3 8M3 3V8H8M4 16C4.76 18.94 7.11 21.2 10.07 21.83C13.04 22.47 16.11 21.37 18 19L21 16M16 16H21V21" }
|
||
if id == 10 { return "S1.7rr:M3 4H21V20H3ZM3 16L8 11L13 16L17 12L21 16M15 8H15.01" }
|
||
return "S1.7rr:M12 3C14.21 3 16 4.79 16 7C16 9.21 14.21 11 12 11C9.79 11 8 9.21 8 7C8 4.79 9.79 3 12 3M4 21V18C4 12 20 12 20 18V21"
|
||
}
|
||
ListRow :: (id: s32, label: string, value: string, x: float32, y: *float32, width: float32,
|
||
dot: s32 = 0, icon: string = "", subtitle: string = "", danger: bool = false) -> bool {
|
||
height := (ifx subtitle == "" then 60.0 else 76.0) * scale
|
||
row := Rectangle.{x, y.*, width, height}
|
||
pressed := Button(session, ButtonProps.{.key = cast(u64)id, .id = id, .bounds = row,
|
||
.label = label, .invisible = true,
|
||
.tone = ifx danger then ButtonTone.ButtonToneDanger else ButtonTone.ButtonToneNeutral}) != 0
|
||
color := ifx danger then ThemeOr("danger", 0xe78a86ff, 0xb53e38ff) else ThemeOr("text", 0xe5eef3ff, 0x203b4bff)
|
||
SvgIcon(session, SvgIconProps.{.shape = ifx icon == "" then ProfileRowShape(id) else icon, .color = color,
|
||
.bounds = Rectangle.{x + 4.0 * scale, y.* + 16.0 * scale, 24.0 * scale, 24.0 * scale}})
|
||
left := x + 44.0 * scale
|
||
if dot != 0 {
|
||
Box(session, BoxProps.{.key = cast(u64)(id + 31000),
|
||
.bounds = Rectangle.{left, y.* + 23.0 * scale, 10.0 * scale, 10.0 * scale}, .radius = 5.0 * scale,
|
||
.fill = ifx dot == 1 then ThemeOr("accent", 0x49a68eff, 0x298a71ff) else ThemeOr("border", 0x34514aff, 0xc9d6d1ff)})
|
||
left += 22.0 * scale
|
||
}
|
||
label_width := x + width - 32.0 * scale - left
|
||
if value != "" { label_width = label_width * 0.55 }
|
||
TextLine(cast(u64)(id + 32000), label, left, y.* + (ifx subtitle == "" then 16.0 else 8.0) * scale, label_width, 16)
|
||
if subtitle != "" { Muted(cast(u64)(id + 35000), subtitle, left, y.* + 36.0 * scale, width - 76.0 * scale, 13) }
|
||
if value != "" {
|
||
Muted(cast(u64)(id + 33000), value, left + label_width, y.* + 16.0 * scale,
|
||
x + width - 32.0 * scale - (left + label_width), 14, TextAlign.TextAlignEnd)
|
||
}
|
||
SvgIcon(session, SvgIconProps.{.shape = "S1.7rr:M9 5L16 12L9 19", .color = color,
|
||
.bounds = Rectangle.{x + width - 24.0 * scale, y.* + 18.0 * scale, 20.0 * scale, 20.0 * scale}})
|
||
Box(session, BoxProps.{.key = cast(u64)(id + 36000),
|
||
.bounds = Rectangle.{x + 44.0 * scale, y.* + height, width - 44.0 * scale, 1.0},
|
||
.fill = ThemeOr("border", 0x34514aff, 0xdde7e3ff)})
|
||
y.* += height + 8.0 * scale
|
||
return pressed
|
||
}
|
||
|
||
ShortId :: (identity: string) -> string {
|
||
if identity.count <= 12 { return identity }
|
||
unused CopyCString(identity[:4], account_short_id[:])
|
||
unused CopyCString("…", account_short_id[4:])
|
||
unused CopyCString(identity[identity.count - 4:], account_short_id[7:])
|
||
return TextUntilNul(account_short_id[:])
|
||
}
|
||
|
||
account_name: [48]u8;
|
||
|
||
AccountName :: () -> string {
|
||
alias := TextUntilNul(management.alias[:])
|
||
if alias != "" && alias.count + 2 <= account_name.count {
|
||
account_name = .{}
|
||
account_name[0] = cast(u8)64
|
||
for byte, index: alias { account_name[index + 1] = byte }
|
||
return TextUntilNul(account_name[:])
|
||
}
|
||
return ShortId(TextUntilNul(management.public_id[:]))
|
||
}
|
||
|
||
ManagementNodeAt :: (address: string) -> s32 {
|
||
for index: 0..management.node_count - 1 {
|
||
if TextUntilNul(management.nodes[index].address[:]) == address { return cast(s32)index }
|
||
}
|
||
return -1
|
||
}
|
||
|
||
NodeConnected :: (index: s32) -> bool {
|
||
at := ManagementNodeAt(TextUntilNul(state.nodes[index][:]))
|
||
return at >= 0 && management.nodes[at].active
|
||
}
|
||
|
||
// A node's host name, which is how people know it.
|
||
NodeHost :: (address: string) -> string {
|
||
if address.count > 8 && address[:8] == "https://" { return address[8:] }
|
||
if address.count > 7 && address[:7] == "http://" { return address[7:] }
|
||
return address
|
||
}
|
||
|
||
nodes_summary: [32]u8;
|
||
|
||
NodesSummary :: () -> string {
|
||
connected: s32 = 0
|
||
for index: 0..state.node_count - 1 { if NodeConnected(cast(s32)index) { connected += 1 } }
|
||
if connected == 0 { return Label("entity.nodes_none", "None connected") }
|
||
out: Vec(u8)
|
||
BuilderPrint(*out, "% %", connected, Label("entity.nodes_connected", "connected"))
|
||
unused CopyCString(BuilderFinish(out), nodes_summary[:])
|
||
return TextUntilNul(nodes_summary[:])
|
||
}
|
||
|
||
ByteLabel :: (bytes: s64) -> string {
|
||
out: Vec(u8)
|
||
if bytes >= 1073741824 { BuilderPrint(*out, "% GB", bytes / 1073741824) }
|
||
else if bytes >= 1048576 { BuilderPrint(*out, "% MB", bytes / 1048576) }
|
||
else if bytes >= 1024 { BuilderPrint(*out, "% KB", bytes / 1024) }
|
||
else { BuilderPrint(*out, "% B", bytes) }
|
||
return BuilderFinish(out)
|
||
}
|
||
|
||
StorageUsageLabel :: (used: s64, limit: s64) -> string {
|
||
template := Label("entity.storage_used_of", "%s of %s used")
|
||
if limit <= 0 {
|
||
template = Label("entity.storage_used_unlimited", "%s used · no limit")
|
||
}
|
||
values: [2]string = .[ByteLabel(used), ByteLabel(limit)]
|
||
out: Vec(u8)
|
||
start: s64 = 0
|
||
at: s64 = 0
|
||
argument: s32 = 0
|
||
while at + 1 < template.count && argument < 2 {
|
||
if template[at:at + 2] == "%s" {
|
||
BuilderPrint(*out, "%", template[start:at])
|
||
BuilderPrint(*out, "%", values[argument])
|
||
argument += 1
|
||
at += 2
|
||
start = at
|
||
} else {
|
||
at += 1
|
||
}
|
||
}
|
||
BuilderPrint(*out, "%", template[start:])
|
||
return BuilderFinish(out)
|
||
}
|
||
|
||
ContinueLabel :: () -> string {
|
||
name := TextUntilNul(management.shared_name[:])
|
||
out: Vec(u8)
|
||
template := Label("entity.continue_as", "Continue as %s")
|
||
at: s64 = 0
|
||
start: s64 = 0
|
||
while at + 1 < template.count {
|
||
if template[at] == #char "%" && template[at + 1] == #char "s" { break }
|
||
at += 1
|
||
}
|
||
if at + 1 >= template.count { return template }
|
||
BuilderPrint(*out, "%", template[start:at])
|
||
if name.count == 64 { BuilderPrint(*out, "%", ShortId(name)) }
|
||
else { BuilderPrint(*out, "@%", name) }
|
||
BuilderPrint(*out, "%", template[at + 2:])
|
||
return BuilderFinish(out)
|
||
}
|
||
|
||
// The choices for someone without an account here.
|
||
SignInChoices :: (x: float32, y: *float32, width: float32) {
|
||
if CanManage(ACCOUNT_CONTINUE) && ListRow(8801, ContinueLabel(), "", x, y, width) { Manage("continue") }
|
||
if (CanManage(ACCOUNT_IMPORT) || CanManage(ACCOUNT_PASTE)) &&
|
||
ListRow(821, Label("entity.sign_in", "Sign in"), "", x, y, width) { OpenManagement(PAGE_IMPORT) }
|
||
if CanManage(ACCOUNT_CREATE) && ListRow(820, Label("entity.create_account", "Create account"), "", x, y, width) { Manage("create") }
|
||
if CanManage(ACCOUNT_LINK) && ListRow(822, Label("entity.link_device", "Link a device"), "", x, y, width) {
|
||
OpenManagement(PAGE_LINK)
|
||
}
|
||
}
|
||
|
||
SignInChoicesHeight :: () -> float32 {
|
||
count: s32 = 0
|
||
if CanManage(ACCOUNT_CREATE) { count += 1 }
|
||
if CanManage(ACCOUNT_IMPORT) || CanManage(ACCOUNT_PASTE) { count += 1 }
|
||
if CanManage(ACCOUNT_LINK) { count += 1 }
|
||
if CanManage(ACCOUNT_CONTINUE) { count += 1 }
|
||
return cast(float32)count * 68.0 * scale
|
||
}
|
||
|
||
// The profile's account entry: a card of sign-in choices, or one row.
|
||
AccountSummary :: (x: float32, y: *float32, width: float32) {
|
||
if management.account {
|
||
PublicIdLine(705, Rectangle.{x, y.*, width, 44.0 * scale})
|
||
y.* += 56.0 * scale
|
||
// Another waozi.xyz site is signed in to a different account.
|
||
if CanManage(ACCOUNT_CONTINUE) && ListRow(8801, ContinueLabel(), "", x, y, width) { Manage("continue") }
|
||
return
|
||
}
|
||
padding := 16.0 * scale
|
||
height := padding * 2.0 + 56.0 * scale + SignInChoicesHeight() - 12.0 * scale
|
||
Box(session, BoxProps.{.key = cast(u64)703, .bounds = Rectangle.{x, y.*, width, height},
|
||
.fill = ThemeOr("surface", 0x1c3330ff, 0xffffffff),
|
||
.border = ThemeOr("border", 0x34514aff, 0xdde7e3ff), .radius = 16.0 * scale})
|
||
inner := x + padding
|
||
top := y.* + padding
|
||
TextLine(700, Label("entity.account", "Account"), inner, top, width - padding * 2.0, 18)
|
||
Muted(701, Label("entity.signed_out", "Not signed in"), inner, top + 28.0 * scale, width - padding * 2.0)
|
||
top += 56.0 * scale
|
||
SignInChoices(inner, *top, width - padding * 2.0)
|
||
y.* += height + 12.0 * scale
|
||
}
|
||
|
||
// Show the alias in Profile; the full public ID stays in its copy/QR dialog.
|
||
PublicIdLine :: (id: s32, bounds: Rectangle) {
|
||
identity := TextUntilNul(management.public_id[:])
|
||
text_bounds := bounds
|
||
text_bounds.width -= 48.0 * scale
|
||
props := TextProps.{.key = cast(u64)(id + 1000), .text = AccountName(),
|
||
.bounds = text_bounds, .font = cast(s32)(14.0 * scale),
|
||
.align = TextAlign.TextAlignCenter, .vertical_align = TextAlign.TextAlignCenter,
|
||
.wrap = TextWrap.TextWrapEllipsis}
|
||
if TextWidth(session, props) > cast(s32)text_bounds.width { props.text = ShortId(identity) }
|
||
group_width := cast(float32)TextWidth(session, props) + 52.0 * scale
|
||
if group_width > bounds.width { group_width = bounds.width }
|
||
text_bounds.x = bounds.x + (bounds.width - group_width) * 0.5
|
||
text_bounds.width = group_width - 52.0 * scale
|
||
props.bounds = text_bounds
|
||
Text(session, props)
|
||
if Button(session, ButtonProps.{.key = cast(u64)id, .id = id,
|
||
.bounds = text_bounds, .label = Label("entity.public_id", "Public ID"), .invisible = true}) != 0 {
|
||
public_id_owner = management.public_id
|
||
public_id_copied = false
|
||
public_id_scroll = 0
|
||
public_id_open = true
|
||
fields = .{}
|
||
}
|
||
if Button(session, ButtonProps.{.key = cast(u64)(id + 1), .id = id + 1,
|
||
.bounds = Rectangle.{text_bounds.x + text_bounds.width + 8.0 * scale, bounds.y, 44.0 * scale, 44.0 * scale},
|
||
.label = Label(ifx public_id_copied then "entity.copied" else "entity.copy_id", ifx public_id_copied then "Copied" else "Copy public ID"), .icon_only = true,
|
||
.icon_shape = ifx public_id_copied then "S1.8rr:M5 12L10 17L20 7" else "S1.6rr:M8 8H20V20H8ZM16 8V4H4V16H8",
|
||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisGhost}) != 0 {
|
||
public_id_copied = ClipboardCopy(identity, 0)
|
||
}
|
||
}
|
||
|
||
PublicIdModal :: () {
|
||
if !public_id_open { return }
|
||
identity := TextUntilNul(public_id_owner[:])
|
||
if !management.account || identity != TextUntilNul(management.public_id[:]) {
|
||
public_id_open = false
|
||
return
|
||
}
|
||
area := AppBounds()
|
||
width := area.width - 32.0 * scale
|
||
if width > 680.0 * scale { width = 680.0 * scale }
|
||
height := area.height - 24.0 * scale
|
||
if height > 520.0 * scale { height = 520.0 * scale }
|
||
modal := ModalFrame(session, ModalFrameProps.{.key = cast(u64)19500, .id = 19500,
|
||
.title = Label("entity.public_id", "Public ID"),
|
||
.bounds = Rectangle.{area.x + (area.width - width) * 0.5, area.y + (area.height - height) * 0.5, width, height},
|
||
.scale = scale, .has_right_action = true, .right_label = Label("entity.done", "Done")})
|
||
if modal.dismissed || modal.right_clicked { public_id_open = false }
|
||
if !modal.opened { return }
|
||
content := modal.layout.content
|
||
// A public ID has no word boundaries; break it explicitly at the host's
|
||
// measured line width, while copy and QR keep the original 64 digits.
|
||
start: s64 = 0
|
||
length: s64 = 0
|
||
for byte, index: identity {
|
||
probe := TextProps.{.text = identity[start:index + 1], .font = cast(s32)(15.0 * scale)}
|
||
if index > start && TextWidth(session, probe) > cast(s32)(content.width - 16.0 * scale) {
|
||
public_id_display[length] = #char "\n"; length += 1; start = index
|
||
}
|
||
public_id_display[length] = byte; length += 1
|
||
}
|
||
public_id_display[length] = 0
|
||
props := TextProps.{.key = cast(u64)19502, .text = TextUntilNul(public_id_display[:]),
|
||
.bounds = Rectangle.{0.0, 0.0, content.width - 16.0 * scale, 0.0},
|
||
.font = cast(s32)(15.0 * scale), .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapAuto}
|
||
id_height := cast(float32)TextHeight(session, props) + 16.0 * scale
|
||
if id_height < 44.0 * scale { id_height = 44.0 * scale }
|
||
// Short landscape screens scroll; the complete ID never truncates.
|
||
scroll := Scroll(session, ScrollProps.{.key = cast(u64)19501, .bounds = content,
|
||
.content_height = cast(s32)(336.0 * scale + id_height), .scroll_offset = public_id_scroll, .scale = scale})
|
||
public_id_scroll = scroll.scroll_offset
|
||
if scroll.opened {
|
||
y := scroll.content.y
|
||
side := DrawConnectionCode(identity, scroll.content.x, y, scroll.content.width)
|
||
y += side + 16.0 * scale
|
||
props.bounds = Rectangle.{scroll.content.x + 8.0 * scale, y, scroll.content.width - 16.0 * scale, id_height}
|
||
Text(session, props)
|
||
if Button(session, ButtonProps.{.key = cast(u64)19503, .id = 19503,
|
||
.bounds = props.bounds, .label = identity, .invisible = true}) != 0 {
|
||
public_id_copied = ClipboardCopy(identity, 0)
|
||
}
|
||
y += id_height
|
||
if Action(19504, Label(ifx public_id_copied then "entity.copied" else "entity.copy_id",
|
||
ifx public_id_copied then "Copied" else "Copy public ID"),
|
||
Rectangle.{scroll.content.x, y, scroll.content.width, 44.0 * scale}) {
|
||
public_id_copied = ClipboardCopy(identity, 0)
|
||
}
|
||
unused End(session)
|
||
}
|
||
unused End(session)
|
||
AppKeyboard(false)
|
||
}
|
||
|
||
// Connection codes are drawn as rectangles worked out once per code, so a
|
||
// shown code costs only its boxes each frame.
|
||
QrRect :: struct { column: s32; row: s32; width: s32; height: s32 }
|
||
QR_RECTS :: 2048
|
||
qr_rects: [QR_RECTS]QrRect;
|
||
qr_rect_count: s32;
|
||
|
||
QrBuild :: () {
|
||
qr_rect_count = 0
|
||
open: [QR_SIZE_MAX]s32
|
||
next: [QR_SIZE_MAX]s32
|
||
for column: 0..QR_SIZE_MAX - 1 { open[column] = -1 }
|
||
for row: 0..qr_code.size - 1 {
|
||
for column: 0..QR_SIZE_MAX - 1 { next[column] = -1 }
|
||
column: s32 = 0
|
||
while column < qr_code.size {
|
||
if !QrModule(*qr_code, column, row) { column += 1; continue }
|
||
start := column
|
||
while column < qr_code.size && QrModule(*qr_code, column, row) { column += 1 }
|
||
above := open[start]
|
||
if above >= 0 && qr_rects[above].width == column - start {
|
||
// The same run as the row above grows that rectangle.
|
||
qr_rects[above].height += 1
|
||
next[start] = above
|
||
} else if qr_rect_count < QR_RECTS {
|
||
qr_rects[qr_rect_count] = QrRect.{start, cast(s32)row, column - start, 1}
|
||
next[start] = qr_rect_count
|
||
qr_rect_count += 1
|
||
} else {
|
||
qr_valid = false
|
||
return
|
||
}
|
||
}
|
||
open = next
|
||
}
|
||
}
|
||
|
||
// Draws the code in a square at most width wide; returns its side.
|
||
DrawConnectionCode :: (text: string, x: float32, y: float32, width: float32) -> float32 {
|
||
if text != TextUntilNul(qr_text[:]) {
|
||
qr_valid = CopyCString(text, qr_text[:]) && QrEncodeText(text, QrEcc.QrEccMedium, *qr_code)
|
||
if qr_valid { QrBuild() }
|
||
}
|
||
if !qr_valid { return 0.0 }
|
||
modules := qr_code.size + 8
|
||
limit := cast(s32)width
|
||
if limit > cast(s32)(260.0 * scale) { limit = cast(s32)(260.0 * scale) }
|
||
cell := limit / modules
|
||
if cell < 1 { return 0.0 }
|
||
side := cell * modules
|
||
left := cast(s32)(x + (width - cast(float32)side) * 0.5)
|
||
top := cast(s32)y
|
||
Box(session, BoxProps.{.key = cast(u64)19000, .radius = 8.0 * scale,
|
||
.bounds = Rectangle.{cast(float32)left, y, cast(float32)side, cast(float32)side}, .fill = Color.{255, 255, 255, 255}})
|
||
for index: 0..qr_rect_count - 1 {
|
||
rect := qr_rects[index]
|
||
Box(session, BoxProps.{.key = cast(u64)(20000 + index),
|
||
.bounds = Rectangle.{cast(float32)(left + (rect.column + 4) * cell), cast(float32)(top + (rect.row + 4) * cell),
|
||
cast(float32)(rect.width * cell), cast(float32)(rect.height * cell)}, .fill = Color.{0, 0, 0, 255}})
|
||
}
|
||
return cast(float32)side
|
||
}
|
||
|
||
PageTitle :: () -> string {
|
||
if management_page == PAGE_IMPORT { return Label("entity.sign_in", "Sign in") }
|
||
if management_page == PAGE_BACKUP { return Label("entity.back_up_account", "Back up account") }
|
||
if management_page == PAGE_SIGN_IN_METHODS { return Label("entity.sign_in_methods", "Sign-in options") }
|
||
if management_page == PAGE_LOGOUT { return Label("entity.logout", "Sign out") }
|
||
if management_page == PAGE_CLEAR { return Label("entity.clear_remote", "Clear remote data") }
|
||
if management_page == PAGE_SWITCH { return Label("entity.switch_account", "Switch account") }
|
||
if management_page == PAGE_LINK { return Label("entity.link_device", "Link a device") }
|
||
if management_page == PAGE_NODES { return Label("entity.nodes", "Nodes") }
|
||
if management_page == PAGE_NODE && node_open < state.node_count { return NodeHost(TextUntilNul(state.nodes[node_open][:])) }
|
||
if management_page == PAGE_ADD_NODE { return Label("entity.add_node", "Add node") }
|
||
if management_page == PAGE_APPEARANCE { return Label("entity.appearance", "Appearance") }
|
||
if management_page == PAGE_FRIENDS { return Label("profile_friends_title", "Friends") }
|
||
if management_page == PAGE_ALIAS { return Label("entity.alias", "Username") }
|
||
return Label("entity.account", "Account")
|
||
}
|
||
|
||
SYNC_SHAPE :: "S1.7rr:M7 19C4.2 19 2 16.8 2 14C2 11.4 4 9.3 6.5 9C7.3 6.1 9.9 4 13 4C16.6 4 19.5 6.9 19.5 10.5C21 11 22 12.4 22 14.2C22 16.9 19.9 19 17.2 19Z";
|
||
|
||
// Account controls are part of Profile, with one navigation stack.
|
||
AccountActions :: (x: float32, y: *float32, width: float32) {
|
||
if !management.account { return }
|
||
if CanManage(ACCOUNT_SYNC) {
|
||
// Laid out like ListRow: icon, label and divider, with the toggle for its arrow.
|
||
SvgIcon(session, SvgIconProps.{.shape = SYNC_SHAPE, .color = ThemeOr("text", 0xe5eef3ff, 0x203b4bff),
|
||
.bounds = Rectangle.{x + 4.0 * scale, y.* + 16.0 * scale, 24.0 * scale, 24.0 * scale}})
|
||
TextLine(815, Label("entity.sync", "Sync"), x + 44.0 * scale, y.* + 16.0 * scale, width - 120.0 * scale, 16)
|
||
result := Toggle(session, ToggleProps.{.key = cast(u64)816, .id = 816,
|
||
.bounds = Rectangle.{x + width - 64.0 * scale, y.* + 10.0 * scale, 64.0 * scale, 40.0 * scale},
|
||
.label = Label("entity.sync", "Sync"), .value = management.enabled, .disabled = management_waiting > management.completed})
|
||
if result.changed { Manage("set_sync", "", "", ifx result.value then 1 else 0) }
|
||
Box(session, BoxProps.{.key = cast(u64)36815,
|
||
.bounds = Rectangle.{x + 44.0 * scale, y.* + 60.0 * scale, width - 44.0 * scale, 1.0},
|
||
.fill = ThemeOr("border", 0x34514aff, 0xdde7e3ff)})
|
||
y.* += 68.0 * scale
|
||
if management.queued > 0 {
|
||
out: Vec(u8)
|
||
BuilderPrint(*out, "%: %", Label("entity.queued", "Waiting to sync"), management.queued)
|
||
Muted(817, BuilderFinish(out), x + 44.0 * scale, y.*, width - 44.0 * scale)
|
||
y.* += 32.0 * scale
|
||
}
|
||
if ListRow(818, Label("entity.sync_now", "Sync now"), "", x, y, width) { Manage("sync") }
|
||
}
|
||
if CanManage(ACCOUNT_ALIAS) {
|
||
alias := TextUntilNul(management.alias[:])
|
||
if ListRow(819, Label("entity.alias", "Username"), ifx alias == "" then Label("entity.alias_unset", "Not set") else alias, x, y, width) {
|
||
OpenManagement(PAGE_ALIAS)
|
||
}
|
||
}
|
||
if CanManage(ACCOUNT_BACKUP) && ListRow(823, Label("entity.back_up_account", "Back up account"), "", x, y, width) { OpenManagement(PAGE_BACKUP) }
|
||
if (CanManage(ACCOUNT_PASSKEY) || CanManage(ACCOUNT_GOOGLE)) && ListRow(8810, Label("entity.sign_in_methods", "Sign-in options"), "", x, y, width) { OpenManagement(PAGE_SIGN_IN_METHODS) }
|
||
if CanManage(ACCOUNT_IMPORT) && ListRow(832, Label("entity.sign_in_other", "Sign in to another account"), "", x, y, width) { OpenManagement(PAGE_IMPORT) }
|
||
if CanManage(ACCOUNT_LINK) && ListRow(824, Label("entity.link_another", "Link another device"), "", x, y, width) { OpenManagement(PAGE_LINK) }
|
||
if management.account {
|
||
y.* += 8.0 * scale
|
||
if CanManage(ACCOUNT_LOGOUT) && ListRow(830, Label("entity.logout", "Sign out"), "", x, y, width, 0, "", "", true) { SignOutPressed() }
|
||
if CanManage(ACCOUNT_CLEAR_REMOTE) && ListRow(831, Label("entity.clear_remote", "Clear remote data"), "", x, y, width, 0, "", "", true) {
|
||
OpenManagement(PAGE_CLEAR)
|
||
}
|
||
}
|
||
}
|
||
|
||
AccountPage :: (x: float32, y: *float32, width: float32) {
|
||
AccountSummary(x, y, width)
|
||
AccountActions(x, y, width)
|
||
}
|
||
|
||
// Text of any length: it takes the lines it needs and moves the page down.
|
||
Note :: (key: u64, text: string, x: float32, y: *float32, width: float32) {
|
||
props := TextProps.{.key = key, .text = text, .bounds = Rectangle.{x, y.*, width, 0.0},
|
||
.font = cast(s32)(14.0 * scale), .wrap = TextWrap.TextWrapAuto}
|
||
height := cast(float32)TextHeight(session, props)
|
||
props.bounds.height = height
|
||
Text(session, props)
|
||
y.* += height + 12.0 * scale
|
||
}
|
||
|
||
// A passkey, a password and Google are easier ways in; the .key backup stays the
|
||
// master key, so nothing here holds a person back from removing one.
|
||
SignInMethodsPage :: (x: float32, y: *float32, width: float32) {
|
||
Note(8811, Label("entity.master_key", "Your .key backup is your master key. Keep it safe."), x, y, width)
|
||
Note(8812, Label("entity.easier_ways", "A passkey, password or Google are only easier ways in."), x, y, width)
|
||
if CanManage(ACCOUNT_PASSKEY) {
|
||
for index: 0..management.passkey_count - 1 {
|
||
entry := *management.passkeys[index]
|
||
label := TextUntilNul(entry.label[:])
|
||
if ListRow(cast(s32)(8820 + index), ifx label == "" then Label("entity.passkey", "Passkey") else label, Label("entity.remove", "Remove"), x, y, width) {
|
||
Manage("passkey_remove", "", TextUntilNul(entry.credential[:]))
|
||
}
|
||
}
|
||
if WideButton(8813, Label("entity.passkey_add", "Add a passkey"), x, y, width, true) { Manage("passkey_add") }
|
||
Note(8814, Label("entity.passkey_help", "A passkey unlocks a sealed copy of your key kept on this node. The node never sees it unlocked."), x, y, width)
|
||
}
|
||
if CanManage(ACCOUNT_GOOGLE) {
|
||
if management.google_linked {
|
||
if WideButton(8815, Label("entity.google_unlink", "Unlink Google"), x, y, width, false, true) { Manage("google_unlink") }
|
||
} else if WideButton(8816, Label("entity.google_link", "Link Google"), x, y, width) { Manage("google_link") }
|
||
Note(8817, Label("entity.google_help", "Google only finds your account. Your password or passkey still unlocks it."), x, y, width)
|
||
}
|
||
}
|
||
|
||
// The file and its password are the login: nothing can reset them, so the page
|
||
// says so, and a backup is never saved without a password.
|
||
BackupPage :: (x: float32, y: *float32, width: float32) {
|
||
Note(8818, Label("entity.master_key", "Your .key backup is your master key. Keep it safe."), x, y, width)
|
||
Note(841, Label("entity.no_reset", "No one can reset your password, so keep a backup."), x, y, width)
|
||
Note(8802, Label("entity.backup_help", "If you lose your backup and password and have no other signed-in device, your account cannot be recovered."), x, y, width)
|
||
unused EditField(4, account_passphrase[:], Label("entity.password", "Password"), Rectangle.{x, y.*, width, 48.0 * scale}, 160, true)
|
||
y.* += 64.0 * scale
|
||
unused EditField(1, account_passphrase_repeat[:], Label("entity.password_repeat", "Repeat password"), Rectangle.{x, y.*, width, 48.0 * scale}, 160, true)
|
||
y.* += 64.0 * scale
|
||
drive_backup := CanManage(ACCOUNT_DRIVE) && WideButton(848, "Google Drive", x, y, width, false)
|
||
if WideButton(803, Label("entity.save_backup", "Save backup file"), x, y, width, true) || drive_backup {
|
||
password: [512]u8
|
||
for index: 0..password.count - 1 { password[index] = account_passphrase[index] }
|
||
{
|
||
value := TextUntilNul(password[:])
|
||
if !ManagementPasswordAccepted(value) { notice = Label("entity.password_rule", "Use a password of at least 12 characters") }
|
||
else if value != TextUntilNul(account_passphrase_repeat[:]) { notice = Label("entity.password_mismatch", "The passwords do not match") }
|
||
else { Manage(ifx drive_backup then "drive_backup" else "backup", value) }
|
||
}
|
||
for index: 0..password.count - 1 { password[index] = cast(u8)0 }
|
||
}
|
||
if WideButton(8803, Label("entity.save_online", "Save backup online"), x, y, width) {
|
||
password: [512]u8
|
||
for index: 0..password.count - 1 { password[index] = account_passphrase[index] }
|
||
{
|
||
value := TextUntilNul(password[:])
|
||
if !ManagementPasswordAccepted(value) { notice = Label("entity.password_rule", "Use a password of at least 12 characters") }
|
||
else if value != TextUntilNul(account_passphrase_repeat[:]) { notice = Label("entity.password_mismatch", "The passwords do not match") }
|
||
else { Manage("backup_online", value) }
|
||
}
|
||
for index: 0..password.count - 1 { password[index] = cast(u8)0 }
|
||
}
|
||
if WideButton(8804, Label("entity.remove_online", "Remove online backup"), x, y, width, false, true) { Manage("backup_online_remove") }
|
||
Note(842, Label("entity.security_note", "Your account signs with post-quantum ML-DSA-44 keys. A backup is encrypted with your password on this device; a node keeps only that sealed copy and never sees your password."), x, y, width)
|
||
}
|
||
|
||
// First the backup, then its password if it has one: a mistyped password never
|
||
// means finding the file again, and older files without a password just open.
|
||
SignInPage :: (x: float32, y: *float32, width: float32) {
|
||
if management.password_needed {
|
||
Note(843, Label("entity.sign_in_password_help", "Enter the password you chose for this backup."), x, y, width)
|
||
unused EditField(4, account_passphrase[:], Label("entity.password", "Password"), Rectangle.{x, y.*, width, 48.0 * scale}, 160, true)
|
||
y.* += 64.0 * scale
|
||
if WideButton(844, Label("entity.sign_in", "Sign in"), x, y, width, true) {
|
||
password: [512]u8
|
||
for index: 0..password.count - 1 { password[index] = account_passphrase[index] }
|
||
Manage("import_password", TextUntilNul(password[:]))
|
||
for index: 0..password.count - 1 { password[index] = cast(u8)0 }
|
||
}
|
||
if WideButton(845, Label("entity.different_backup", "Use a different backup"), x, y, width, false, true) { Manage("import_cancel") }
|
||
return
|
||
}
|
||
Note(846, Label("entity.no_reset", "No one can reset your password, so keep a backup."), x, y, width)
|
||
if CanManage(ACCOUNT_PASSKEY) {
|
||
if WideButton(8830, Label("entity.passkey_sign_in", "Sign in with a passkey"), x, y, width, true) { Manage("passkey_sign_in") }
|
||
} else {
|
||
Note(8831, Label("entity.passkey_unavailable", "Passkeys are not available here. Use your password."), x, y, width)
|
||
}
|
||
if CanManage(ACCOUNT_GOOGLE) {
|
||
if WideButton(8832, Label("entity.google_sign_in", "Sign in with Google"), x, y, width) { Manage("google_sign_in") }
|
||
Note(8833, Label("entity.google_help", "Google only finds your account. Your password or passkey still unlocks it."), x, y, width)
|
||
}
|
||
found := TextUntilNul(management.found_account[:])
|
||
if found != "" && found != TextUntilNul(sign_in_found[:]) {
|
||
sign_in_found = management.found_account
|
||
unused CopyCString(found, sign_in_account[:])
|
||
}
|
||
unused EditField(7, sign_in_account[:], Label("entity.sign_in_account", "Username or public ID"), Rectangle.{x, y.*, width, 48.0 * scale}, 70)
|
||
y.* += 64.0 * scale
|
||
unused EditField(4, account_passphrase[:], Label("entity.password", "Password"), Rectangle.{x, y.*, width, 48.0 * scale}, 160, true)
|
||
y.* += 64.0 * scale
|
||
if WideButton(8805, Label("entity.sign_in", "Sign in"), x, y, width, true) {
|
||
password: [512]u8
|
||
for index: 0..password.count - 1 { password[index] = account_passphrase[index] }
|
||
account: [80]u8
|
||
account = sign_in_account
|
||
{
|
||
Manage("sign_in_online", TextUntilNul(password[:]), TextUntilNul(account[:]))
|
||
}
|
||
for index: 0..password.count - 1 { password[index] = cast(u8)0 }
|
||
for index: 0..account.count - 1 { account[index] = cast(u8)0 }
|
||
}
|
||
Note(8806, Label("entity.sign_in_online_help", "This works if you saved a backup online. Otherwise use your backup file or link a device."), x, y, width)
|
||
if CanManage(ACCOUNT_DRIVE) && WideButton(849, "Google Drive", x, y, width, false) { Manage("drive_import") }
|
||
if CanManage(ACCOUNT_IMPORT) && WideButton(805, Label("entity.choose_backup", "Choose backup file"), x, y, width, true) { Manage("import") }
|
||
if CanManage(ACCOUNT_PASTE) && WideButton(804, Label("entity.paste_backup", "Paste backup"), x, y, width, !CanManage(ACCOUNT_IMPORT)) { Manage("import_paste") }
|
||
}
|
||
|
||
KeyPage :: (x: float32, y: *float32, width: float32) {
|
||
if management_page == PAGE_SIGN_IN_METHODS { SignInMethodsPage(x, y, width) }
|
||
else if management_page == PAGE_IMPORT { SignInPage(x, y, width) }
|
||
else { BackupPage(x, y, width) }
|
||
}
|
||
|
||
// One reminder to back up, unless this device already did. Never a block.
|
||
SignOutPressed :: () {
|
||
if !ManagementSignOutWarns(*management) { Manage("logout"); return }
|
||
OpenManagement(PAGE_LOGOUT)
|
||
}
|
||
|
||
ConfirmPage :: (x: float32, y: *float32, width: float32) {
|
||
explanation := Label("entity.logout_help", "Your records stay on this device.")
|
||
if management_page == PAGE_CLEAR { explanation = Label("entity.clear_remote_help", "Removes this account's data from its node.") }
|
||
if management_page == PAGE_SWITCH { explanation = Label("entity.switch_help", "Keep this device's records with the new account?") }
|
||
Note(806, explanation, x, y, width)
|
||
if management_page == PAGE_LOGOUT {
|
||
if ManagementSignOutWarns(*management) {
|
||
Note(847, Label("entity.sign_out_warning", "Back up your key first. Without a backup or another signed-in device you cannot sign back in."), x, y, width)
|
||
if CanManage(ACCOUNT_BACKUP) && WideButton(8807, Label("entity.back_up_key", "Back up key"), x, y, width, true) {
|
||
sign_out_after_backup = true
|
||
OpenManagement(PAGE_BACKUP)
|
||
}
|
||
}
|
||
if WideButton(8808, Label("entity.logout", "Sign out"), x, y, width, false, false, true) { Manage("logout") }
|
||
return
|
||
}
|
||
if management_page == PAGE_SWITCH {
|
||
if WideButton(807, Label("entity.merge", "Keep and merge"), x, y, width, true) { Manage("switch_apply", "", "", 1) }
|
||
if WideButton(808, Label("entity.replace", "Replace them"), x, y, width, false, false, true) { Manage("switch_apply", "", "", 2) }
|
||
if WideButton(809, Label("entity.cancel", "Cancel"), x, y, width, false, true) { Manage("switch_cancel"); unused ManagementBack() }
|
||
return
|
||
}
|
||
if WideButton(807, PageTitle(), x, y, width, false, false, true) { Manage(ifx management_page == PAGE_LOGOUT then "logout" else "clear_remote") }
|
||
if WideButton(809, Label("entity.cancel", "Cancel"), x, y, width, false, true) { unused ManagementBack() }
|
||
}
|
||
|
||
LinkPage :: (x: float32, y: *float32, width: float32) {
|
||
stage := management.link_stage
|
||
if stage == 0 || stage == 7 {
|
||
if stage == 7 && management.link_message[0] != cast(u8)0 {
|
||
Paragraph(832, TextUntilNul(management.link_message[:]), x, y.*, width, 48.0)
|
||
y.* += 56.0 * scale
|
||
}
|
||
if WideButton(833, Label("entity.show_code", "Show a code"), x, y, width, true) { Manage("link_show") }
|
||
if CanManage(ACCOUNT_SCAN) && WideButton(834, Label("entity.scan_code", "Scan a code"), x, y, width) { Manage("link_scan") }
|
||
if CanManage(ACCOUNT_PASTE) && WideButton(835, Label("entity.paste_code", "Paste a code"), x, y, width) { Manage("link_paste") }
|
||
y.* += 8.0 * scale
|
||
unused EditField(5, account_code[:], Label("entity.enter_code", "Or type a code"), Rectangle.{x, y.*, width - 112.0 * scale, 48.0 * scale}, 1023)
|
||
if Button(session, ButtonProps.{.key = cast(u64)836, .id = 836, .label = Label("entity.connect", "Connect"),
|
||
.bounds = Rectangle.{x + width - 104.0 * scale, y.*, 104.0 * scale, 48.0 * scale},
|
||
.disabled = account_code[0] == cast(u8)0,
|
||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}) != 0 {
|
||
Manage("link_join", TextUntilNul(account_code[:]))
|
||
}
|
||
y.* += 64.0 * scale
|
||
return
|
||
}
|
||
if management.link_code[0] != cast(u8)0 {
|
||
side := DrawConnectionCode(TextUntilNul(management.link_code[:]), x, y.*, width)
|
||
y.* += side + 12.0 * scale
|
||
if WideButton(837, Label("entity.copy_code", "Copy code"), x, y, width, false, true) {
|
||
if ClipboardCopy(TextUntilNul(management.link_code[:]), 0) { notice = Label("entity.copied", "Copied") }
|
||
}
|
||
}
|
||
if management.link_message[0] != cast(u8)0 {
|
||
Paragraph(838, TextUntilNul(management.link_message[:]), x, y.*, width, 48.0, 16)
|
||
y.* += 56.0 * scale
|
||
}
|
||
if (stage == 2 || stage == 4) && WideButton(839, Label("entity.confirm_device", "The digits match, connect"), x, y, width, true) { Manage("link_confirm") }
|
||
if stage != 6 && WideButton(842, Label("entity.cancel", "Cancel"), x, y, width, false, true) { Manage("link_cancel") }
|
||
}
|
||
|
||
NodesPage :: (x: float32, y: *float32, width: float32) {
|
||
connected := false
|
||
for index: 0..state.node_count - 1 { if NodeConnected(cast(s32)index) { connected = true } }
|
||
if !connected {
|
||
Muted(850, Label("entity.not_connected", "Not connected to a node"), x + 4.0 * scale, y.*, width)
|
||
y.* += 36.0 * scale
|
||
}
|
||
for index: 0..state.node_count - 1 {
|
||
address_bytes: [256]u8
|
||
for byte: 0..255 { address_bytes[byte] = state.nodes[index][byte] }
|
||
address := TextUntilNul(address_bytes[:])
|
||
value := ifx state.preferred == index then Label("entity.default", "Default") else ""
|
||
if ListRow(851 + cast(s32)index, NodeHost(address), value, x, y, width, ifx NodeConnected(cast(s32)index) then 1 else 2) {
|
||
node_open = cast(s32)index
|
||
OpenManagement(PAGE_NODE)
|
||
}
|
||
}
|
||
y.* += 8.0 * scale
|
||
if state.node_count < ENTITY_NODE_LIMIT && WideButton(860, Label("entity.add_node", "Add node"), x, y, width, false, true) {
|
||
node_text[0] = cast(u8)0
|
||
OpenManagement(PAGE_ADD_NODE)
|
||
}
|
||
}
|
||
|
||
NodePage :: (x: float32, y: *float32, width: float32) {
|
||
if node_open < 0 || node_open >= state.node_count { unused ManagementBack(); return }
|
||
// A copy: removing the node below moves the saved list.
|
||
address_bytes: [256]u8
|
||
for byte: 0..255 { address_bytes[byte] = state.nodes[node_open][byte] }
|
||
address := TextUntilNul(address_bytes[:])
|
||
Muted(861, address, x, y.*, width)
|
||
y.* += 32.0 * scale
|
||
status := ifx NodeConnected(node_open) then Label("entity.connected", "Connected") else Label("entity.not_connected_short", "Not connected")
|
||
TextLine(862, status, x, y.*, width, 16)
|
||
y.* += 36.0 * scale
|
||
at := ManagementNodeAt(address)
|
||
if state.show_storage && at >= 0 && management.nodes[at].known {
|
||
node := management.nodes[at]
|
||
Muted(863, StorageUsageLabel(node.used, node.limit), x, y.*, width)
|
||
y.* += 32.0 * scale
|
||
}
|
||
if state.show_storage && at >= 0 && management.nodes[at].media_supported {
|
||
TextLine(864, Label("entity.node_media", "Upload photos and videos"), x, y.* + 10.0 * scale, width - 80.0 * scale, 15)
|
||
result := Toggle(session, ToggleProps.{.key = cast(u64)865, .id = 865,
|
||
.bounds = Rectangle.{x + width - 64.0 * scale, y.*, 64.0 * scale, 40.0 * scale},
|
||
.label = Label("entity.node_media", "Upload photos and videos"), .value = management.nodes[at].media,
|
||
.disabled = management.busy || management_waiting > management.completed})
|
||
if result.changed { Manage("media", "", address, ifx result.value then 1 else 0) }
|
||
y.* += 56.0 * scale
|
||
}
|
||
y.* += 8.0 * scale
|
||
if state.preferred == node_open {
|
||
Muted(866, Label("entity.default_node", "This is your default node"), x, y.*, width)
|
||
y.* += 40.0 * scale
|
||
} else if WideButton(867, Label("entity.make_default", "Make default"), x, y, width, true) {
|
||
state.preferred = node_open
|
||
unused Save()
|
||
}
|
||
if state.node_count > 1 && WideButton(868, Label("entity.remove", "Remove node"), x, y, width, false, true, true) {
|
||
for next: node_open..state.node_count - 2 { state.nodes[next] = state.nodes[next + 1] }
|
||
state.node_count -= 1
|
||
if state.preferred > node_open || state.preferred >= state.node_count { state.preferred -= 1 }
|
||
if state.preferred < 0 { state.preferred = 0 }
|
||
unused Save()
|
||
unused ManagementBack()
|
||
}
|
||
}
|
||
|
||
AddNodePage :: (x: float32, y: *float32, width: float32) {
|
||
submitted := EditField(2, node_text[:], Label("entity.node_address", "Node address"),
|
||
Rectangle.{x, y.*, width, 48.0 * scale}, 255)
|
||
y.* += 64.0 * scale
|
||
add := WideButton(870, Label("entity.add", "Add"), x, y, width, true)
|
||
if !submitted && !add { return }
|
||
added := false
|
||
{
|
||
snapshot := node_text
|
||
origin := NodeOrigin(TextUntilNul(snapshot[:]))
|
||
known := false
|
||
for index: 0..state.node_count - 1 { if TextUntilNul(state.nodes[index][:]) == origin { known = true } }
|
||
if origin == "" {
|
||
notice = Label("entity.node_invalid", "Enter a valid HTTPS node address")
|
||
} else if known {
|
||
added = true
|
||
} else if state.node_count >= ENTITY_NODE_LIMIT {
|
||
notice = Label("entity.node_limit", "Eight nodes are already saved")
|
||
} else {
|
||
unused CopyCString(origin, state.nodes[state.node_count][:])
|
||
state.node_count += 1
|
||
unused Save()
|
||
added = true
|
||
}
|
||
}
|
||
if added {
|
||
node_text[0] = cast(u8)0
|
||
unused ManagementBack()
|
||
}
|
||
}
|
||
|
||
DrawAccount :: () {
|
||
session = AppSession()
|
||
scale = AppScale()
|
||
if scale <= 0.0 { scale = 1.0 }
|
||
area := AppBounds()
|
||
width := area.width - 40.0 * scale
|
||
if width > 680.0 * scale { width = 680.0 * scale }
|
||
if width < 160.0 * scale { return }
|
||
Box(session, BoxProps.{.key = cast(u64)2, .bounds = area,
|
||
.fill = ThemeOr("canvas", 0x142724ff, 0xeef4f2ff)})
|
||
scroll := Scroll(session, ScrollProps.{.key = cast(u64)1, .bounds = area,
|
||
.content_height = cast(s32)account_height, .scroll_offset = management_scroll, .scale = scale})
|
||
management_scroll = scroll.scroll_offset
|
||
if !scroll.opened { return }
|
||
x := scroll.content.x + (scroll.content.width - width) * 0.5
|
||
top := scroll.content.y
|
||
y := top + 16.0 * scale
|
||
if !state.host_navigation {
|
||
if Action(800, Label("entity.back", "Back"), Rectangle.{x, y, 84.0 * scale, 40.0 * scale}) { unused ManagementBack() }
|
||
y += 56.0 * scale
|
||
}
|
||
if management_page != PAGE_FRIENDS || !state.host_navigation {
|
||
TextLine(801, PageTitle(), x, y, width, 24)
|
||
y += 52.0 * scale
|
||
}
|
||
page := management_page
|
||
if page == PAGE_IMPORT || page == PAGE_BACKUP || page == PAGE_SIGN_IN_METHODS { KeyPage(x, *y, width) }
|
||
else if page == PAGE_LOGOUT || page == PAGE_CLEAR || page == PAGE_SWITCH { ConfirmPage(x, *y, width) }
|
||
else if page == PAGE_LINK { LinkPage(x, *y, width) }
|
||
else if page == PAGE_NODES { NodesPage(x, *y, width) }
|
||
else if page == PAGE_NODE { NodePage(x, *y, width) }
|
||
else if page == PAGE_ADD_NODE { AddNodePage(x, *y, width) }
|
||
else if page == PAGE_ALIAS { AliasPage(x, *y, width) }
|
||
else if page == PAGE_FRIENDS { FriendsPage(x, *y, width) }
|
||
else if page == PAGE_APPEARANCE { AppearanceControls(x, *y, width, ENTITY_APPEARANCE | ENTITY_ACCENT | ENTITY_WIDGETS) }
|
||
else { AccountPage(x, *y, width) }
|
||
if management_waiting > management.completed {
|
||
Muted(841, Label("entity.working", "Working…"), x, y, width)
|
||
y += 32.0 * scale
|
||
} else if notice != "" {
|
||
Paragraph(840, notice, x, y, width, 48.0)
|
||
y += 56.0 * scale
|
||
}
|
||
account_height = y - top + 24.0 * scale
|
||
unused End(session)
|
||
AppKeyboard(fields[2].focused || fields[3].focused || fields[4].focused || fields[5].focused)
|
||
PublicIdModal()
|
||
PictureModal()
|
||
AliasPurchaseModal()
|
||
}
|
||
|
||
Picture :: (index: s32, bounds: Rectangle) -> ImageProps {
|
||
image := EntityIconImage(EntityPictureIcon(0, index, 0), bounds, Label("entity.picture", "Profile picture"))
|
||
if asset_root[0] != cast(u8)0 {
|
||
path: Vec(u8)
|
||
BuilderPrint(*path, "%/%", TextUntilNul(asset_root[:]), image.asset_path)
|
||
image.asset_path = BuilderFinish(path)
|
||
}
|
||
return image
|
||
}
|
||
|
||
ExtensionShape :: (route: string) -> string {
|
||
if route == "leaderboard" { return "S1.7rr:M4 21V13H8V21M10 21V4H14V21M16 21V9H20V21" }
|
||
if route == "dew" { return "S1.7rr:M12 3C10 6 5 11 5 15C5 24 19 24 19 15C19 11 14 6 12 3ZM8 15C8 18 10 19 12 19" }
|
||
if route == "achievements" { return "S1.7rr:M8 3H16V10C16 16 8 16 8 10ZM8 5H4V8L8 11M16 5H20V8L16 11M12 15V21M8 21H16" }
|
||
if route == "inbe" { return "S1.7rr:M3 13H7L10 5L14 20L17 11H21" }
|
||
if route == "friends" { return "S1.7rr:M9 3C4 3 4 11 9 11C14 11 14 3 9 3M2 21V18C2 12 16 12 16 18V21M17 4C22 4 22 11 17 11M19 14C22 15 22 18 22 21" }
|
||
if route == "telegram" { return "S1.7rr:M3 11L21 4L17 21L11 15L7 18L8 13L18 7L11 15" }
|
||
if route == "data" { return "S1.7rr:M4 5C4 1 20 1 20 5C20 9 4 9 4 5V18C4 22 20 22 20 18V5M4 11C4 15 20 15 20 11" }
|
||
return "S1.7rr:M5 5H19V19H5ZM9 9L15 15M9 15L15 9"
|
||
}
|
||
|
||
ExtensionRows :: (left: float32, top: *float32, width: float32) {
|
||
for index: 0..state.extension_count - 1 {
|
||
entry := state.extensions[index]
|
||
route := TextUntilNul(entry.id[:])
|
||
if management.available && route == "account" { continue }
|
||
if route == "dew" && AppSupports("entity.dew") { continue }
|
||
if route == "leaderboard" { continue }
|
||
if ListRow(500 + cast(s32)index, TextUntilNul(entry.label[:]), "", left, top, width,
|
||
0, ExtensionShape(route), TextUntilNul(entry.summary[:])) && Save() {
|
||
if route == "dew" && AppSupports("entity.dew") {
|
||
dew_page = true
|
||
dew_refresh = true
|
||
} else if route == "leaderboard" { unused ProfileLeaderboardCommand(route) }
|
||
else if !AchievementOpenRoute(route) && !TelegramViewRoute(route) { AppReply(route) }
|
||
}
|
||
|
||
}
|
||
top.* += 16.0 * scale
|
||
}
|
||
|
||
Draw :: () {
|
||
PollManagement()
|
||
if !loaded {
|
||
state = EntityDefault()
|
||
assets := AppService("entity.assets", "")
|
||
// An absolute folder: /home/… or, on Windows, a drive such as C:/….
|
||
absolute := (assets.count > 0 && assets[0] == cast(u8)47) ||
|
||
(assets.count > 2 && assets[1] == cast(u8)58 && assets[2] == cast(u8)47)
|
||
if absolute { unused CopyCString(assets, asset_root[:]) }
|
||
bytes: [16385]u8
|
||
count := ReadStore("entity.json", bytes[:])
|
||
if count > 0 { unused EntityDecode(TextUntilNul(bytes[:]), *state) }
|
||
loaded = true
|
||
dew_refresh = true
|
||
}
|
||
if TelegramViewFrame(!state.host_navigation) { return }
|
||
if ProfileLeaderboardFrame(!state.host_navigation) { return }
|
||
if AchievementViewFrame(!state.host_navigation) { return }
|
||
if dew_page { DrawDew(); return }
|
||
if management_page != 0 { DrawAccount(); return }
|
||
session = AppSession()
|
||
scale = AppScale()
|
||
if scale <= 0.0 { scale = 1.0 }
|
||
area := AppBounds()
|
||
width := area.width - 40.0 * scale
|
||
if width > 680.0 * scale { width = 680.0 * scale }
|
||
if width < 160.0 * scale { return }
|
||
inline_dew := AppSupports("entity.dew") && (state.profile_sections & PROFILE_DEW) != 0
|
||
if inline_dew { ProfileDewRead() }
|
||
inline_activity := AppSupports("entity.activity")
|
||
if inline_activity { ProfileActivityRead() }
|
||
Box(session, BoxProps.{.key = cast(u64)2, .bounds = area,
|
||
.fill = ThemeOr("canvas", 0x142724ff, 0xeef4f2ff)})
|
||
// The column scrolls over the height the previous frame drew.
|
||
scroll := Scroll(session, ScrollProps.{.key = cast(u64)1,
|
||
.bounds = area, .content_height = cast(s32)profile_height,
|
||
.scroll_offset = scroll_offset, .scale = scale})
|
||
scroll_offset = scroll.scroll_offset
|
||
if !scroll.opened { return }
|
||
x := scroll.content.x + (scroll.content.width - width) * 0.5
|
||
top := scroll.content.y
|
||
y := top + 24.0 * scale
|
||
if !state.host_navigation {
|
||
TextLine(5, Label("entity.title", "Your profile"), x, y, width, 30)
|
||
y += 44.0 * scale
|
||
}
|
||
center_x := x + width * 0.5
|
||
Box(session, BoxProps.{.key = cast(u64)6,
|
||
.bounds = Rectangle.{center_x - 44.0 * scale, y, 88.0 * scale, 88.0 * scale},
|
||
.radius = 44.0 * scale, .fill = ThemeOr("surface", 0x2a4540ff, 0xeaf1eaff)})
|
||
ProfilePicture(9, Rectangle.{center_x - 40.0 * scale, y + 4.0 * scale, 80.0 * scale, 80.0 * scale})
|
||
y += 96.0 * scale
|
||
if ListRow(10, Label("entity.change_picture", "Change picture"), "", x, *y, width) { OpenPicturePicker() }
|
||
if management.available { AccountSummary(x, *y, width) }
|
||
// Dew needs an account; without one the card would only say so.
|
||
if inline_dew && dew_profile_available { y += ProfileDewBalance(x, y, width, true).height }
|
||
if inline_activity { y += ProfileActivity(x, y, width, true) }
|
||
if (state.controls & ENTITY_NODES) != 0 && ListRow(704, Label("entity.nodes", "Nodes"), NodesSummary(), x, *y, width) {
|
||
OpenManagement(PAGE_NODES)
|
||
}
|
||
if AppSupports("entity.friends") && (state.profile_sections & PROFILE_FRIENDS) != 0 &&
|
||
ListRow(551, Label("profile_friends_title", "Friends"), "", x, *y, width) { OpenManagement(PAGE_FRIENDS) }
|
||
if AppSupports(LEADERBOARD_SERVICE) && (state.profile_sections & PROFILE_LEADERBOARD) != 0 &&
|
||
ListRow(550, Label("leaderboard_title", "Leaderboard"), "", x, *y, width) { unused ProfileLeaderboardCommand("leaderboard") }
|
||
ExtensionRows(x, *y, width)
|
||
if management.available { AccountActions(x, *y, width) }
|
||
if notice != "" {
|
||
Text(session, TextProps.{.key = cast(u64)22, .text = notice,
|
||
.bounds = Rectangle.{x, y, width, 40.0 * scale}, .font = cast(s32)(13.0 * scale), .wrap = TextWrap.TextWrapAuto})
|
||
y += 48.0 * scale
|
||
}
|
||
AppearanceControls(x, *y, width, state.controls)
|
||
profile_height = y - top + 24.0 * scale
|
||
unused End(session)
|
||
AppKeyboard(fields[0].focused || fields[1].focused)
|
||
PublicIdModal()
|
||
PictureModal()
|
||
}
|
||
|
||
#program_export
|
||
Main :: () -> s64 {
|
||
mode := AppMode()
|
||
if mode == APP_COMMAND && AppCommand() == "back" && choosing_picture {
|
||
choosing_picture = false
|
||
AppReply("handled")
|
||
return 0
|
||
}
|
||
if mode == APP_COMMAND && AppCommand() == "back" && public_id_open {
|
||
public_id_open = false
|
||
AppReply("handled")
|
||
return 0
|
||
}
|
||
if mode == APP_COMMAND {
|
||
command := AppCommand()
|
||
// Each root page replaces the last one, so a Dew or leaderboard page
|
||
// left open never covers the page asked for next.
|
||
if command == "root:profile" || command == "root:leaderboard" || command == "root:dew" || command == "root:appearance" {
|
||
dew_page = false
|
||
dew_confirmation = -1
|
||
profile_leaderboard_open = false
|
||
}
|
||
if command == "root:profile" { root_page = ""; ManagementHome(0); return 0 }
|
||
if command == "root:leaderboard" { root_page = "leaderboard"; unused ProfileLeaderboardCommand("leaderboard"); return 0 }
|
||
if command == "root:dew" { root_page = "dew"; dew_page = true; dew_refresh = true; return 0 }
|
||
if command == "root:appearance" { root_page = "appearance"; ManagementHome(PAGE_APPEARANCE); return 0 }
|
||
if command == "back" && ((root_page == "leaderboard" && profile_leaderboard_open) ||
|
||
(root_page == "dew" && dew_page && dew_confirmation < 0) ||
|
||
(root_page == "appearance" && management_page == PAGE_APPEARANCE)) {
|
||
root_page = ""
|
||
dew_page = false
|
||
profile_leaderboard_open = false
|
||
ManagementHome(0)
|
||
AppReply("close")
|
||
return 0
|
||
}
|
||
}
|
||
if mode == APP_IDENTIFY {
|
||
AppIdentity("entity")
|
||
AppDescribe("Entity", "S1.6rr:M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM4 22V20C4 15.58 7.58 12 12 12C16.42 12 20 15.58 20 20V22")
|
||
return APP_PROTOCOL
|
||
}
|
||
if mode == APP_COMMAND && AppCommand() == "back" && dew_page {
|
||
dew_page = false
|
||
dew_confirmation = -1
|
||
AppReply("handled")
|
||
return 0
|
||
}
|
||
if mode == APP_COMMAND && TelegramViewCommand(AppCommand()) { return 0 }
|
||
if mode == APP_COMMAND && ProfileLeaderboardCommand(AppCommand()) { return 0 }
|
||
if mode == APP_COMMAND && AchievementCommand(AppCommand()) { return 0 }
|
||
if mode == APP_FRAME { Draw() }
|
||
if mode == APP_COMMAND && AppCommand() == "reload" {
|
||
loaded = false
|
||
public_id_open = false
|
||
choosing_picture = false
|
||
fields = .{}
|
||
}
|
||
if mode == APP_COMMAND && AppCommand() == "account" { ManagementHome(PAGE_ACCOUNT) }
|
||
if mode == APP_COMMAND && AppCommand() == "dew" && AppSupports("entity.dew") {
|
||
dew_page = true
|
||
dew_refresh = true
|
||
dew_confirmation = -1
|
||
management_scroll = 0
|
||
}
|
||
if mode == APP_COMMAND && AppCommand() == "back" && ManagementBack() { AppReply("handled") }
|
||
if mode == APP_SAVE && loaded { return ifx Save() then 0 else 1 }
|
||
return 0
|
||
}
|
||
|
||
// One Dew page for native Entity providers. The host supplies verified node
|
||
// state and queues explicit requests; balances are never computed locally.
|
||
dew_page: bool;
|
||
dew_refresh: bool;
|
||
dew_confirmation: s32 = -1;
|
||
dew_view_tick: s32;
|
||
dew_view_json: [20000]u8;
|
||
dew_profile_account: DewAccount;
|
||
dew_profile_available: bool;
|
||
dew_profile_busy: bool;
|
||
dew_profile_error: bool;
|
||
dew_profile_host_actions: bool;
|
||
dew_profile_manage_data: bool;
|
||
// Whether the host sells Dew here; a host answering "top_up":false does not.
|
||
dew_profile_top_up: bool;
|
||
dew_profile_worth: [256]u8;
|
||
dew_profile_plan: [256]u8;
|
||
dew_profile_usage: [256]u8;
|
||
|
||
ProfileDewRead :: () {
|
||
dew_view_tick += 1
|
||
if dew_view_tick % 15 != 1 && !dew_refresh { return }
|
||
unused CopyCString(AppService("entity.dew", ""), dew_view_json[:])
|
||
json := TextUntilNul(dew_view_json[:])
|
||
owner: [65]u8
|
||
unused ReadStringText(json, FieldAt(json, 0, "owner"), owner[:])
|
||
same_owner := TextUntilNul(owner[:]) == TextUntilNul(management.public_id[:]) && TextUntilNul(owner[:]).count == 64
|
||
dew_profile_available = same_owner && MatchLiteral(json, FieldAt(json, 0, "available"), "true")
|
||
dew_profile_busy = MatchLiteral(json, FieldAt(json, 0, "busy"), "true")
|
||
dew_profile_error = MatchLiteral(json, FieldAt(json, 0, "error"), "true")
|
||
dew_profile_host_actions = MatchLiteral(json, FieldAt(json, 0, "host_actions"), "true")
|
||
dew_profile_manage_data = dew_profile_host_actions && MatchLiteral(json, FieldAt(json, 0, "manage_data"), "true")
|
||
dew_profile_top_up = !MatchLiteral(json, FieldAt(json, 0, "top_up"), "false")
|
||
dew_profile_account = .{}
|
||
dew_profile_worth = .{}
|
||
dew_profile_plan = .{}
|
||
dew_profile_usage = .{}
|
||
at := FieldAt(json, 0, "account")
|
||
end := ValueEnd(json, at, 0)
|
||
if same_owner && at >= 0 && end > at {
|
||
unused DewParseAccount(json[at:end], TextUntilNul(owner[:]), *dew_profile_account)
|
||
unused ReadStringText(json, FieldAt(json, 0, "worth"), dew_profile_worth[:])
|
||
unused ReadStringText(json, FieldAt(json, 0, "plan_summary"), dew_profile_plan[:])
|
||
unused ReadStringText(json, FieldAt(json, 0, "usage_summary"), dew_profile_usage[:])
|
||
}
|
||
if dew_refresh && dew_profile_available && !dew_profile_busy {
|
||
sequence := cast(s32)ReadNumber(json, FieldAt(json, 0, "sequence")).value
|
||
DewCommand("refresh", sequence)
|
||
dew_refresh = false
|
||
}
|
||
}
|
||
|
||
ProfileDewBalance :: (x: float32, y: float32, width: float32, draw: bool) -> DewBalanceResult {
|
||
account := dew_profile_account
|
||
amount: [64]u8
|
||
unused CopyCString("—", amount[:])
|
||
if account.known && dew_profile_available { unused DewFormat(account.balance, DewUnits, amount[:], "Dew") }
|
||
plan := TextUntilNul(dew_profile_plan[:])
|
||
usage := TextUntilNul(dew_profile_usage[:])
|
||
own_plan: [256]u8
|
||
own_usage: [256]u8
|
||
if account.known && plan == "" {
|
||
unused CopyCString(ifx account.plan_size > 0 then Label("profile_dew_paid_plan", "Paid storage") else Label("profile_dew_plan_free", "Free"), own_plan[:])
|
||
plan = TextUntilNul(own_plan[:])
|
||
}
|
||
if account.known && usage == "" && account.limit_bytes > 0 {
|
||
used: [64]u8
|
||
limit: [64]u8
|
||
unused DewFormat(account.used_bytes / 1048576, 1, used[:], "MB")
|
||
unused DewFormat(account.limit_bytes / 1048576, 1, limit[:], "MB")
|
||
at: s64 = 0
|
||
for byte: TextUntilNul(used[:]) { own_usage[at] = byte; at += 1 }
|
||
for byte: " / " { own_usage[at] = byte; at += 1 }
|
||
for byte: TextUntilNul(limit[:]) { own_usage[at] = byte; at += 1 }
|
||
usage = TextUntilNul(own_usage[:])
|
||
}
|
||
notice := ""
|
||
if !dew_profile_available { notice = Label("profile_dew_connect", "Sign in to use Dew.") }
|
||
else if dew_profile_error { notice = Label("profile_dew_error", "Could not refresh Dew. Any balance shown is the last confirmed balance.") }
|
||
else if !account.known { notice = Label("profile_dew_loading", "Checking Dew…") }
|
||
result := DewBalance(session, DewBalanceProps.{.bounds = Rectangle.{x, y, width, 0.0}, .scale = scale,
|
||
.title = Label("profile_dew_title", "Dew balance"), .balance = TextUntilNul(amount[:]),
|
||
.plan = ifx state.show_storage then plan else "", .usage = ifx state.show_storage then usage else "", .notice = notice,
|
||
.top_up = ifx dew_profile_top_up then Label("profile_dew_topup", "Top up") else "",
|
||
.plans = ifx state.show_storage then Label("profile_dew_plans", "Storage plans") else "",
|
||
.data = ifx state.show_storage && dew_profile_manage_data then Label("entity.manage_data", "Manage data") else "",
|
||
.ready = dew_profile_available, .known = account.known, .busy = dew_profile_busy, .enabled = account.enabled,
|
||
.has_usage = state.show_storage && account.limit_bytes > 0,
|
||
.usage_percent = ifx account.limit_bytes > 0 then cast(s32)(account.used_bytes * 100 / account.limit_bytes) else 0,
|
||
.fill = Darken(ThemeOr("canvas", 0x142724ff, 0xeef4f2ff), 7), .track = ThemeOr("border", 0x34514aff, 0xdde7e3ff),
|
||
.accent = ThemeOr("accent", 0x49a68eff, 0x298a71ff),
|
||
.warning = Color.{163, 98, 0, 255}, .danger = Color.{179, 38, 30, 255}}, draw)
|
||
if result.action != 0 {
|
||
if dew_profile_host_actions {
|
||
AppReply(ifx result.action == DewBalanceTopUp then "dew-topup" else ifx result.action == DewBalanceData then "dew-data" else "dew-plans")
|
||
}
|
||
// Hosts that know dew.waozi.xyz open it for this account; others keep
|
||
// the Profile's own Dew page.
|
||
else if result.action == DewBalanceTopUp && AppService("entity.dew", "open-topup") == "opened" {}
|
||
else { dew_page = true; dew_refresh = true; management_scroll = 0 }
|
||
}
|
||
return result
|
||
}
|
||
|
||
// The same darkening Inner Breeze gives its cards, so they stand off the panel.
|
||
Darken :: (color: Color, percent: s32) -> Color {
|
||
keep := cast(s32)(100 - percent)
|
||
return Color.{cast(u8)(cast(s32)color.r * keep / 100), cast(u8)(cast(s32)color.g * keep / 100),
|
||
cast(u8)(cast(s32)color.b * keep / 100), color.a}
|
||
}
|
||
|
||
// Up to three figures a host shows about its own use, such as Inner Breeze's
|
||
// practice days. Hosts without the service show nothing.
|
||
ActivityStat :: struct { label: [64]u8; value: [32]u8; icon: [16]u8 }
|
||
activity_stats: [3]ActivityStat;
|
||
activity_count: s32;
|
||
activity_tick: s32;
|
||
|
||
ProfileActivityRead :: () {
|
||
activity_tick += 1
|
||
if activity_tick % 30 != 1 { return }
|
||
json := AppService("entity.activity", "")
|
||
at := FieldAt(json, 0, "stats")
|
||
count := ArrayCount(json, at)
|
||
activity_count = 0
|
||
for index: 0..count - 1 {
|
||
if activity_count >= activity_stats.count { break }
|
||
row := ElementAt(json, at, cast(s32)index)
|
||
stat: ActivityStat
|
||
if ReadStringText(json, FieldAt(json, row, "label"), stat.label[:]) < 1 ||
|
||
ReadStringText(json, FieldAt(json, row, "value"), stat.value[:]) < 1 { continue }
|
||
unused ReadStringText(json, FieldAt(json, row, "icon"), stat.icon[:])
|
||
activity_stats[activity_count] = stat
|
||
activity_count += 1
|
||
}
|
||
}
|
||
|
||
ActivityShape :: (icon: string) -> string {
|
||
if icon == "today" { return "S1.7rr:M4 6H20V20H4ZM4 10H20M8 3V7M16 3V7" }
|
||
if icon == "days" { return "S1.7rr:M3 13H7L10 5L14 20L17 11H21" }
|
||
if icon == "sessions" { return "S1.7rr:M5 20V12M12 20V5M19 20V9" }
|
||
return ""
|
||
}
|
||
|
||
ProfileActivity :: (x: float32, y: float32, width: float32, draw: bool) -> float32 {
|
||
if activity_count == 0 { return 0.0 }
|
||
height := 112.0 * scale
|
||
if draw {
|
||
gap := 8.0 * scale
|
||
tile := (width - gap * cast(float32)(activity_count - 1)) / cast(float32)activity_count
|
||
for index: 0..activity_count - 1 {
|
||
stat := activity_stats[index]
|
||
left := x + cast(float32)index * (tile + gap)
|
||
center := left + tile * 0.5
|
||
Box(session, BoxProps.{.key = cast(u64)(1200 + index), .bounds = Rectangle.{left, y, tile, height},
|
||
.fill = Darken(ThemeOr("canvas", 0x142724ff, 0xeef4f2ff), 7), .radius = 12.0 * scale})
|
||
shape := ActivityShape(TextUntilNul(stat.icon[:]))
|
||
if shape != "" {
|
||
Box(session, BoxProps.{.key = cast(u64)(1210 + index),
|
||
.bounds = Rectangle.{center - 17.0 * scale, y + 9.0 * scale, 34.0 * scale, 34.0 * scale},
|
||
.fill = ThemeOr("accent", 0x49a68eff, 0x298a71ff), .radius = 17.0 * scale})
|
||
SvgIcon(session, SvgIconProps.{.shape = shape, .color = Color.{255, 255, 255, 255},
|
||
.bounds = Rectangle.{center - 9.0 * scale, y + 17.0 * scale, 18.0 * scale, 18.0 * scale}})
|
||
}
|
||
Text(session, TextProps.{.key = cast(u64)(1220 + index), .text = TextUntilNul(stat.label[:]),
|
||
.bounds = Rectangle.{left + 4.0 * scale, y + 50.0 * scale, tile - 8.0 * scale, 22.0 * scale},
|
||
.font = cast(s32)(13.0 * scale), .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapEllipsis})
|
||
Text(session, TextProps.{.key = cast(u64)(1230 + index), .text = TextUntilNul(stat.value[:]),
|
||
.bounds = Rectangle.{left + 4.0 * scale, y + 74.0 * scale, tile - 8.0 * scale, 30.0 * scale},
|
||
.font = cast(s32)(22.0 * scale), .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapEllipsis})
|
||
}
|
||
}
|
||
return height + 16.0 * scale
|
||
}
|
||
|
||
DewCommand :: (operation: string, sequence: s32, size: string = "", period: string = "") {
|
||
unused DewQueue(operation, sequence, size, period)
|
||
}
|
||
|
||
// Whether the host queued the request.
|
||
DewQueue :: (operation: string, sequence: s32, size: string = "", period: string = "") -> bool {
|
||
request: Vec(u8)
|
||
BuilderPrint(*request, "{\"owner\":\"%\",\"sequence\":%,\"operation\":\"%\",\"size\":\"%\",\"period\":\"%\"}",
|
||
TextUntilNul(management.public_id[:]), sequence + 1, operation, size, period)
|
||
document := BuilderFinish(request)
|
||
return AppService("entity.dew", document) == "queued"
|
||
}
|
||
|
||
DewDecimal :: (units: s64, divisor: s64, suffix: string) -> string {
|
||
text: Vec(u8)
|
||
fraction := units % divisor
|
||
BuilderPrint(*text, "%", units / divisor)
|
||
if fraction != 0 {
|
||
digits: [19]u8
|
||
places: s32 = 0
|
||
factor := divisor
|
||
while factor > 1 { places += 1; factor /= 10 }
|
||
value := fraction
|
||
index := places
|
||
while index > 0 { index -= 1; digits[index] = cast(u8)(48 + value % 10); value /= 10 }
|
||
last := places
|
||
while last > 0 && digits[last - 1] == cast(u8)48 { last -= 1 }
|
||
BuilderPrint(*text, ".%", TextView(digits[:last]))
|
||
}
|
||
BuilderPrint(*text, " %", suffix)
|
||
return BuilderFinish(text)
|
||
}
|
||
|
||
DewFundingCode :: (address: string, uri: string, x: float32, y: *float32, width: float32) {
|
||
side := DrawConnectionCode(uri, x, y.*, width)
|
||
if side > 0.0 { y.* += side + 16.0 * scale }
|
||
|
||
display: [256]u8
|
||
start: s64 = 0
|
||
length: s64 = 0
|
||
font := cast(s32)(14.0 * scale)
|
||
for byte, index: address {
|
||
probe := TextProps.{.text = address[start:index + 1], .font = font}
|
||
if index > start && TextWidth(session, probe) > cast(s32)(width - 16.0 * scale) {
|
||
display[length] = #char "\n"
|
||
length += 1
|
||
start = index
|
||
}
|
||
display[length] = byte
|
||
length += 1
|
||
}
|
||
props := TextProps.{.key = cast(u64)45009, .text = TextUntilNul(display[:]),
|
||
.bounds = Rectangle.{x + 8.0 * scale, y.*, width - 16.0 * scale, 0.0},
|
||
.font = font, .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapAuto}
|
||
props.bounds.height = cast(float32)TextHeight(session, props) + 8.0 * scale
|
||
Text(session, props)
|
||
y.* += props.bounds.height + 12.0 * scale
|
||
if Action(45010, Label("entity.copy_address", "Copy address"), Rectangle.{x, y.*, width, 44.0 * scale}) {
|
||
unused ClipboardCopy(address, 0)
|
||
}
|
||
y.* += 56.0 * scale
|
||
}
|
||
|
||
// The Dew shop: packs side by side like a game's store. The Google Play
|
||
// edition prices them through Play; other editions price them in Monero at
|
||
// the node's rate and add a custom amount.
|
||
DewPackCustom :: -1
|
||
dew_choice: s32 = 2;
|
||
dew_custom: [16]u8;
|
||
// Whether this visit already asked the node for the account's Monero address.
|
||
dew_address_asked: bool;
|
||
dew_height: float32;
|
||
dew_panel_height: float32 = 400.0;
|
||
DEW_DROP :: "S1.7rr:M12 3C10 6 5 11 5 15C5 24 19 24 19 15C19 11 14 6 12 3ZM8 15C8 18 10 19 12 19"
|
||
DEW_CARD_HEIGHT :: 196.0
|
||
|
||
// "Buy %1 Dew with another coin" with %1 filled in.
|
||
DewFill :: (template: string, value: string) -> string {
|
||
out: Vec(u8)
|
||
index: s64 = 0
|
||
while index < template.count {
|
||
if index + 1 < template.count && template[index] == #char "%" && template[index + 1] == #char "1" {
|
||
BuilderPrint(*out, "%", value)
|
||
index += 2
|
||
continue
|
||
}
|
||
BuilderPrint(*out, "%", template[index:index + 1])
|
||
index += 1
|
||
}
|
||
return BuilderFinish(out)
|
||
}
|
||
|
||
DewDrops :: (key: s32, count: s32, x: float32, y: float32, width: float32) {
|
||
drop := 30.0 * scale
|
||
step := drop * 0.62
|
||
pile := step * cast(float32)(count - 1) + drop
|
||
left := x + (width - pile) * 0.5
|
||
accent := ThemeOr("accent", 0x49a68eff, 0x298a71ff)
|
||
for index: 0..count - 1 {
|
||
// Alternate drops sit lower, so bigger packs read as a pile.
|
||
top := y
|
||
if count == 1 { top = y + 3.0 * scale } else if index % 2 == 0 { top = y + 6.0 * scale }
|
||
cx := left + cast(float32)index * step
|
||
Box(session, BoxProps.{.key = cast(u64)(key + index * 2), .bounds = Rectangle.{cx, top, drop, drop},
|
||
.fill = accent, .border = ThemeOr("surface", 0x1c3330ff, 0xffffffff), .radius = drop * 0.5})
|
||
SvgIcon(session, SvgIconProps.{.shape = DEW_DROP, .color = Color.{255, 255, 255, 255},
|
||
.bounds = Rectangle.{cx + drop * 0.22, top + drop * 0.2, drop * 0.56, drop * 0.6}})
|
||
}
|
||
}
|
||
|
||
// One pack card; returns true when its price button is pressed.
|
||
DewPackCard :: (key: s32, title: string, subtitle: string, drops: s32, price: string, badge: string,
|
||
bounds: Rectangle, chosen: bool, enabled: bool) -> bool {
|
||
accent := ThemeOr("accent", 0x49a68eff, 0x298a71ff)
|
||
if chosen {
|
||
Box(session, BoxProps.{.key = cast(u64)key, .bounds = Rectangle.{bounds.x - 2.0 * scale, bounds.y - 2.0 * scale,
|
||
bounds.width + 4.0 * scale, bounds.height + 4.0 * scale}, .fill = accent, .radius = 16.0 * scale})
|
||
}
|
||
Box(session, BoxProps.{.key = cast(u64)(key + 1), .bounds = bounds,
|
||
.fill = ThemeOr("surface", 0x1c3330ff, 0xffffffff),
|
||
.border = ThemeOr("border", 0x34514aff, 0xc9d6d1ff), .radius = 14.0 * scale})
|
||
// A card without drops, the custom amount, keeps its middle for the field.
|
||
title_y := ifx drops > 0 then 58.0 * scale else 18.0 * scale
|
||
if drops > 0 { DewDrops(key + 10, drops, bounds.x, bounds.y + 16.0 * scale, bounds.width) }
|
||
Text(session, TextProps.{.key = cast(u64)(key + 2), .text = title,
|
||
.bounds = Rectangle.{bounds.x + 6.0 * scale, bounds.y + title_y, bounds.width - 12.0 * scale, 36.0 * scale},
|
||
.font = cast(s32)(26.0 * scale), .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapEllipsis})
|
||
Text(session, TextProps.{.key = cast(u64)(key + 3), .text = subtitle,
|
||
.bounds = Rectangle.{bounds.x + 6.0 * scale, bounds.y + 94.0 * scale, bounds.width - 12.0 * scale, 22.0 * scale},
|
||
.font = cast(s32)(13.0 * scale), .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapEllipsis})
|
||
if badge != "" {
|
||
badge_width := cast(float32)TextWidth(session, TextProps.{.text = badge, .font = cast(s32)(12.0 * scale)}) + 16.0 * scale
|
||
if badge_width > bounds.width - 12.0 * scale { badge_width = bounds.width - 12.0 * scale }
|
||
badge_x := bounds.x + bounds.width - badge_width - 6.0 * scale
|
||
Box(session, BoxProps.{.key = cast(u64)(key + 4), .bounds = Rectangle.{badge_x, bounds.y - 9.0 * scale, badge_width, 22.0 * scale},
|
||
.fill = ThemeOr("canvas", 0x142724ff, 0xeef4f2ff), .border = accent, .radius = 11.0 * scale})
|
||
Text(session, TextProps.{.key = cast(u64)(key + 5), .text = badge,
|
||
.bounds = Rectangle.{badge_x, bounds.y - 7.0 * scale, badge_width, 18.0 * scale},
|
||
.font = cast(s32)(12.0 * scale), .align = TextAlign.TextAlignCenter, .wrap = TextWrap.TextWrapEllipsis})
|
||
}
|
||
return Button(session, ButtonProps.{.key = cast(u64)(key + 6), .id = key + 6, .label = price,
|
||
.bounds = Rectangle.{bounds.x + 10.0 * scale, bounds.y + bounds.height - 56.0 * scale, bounds.width - 20.0 * scale, 44.0 * scale},
|
||
.disabled = !enabled, .selected = chosen, .tone = ButtonTone.ButtonToneAccent,
|
||
.emphasis = ifx chosen then ButtonEmphasis.ButtonEmphasisFilled else ButtonEmphasis.ButtonEmphasisSoft}) != 0
|
||
}
|
||
|
||
// The bounds of card index in a grid that is two cards wide on phones and
|
||
// three on wider screens.
|
||
DewCardBounds :: (index: s32, x: float32, y: float32, width: float32) -> Rectangle {
|
||
columns: s32 = ifx width >= 520.0 * scale then 3 else 2
|
||
gap := 12.0 * scale
|
||
card := (width - gap * cast(float32)(columns - 1)) / cast(float32)columns
|
||
return Rectangle.{x + cast(float32)(index % columns) * (card + gap),
|
||
y + cast(float32)(index / columns) * (DEW_CARD_HEIGHT * scale + gap), card, DEW_CARD_HEIGHT * scale}
|
||
}
|
||
|
||
DewGridHeight :: (count: s32, width: float32) -> float32 {
|
||
columns: s32 = ifx width >= 520.0 * scale then 3 else 2
|
||
rows := (count + columns - 1) / columns
|
||
return cast(float32)rows * (DEW_CARD_HEIGHT * scale + 12.0 * scale) + 12.0 * scale
|
||
}
|
||
|
||
DrawDew :: () {
|
||
session = AppSession()
|
||
scale = AppScale()
|
||
if scale <= 0.0 { scale = 1.0 }
|
||
dew_view_tick += 1
|
||
fresh := dew_view_tick % 15 == 1 || dew_refresh
|
||
if fresh { unused CopyCString(AppService("entity.dew", ""), dew_view_json[:]) }
|
||
if dew_refresh { dew_address_asked = false }
|
||
json := TextUntilNul(dew_view_json[:])
|
||
owner: [65]u8
|
||
unused ReadStringText(json, FieldAt(json, 0, "owner"), owner[:])
|
||
sequence := cast(s32)ReadNumber(json, FieldAt(json, 0, "sequence")).value
|
||
available := TextUntilNul(owner[:]) == TextUntilNul(management.public_id[:]) && MatchLiteral(json, FieldAt(json, 0, "available"), "true")
|
||
busy := MatchLiteral(json, FieldAt(json, 0, "busy"), "true")
|
||
if dew_refresh && available && !busy { DewCommand("refresh", sequence); dew_refresh = false }
|
||
area := AppBounds()
|
||
Box(session, BoxProps.{.key = cast(u64)45000, .bounds = area, .fill = ThemeOr("canvas", 0x142724ff, 0xeef4f2ff)})
|
||
content := ifx dew_height > 0.0 then dew_height else 1180.0 * scale
|
||
scroll := Scroll(session, ScrollProps.{.key = cast(u64)45001, .bounds = area, .content_height = cast(s32)content, .scroll_offset = management_scroll})
|
||
management_scroll = scroll.scroll_offset
|
||
if !scroll.opened { return }
|
||
defer { End(session) }
|
||
y := scroll.content.y + 16.0 * scale
|
||
width := scroll.content.width - 32.0 * scale
|
||
if width > 600.0 * scale { width = 600.0 * scale }
|
||
x := scroll.content.x + (scroll.content.width - width) * 0.5
|
||
if !state.host_navigation {
|
||
if Action(45002, Label("entity.back", "Back"), Rectangle.{x, y, 76.0 * scale, 44.0 * scale}) { dew_page = false; dew_confirmation = -1 }
|
||
y += 56.0 * scale
|
||
TextLine(45003, "Dew", x, y, width, 28)
|
||
y += 48.0 * scale
|
||
}
|
||
if !available {
|
||
Paragraph(45004, Label("entity.dew_connect", "Sign in to use Dew"), x, y, width, 70.0)
|
||
dew_height = y - scroll.content.y + 100.0 * scale
|
||
return
|
||
}
|
||
account: DewAccount
|
||
at := FieldAt(json, 0, "account")
|
||
account_end := ValueEnd(json, at, 0)
|
||
known := at >= 0 && account_end > at && DewParseAccount(json[at:account_end], TextUntilNul(owner[:]), *account)
|
||
|
||
// The wallet: the balance in a pill, like a game's coin counter.
|
||
refresh_width := 112.0 * scale
|
||
pill_width := width - refresh_width - 12.0 * scale
|
||
Box(session, BoxProps.{.key = cast(u64)45060, .bounds = Rectangle.{x, y, pill_width, 52.0 * scale},
|
||
.fill = ThemeOr("surface", 0x1c3330ff, 0xffffffff), .border = ThemeOr("border", 0x34514aff, 0xc9d6d1ff), .radius = 26.0 * scale})
|
||
Box(session, BoxProps.{.key = cast(u64)45061, .bounds = Rectangle.{x + 8.0 * scale, y + 8.0 * scale, 36.0 * scale, 36.0 * scale},
|
||
.fill = ThemeOr("accent", 0x49a68eff, 0x298a71ff), .radius = 18.0 * scale})
|
||
SvgIcon(session, SvgIconProps.{.shape = DEW_DROP, .color = Color.{255, 255, 255, 255},
|
||
.bounds = Rectangle.{x + 16.0 * scale, y + 15.0 * scale, 20.0 * scale, 22.0 * scale}})
|
||
balance := ifx known then DewDecimal(account.balance, DewUnits, "Dew") else ifx busy then Label("entity.working", "Working…") else "… Dew"
|
||
TextLine(45006, balance, x + 54.0 * scale, y + 8.0 * scale, pill_width - 62.0 * scale, 22)
|
||
if !busy && Button(session, ButtonProps.{.key = cast(u64)45007, .id = 45007, .label = Label("entity.refresh", "Refresh"),
|
||
.bounds = Rectangle.{x + width - refresh_width, y + 4.0 * scale, refresh_width, 44.0 * scale},
|
||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}) != 0 {
|
||
DewCommand("refresh", sequence)
|
||
dew_address_asked = false
|
||
}
|
||
y += 68.0 * scale
|
||
|
||
funding_allowed := !MatchLiteral(json, FieldAt(json, 0, "funding_allowed"), "false")
|
||
play_at := FieldAt(json, 0, "play")
|
||
play_end := ValueEnd(json, play_at, 0)
|
||
play_edition := play_at >= 0 && play_end > play_at && json[play_at] == #char "{"
|
||
if play_edition || funding_allowed {
|
||
TextLine(45050, Label("entity.dew_buy", "Buy Dew"), x, y, width, 22)
|
||
y += 44.0 * scale
|
||
}
|
||
|
||
// The Google Play edition sells Dew packs through Play, priced in the buyer's currency.
|
||
if play_edition {
|
||
play := json[play_at:play_end]
|
||
products := FieldAt(play, 0, "products")
|
||
best := DewPlayBest(play)
|
||
shown: s32 = 0
|
||
savings_shown := false
|
||
for index: cast(s32)0..4 {
|
||
item := ElementAt(play, products, index)
|
||
if item < 0 { break }
|
||
item_end := ValueEnd(play, item, 0)
|
||
if item_end <= item { break }
|
||
product := play[item:item_end]
|
||
id: [32]u8
|
||
price: [64]u8
|
||
if ReadStringText(product, FieldAt(product, 0, "id"), id[:]) <= 4 || ReadStringText(product, FieldAt(product, 0, "price"), price[:]) <= 0 { continue }
|
||
size := DewPlayPackSize(TextUntilNul(id[:]))
|
||
if size <= 0 { continue }
|
||
badge := ""
|
||
savings := DewPlaySavings(play, TextUntilNul(id[:]))
|
||
if savings > 0 {
|
||
text: Vec(u8)
|
||
if TextUntilNul(id[:]) == best { BuilderPrint(*text, "% · ", Label("entity.dew_best_value", "Best value")) }
|
||
BuilderPrint(*text, "−%", savings)
|
||
BuilderPrint(*text, "%%")
|
||
badge = BuilderFinish(text)
|
||
savings_shown = true
|
||
}
|
||
digits: Vec(u8)
|
||
BuilderPrint(*digits, "%", size)
|
||
title := BuilderFinish(digits)
|
||
bounds := DewCardBounds(shown, x, y + 10.0 * scale, width)
|
||
if DewPackCard(45100 + shown * 30, title, "Dew", DewPackIndex(cast(s64)size) + 1, TextUntilNul(price[:]), badge,
|
||
bounds, false, !busy) {
|
||
DewCommand("play", sequence, TextUntilNul(id[:]))
|
||
}
|
||
shown += 1
|
||
}
|
||
if shown > 0 { y += DewGridHeight(shown, width) + 10.0 * scale }
|
||
if savings_shown {
|
||
Paragraph(45057, Label("profile_dew_play_comparison", "Savings per Dew compared with the 10 Dew pack."), x, y, width, 48.0)
|
||
y += 56.0 * scale
|
||
}
|
||
status: [16]u8
|
||
unused ReadStringText(json, FieldAt(json, 0, "play_status"), status[:])
|
||
play_error: [64]u8
|
||
unused ReadStringText(play, FieldAt(play, 0, "error"), play_error[:])
|
||
message := ""
|
||
if TextUntilNul(status[:]) == "verifying" { message = Label("entity.dew_play_verifying", "Adding the Dew from your Google Play purchase…") }
|
||
else if TextUntilNul(status[:]) == "credited" { message = Label("entity.dew_play_credited", "Your Dew has been added.") }
|
||
else if TextUntilNul(status[:]) == "failed" { message = Label("entity.dew_play_failed", "Google Play took the payment, but the Dew could not be added yet. It tries again automatically.") }
|
||
else if shown == 0 && TextUntilNul(play_error[:]) != "" && TextUntilNul(play_error[:]) != "cancelled" { message = Label("entity.dew_play_unavailable", "Google Play purchases are not available right now.") }
|
||
else if shown == 0 { message = Label("entity.dew_play_loading", "Loading Google Play prices…") }
|
||
if message != "" {
|
||
Paragraph(45056, message, x, y, width, 64.0)
|
||
y += 72.0 * scale
|
||
}
|
||
} else if funding_allowed {
|
||
funding: DewFunding
|
||
at = FieldAt(json, 0, "funding")
|
||
funding_end := ValueEnd(json, at, 0)
|
||
funded := at >= 0 && funding_end > at && DewParseFunding(json[at:funding_end], TextUntilNul(owner[:]), *funding)
|
||
// The rate comes with the account's address, so the shop asks for it once a visit.
|
||
if !funded && !dew_address_asked && fresh && known && !busy && !MatchLiteral(json, FieldAt(json, 0, "error"), "true") {
|
||
dew_address_asked = DewQueue("address", sequence)
|
||
}
|
||
for index: cast(s32)0..DewPackCount - 1 {
|
||
dew := DewPackSizes[index]
|
||
atomic := ifx funded then DewPackAtomic(dew, funding.atomic, funding.units) else cast(s64)-1
|
||
price := ifx atomic > 0 then DewDecimal(atomic, DewPiconero, "XMR") else "… XMR"
|
||
digits: Vec(u8)
|
||
BuilderPrint(*digits, "%", dew)
|
||
if DewPackCard(45100 + index * 30, BuilderFinish(digits), "Dew", index + 1, price, "",
|
||
DewCardBounds(index, x, y + 10.0 * scale, width), dew_choice == index,
|
||
atomic >= funding.minimum && atomic > 0) {
|
||
dew_choice = index
|
||
fields[6].focused = false
|
||
}
|
||
}
|
||
// Any whole amount, typed into the last card.
|
||
custom_bounds := DewCardBounds(DewPackCount, x, y + 10.0 * scale, width)
|
||
custom := DewPackTyped(TextUntilNul(dew_custom[:]))
|
||
custom_atomic := ifx funded && custom > 0 then DewPackAtomic(custom, funding.atomic, funding.units) else cast(s64)-1
|
||
custom_price := ifx custom_atomic > 0 then DewDecimal(custom_atomic, DewPiconero, "XMR") else Label("entity.dew_choose", "Choose")
|
||
if DewPackCard(45100 + DewPackCount * 30, Label("entity.dew_custom", "Custom"), "", 0, custom_price, "",
|
||
custom_bounds, dew_choice == DewPackCustom, custom_atomic >= funding.minimum && custom_atomic > 0) {
|
||
dew_choice = DewPackCustom
|
||
}
|
||
unused EditField(6, dew_custom[:], Label("entity.dew_amount", "Dew amount"),
|
||
Rectangle.{custom_bounds.x + 10.0 * scale, custom_bounds.y + 72.0 * scale, custom_bounds.width - 20.0 * scale, 44.0 * scale}, 7)
|
||
if fields[6].focused { dew_choice = DewPackCustom }
|
||
y += DewGridHeight(DewPackCount + 1, width) + 10.0 * scale
|
||
|
||
// The chosen pack's payment: the account's own Monero address with the amount filled in.
|
||
chosen := ifx dew_choice == DewPackCustom then custom else ifx dew_choice >= 0 && dew_choice < DewPackCount then DewPackSizes[dew_choice] else cast(s64)0
|
||
chosen_atomic := ifx funded && chosen > 0 then DewPackAtomic(chosen, funding.atomic, funding.units) else cast(s64)-1
|
||
if !funded {
|
||
failed := dew_address_asked && !busy && MatchLiteral(json, FieldAt(json, 0, "error"), "true")
|
||
Paragraph(45070, ifx failed then Label("entity.dew_rate_retry", "Could not load the Monero rate. Refresh to try again.")
|
||
else Label("entity.dew_loading_rate", "Loading the Monero rate…"), x, y, width, 48.0)
|
||
y += 56.0 * scale
|
||
} else if chosen_atomic <= 0 || chosen_atomic < funding.minimum {
|
||
minimum := DewDecimal(funding.minimum, DewPiconero, "XMR")
|
||
line: Vec(u8)
|
||
BuilderPrint(*line, "%: %", Label("entity.dew_minimum", "Minimum"), minimum)
|
||
Paragraph(45071, ifx chosen > 0 then BuilderFinish(line) else Label("entity.dew_type_amount", "Type how much Dew you want."), x, y, width, 48.0)
|
||
y += 56.0 * scale
|
||
} else {
|
||
panel_y := y
|
||
Box(session, BoxProps.{.key = cast(u64)45072, .bounds = Rectangle.{x, y, width, dew_panel_height},
|
||
.fill = ThemeOr("surface", 0x1c3330ff, 0xffffffff), .border = ThemeOr("border", 0x34514aff, 0xc9d6d1ff), .radius = 14.0 * scale})
|
||
inner_x := x + 16.0 * scale
|
||
inner := width - 32.0 * scale
|
||
y += 16.0 * scale
|
||
amount := DewDecimal(chosen_atomic, DewPiconero, "XMR")
|
||
heading: Vec(u8)
|
||
BuilderPrint(*heading, "% Dew · %", chosen, amount)
|
||
TextLine(45073, BuilderFinish(heading), inner_x, y, inner, 20)
|
||
y += 36.0 * scale
|
||
Paragraph(45074, Label("entity.dew_send_monero", "Send this amount of Monero to your Dew address. Any Monero that arrives becomes Dew at the node's rate."), inner_x, y, inner, 48.0)
|
||
y += 56.0 * scale
|
||
uri: [256]u8
|
||
address := TextUntilNul(funding.address[:])
|
||
DewFundingCode(address, DewPackMoneroUri(address, chosen_atomic, uri[:]), inner_x, *y, inner)
|
||
explanation: Vec(u8)
|
||
BuilderPrint(*explanation, "%: % · %: %", Label("entity.dew_minimum", "Minimum"), DewDecimal(funding.minimum, DewPiconero, "XMR"),
|
||
Label("entity.dew_confirmations", "Confirmations"), funding.confirmations)
|
||
Paragraph(45014, BuilderFinish(explanation), inner_x, y, inner, 40.0)
|
||
y += 48.0 * scale
|
||
// Other coins go through dew.waozi.xyz, whose swap starts at 100 Dew.
|
||
least := DewOtherCoinMinimum(funding.atomic, funding.units)
|
||
if least > 0 && chosen >= least {
|
||
count: Vec(u8)
|
||
BuilderPrint(*count, "%", chosen)
|
||
label := DewFill(Label("entity.dew_other_coin", "Buy %1 Dew with another coin"), BuilderFinish(count))
|
||
if Button(session, ButtonProps.{.key = cast(u64)45075, .id = 45075, .label = label,
|
||
.bounds = Rectangle.{inner_x, y, inner, 44.0 * scale}, .tone = ButtonTone.ButtonToneAccent,
|
||
.emphasis = ButtonEmphasis.ButtonEmphasisSoft}) != 0 {
|
||
request: Vec(u8)
|
||
BuilderPrint(*request, "open-topup:%", chosen)
|
||
if AppService("entity.dew", BuilderFinish(request)) != "opened" { unused AppService("entity.dew", "open-topup") }
|
||
}
|
||
y += 56.0 * scale
|
||
} else if least > 0 {
|
||
line: Vec(u8)
|
||
BuilderPrint(*line, "%: % Dew", Label("entity.dew_other_coin_minimum", "Other coins from"), least)
|
||
Paragraph(45076, BuilderFinish(line), inner_x, y, inner, 40.0)
|
||
y += 48.0 * scale
|
||
}
|
||
y += 4.0 * scale
|
||
dew_panel_height = y - panel_y
|
||
y += 16.0 * scale
|
||
}
|
||
}
|
||
AppKeyboard(fields[6].focused)
|
||
if state.show_storage && MatchLiteral(json, FieldAt(json, 0, "pending"), "true") {
|
||
Paragraph(45011, Label("entity.dew_pending", "A purchase is awaiting confirmation. Retry checks the same purchase."), x, y, width, 60.0)
|
||
y += 68.0 * scale
|
||
if !busy && Action(45012, Label("entity.retry", "Retry"), Rectangle.{x, y, width, 44.0 * scale}) { DewCommand("retry", sequence) }
|
||
y += 56.0 * scale
|
||
} else if state.show_storage && known && account.enabled && !busy {
|
||
TextLine(45013, Label("entity.storage_plans", "Storage plans"), x, y, width, 20)
|
||
y += 40.0 * scale
|
||
for index: cast(s32)0..3 {
|
||
slot := index / 2
|
||
yearly := index % 2 == 1
|
||
cost := ifx yearly then account.plans[slot].yearly_units else account.plans[slot].monthly_units
|
||
if cost <= 0 || cost > account.balance { continue }
|
||
amount := DewDecimal(cost, DewUnits, "Dew")
|
||
title: Vec(u8)
|
||
BuilderPrint(*title, "% GB · % · %", ifx slot == 0 then 1 else 5,
|
||
ifx yearly then Label("entity.yearly", "Yearly") else Label("entity.monthly", "Monthly"), amount)
|
||
label := BuilderFinish(title)
|
||
if Action(45020 + index, label, Rectangle.{x, y, width, 44.0 * scale}) { dew_confirmation = index }
|
||
y += 56.0 * scale
|
||
if dew_confirmation == index {
|
||
if Action(45030 + index, Label("entity.confirm_purchase", "Confirm purchase"), Rectangle.{x, y, width, 44.0 * scale}, true) {
|
||
DewCommand("buy", sequence, DewPlanSizes[slot], ifx yearly then "yearly" else "monthly")
|
||
dew_confirmation = -1
|
||
}
|
||
y += 56.0 * scale
|
||
}
|
||
}
|
||
}
|
||
if MatchLiteral(json, FieldAt(json, 0, "error"), "true") {
|
||
Paragraph(45040, Label("entity.dew_error", "Could not confirm the node's response. Refresh or retry."), x, y, width, 64.0)
|
||
y += 72.0 * scale
|
||
}
|
||
dew_height = y - scroll.content.y + 32.0 * scale
|
||
}
|
||
|
||
OpenPicturePicker :: () {
|
||
picture_tab = ifx state.picture_kind == 1 then 0 else 1
|
||
choosing_picture = true
|
||
picture_scroll = 0
|
||
fields = .{}
|
||
}
|
||
|
||
AbstractPicture :: (index: s32, bounds: Rectangle) -> ImageProps {
|
||
image := EntityIconImage(EntityPictureIcon(1, 0, index), bounds, Label("entity.abstract", "Abstract"))
|
||
if asset_root[0] != 0 {
|
||
out: Vec(u8)
|
||
BuilderPrint(*out, "%/%", TextUntilNul(asset_root[:]), image.asset_path)
|
||
image.asset_path = BuilderFinish(out)
|
||
}
|
||
return image
|
||
}
|
||
|
||
ProfilePicture :: (id: s32, bounds: Rectangle) {
|
||
if state.picture_kind == 1 { Image(session, AbstractPicture(state.abstract_picture, bounds)) }
|
||
else { Image(session, Picture(state.picture, bounds)) }
|
||
if Button(session, ButtonProps.{.key = cast(u64)id, .id = id, .bounds = bounds,
|
||
.label = Label("entity.change_picture", "Change picture"), .invisible = true}) != 0 {
|
||
OpenPicturePicker()
|
||
}
|
||
}
|
||
|
||
SelectPicture :: (kind: s32, picture: s32) {
|
||
previous := state
|
||
state.picture_kind = kind
|
||
if kind == 0 { state.picture = picture }
|
||
if kind == 1 { state.abstract_picture = picture }
|
||
if Save() { choosing_picture = false }
|
||
else { state = previous }
|
||
}
|
||
|
||
PictureModal :: () {
|
||
if !choosing_picture { return }
|
||
area := AppBounds()
|
||
width := area.width - 24.0 * scale
|
||
if width > 620.0 * scale { width = 620.0 * scale }
|
||
height := area.height - 24.0 * scale
|
||
if height > 650.0 * scale { height = 650.0 * scale }
|
||
modal := ModalFrame(session, ModalFrameProps.{.key = cast(u64)76000, .id = 76000,
|
||
.title = Label("entity.picture", "Profile picture"),
|
||
.bounds = Rectangle.{area.x + (area.width - width) * 0.5, area.y + (area.height - height) * 0.5, width, height},
|
||
.scale = scale, .has_right_action = true, .right_label = Label("entity.done", "Done")})
|
||
if modal.dismissed || modal.right_clicked { choosing_picture = false }
|
||
if !modal.opened { return }
|
||
content := modal.layout.content
|
||
labels: [2]string = .[Label("entity.abstract", "Abstract"), Label("entity.classic", "Classic")]
|
||
half := (content.width - 8.0 * scale) / 2.0
|
||
for index: cast(s32)0..1 {
|
||
if Action(76100 + index, labels[index], Rectangle.{content.x + cast(float32)index * (half + 8.0 * scale),
|
||
content.y, half, 44.0 * scale}, picture_tab == index) { picture_tab = index; picture_scroll = 0 }
|
||
}
|
||
content.y += 56.0 * scale
|
||
content.height -= 56.0 * scale
|
||
{
|
||
columns := cast(s32)((content.width + 12.0 * scale) / (76.0 * scale))
|
||
if columns < 3 { columns = 3 }
|
||
if columns > 7 { columns = 7 }
|
||
count: s32 = ifx picture_tab == 0 then 3 else 28
|
||
scroll := Scroll(session, ScrollProps.{.key = cast(u64)76300, .bounds = content,
|
||
.content_height = ((count + columns - 1) / columns) * cast(s32)(84.0 * scale), .scroll_offset = picture_scroll, .scale = scale})
|
||
picture_scroll = scroll.scroll_offset
|
||
if scroll.opened {
|
||
size := 64.0 * scale
|
||
gap := (content.width - cast(float32)columns * size) / cast(float32)(columns - 1)
|
||
position: s32 = 0
|
||
for index: cast(s32)0..count - 1 {
|
||
if picture_tab == 1 && (state.pictures & (1 << index)) == 0 { continue }
|
||
image := ifx picture_tab == 0 then AbstractPicture(index, Rectangle.{}) else Picture(index, Rectangle.{})
|
||
if Button(session, ButtonProps.{.key = cast(u64)(76400 + index), .id = 76400 + index,
|
||
.label = labels[picture_tab], .icon_only = true, .image = image,
|
||
.selected = ifx picture_tab == 0 then state.picture_kind == 1 && state.abstract_picture == index else state.picture_kind == 0 && state.picture == index,
|
||
.bounds = Rectangle.{content.x + cast(float32)(position % columns) * (size + gap),
|
||
scroll.content.y + cast(float32)(position / columns) * 84.0 * scale, size, size}}) != 0 {
|
||
SelectPicture(ifx picture_tab == 0 then 1 else 0, index)
|
||
}
|
||
position += 1
|
||
}
|
||
unused End(session)
|
||
}
|
||
}
|
||
unused End(session)
|
||
AppKeyboard(false)
|
||
}
|
||
|
||
ExtensionButton :: (id: s32, route: string, label: string, left: float32, top: *float32, width: float32) {
|
||
if ListRow(id, label, "", left, top, width, 0, ExtensionShape(route)) && Save() {
|
||
if route == "friends" { OpenManagement(PAGE_FRIENDS) }
|
||
else { unused ProfileLeaderboardCommand(route) }
|
||
}
|
||
}
|
||
|
||
AppearanceControls :: (x: float32, top: *float32, width: float32, controls: s32) {
|
||
y := top.*
|
||
if (controls & ENTITY_APPEARANCE) != 0 {
|
||
TextLine(30, Label("entity.appearance", "Appearance"), x, y, width, 20)
|
||
y += 36.0 * scale
|
||
modes: [3]string = .[Label("entity.system", "System"), Label("entity.light", "Light"), Label("entity.dark", "Dark")]
|
||
third := (width - 16.0 * scale) / 3.0
|
||
for index: 0..2 {
|
||
if Action(50 + cast(s32)index, modes[index], Rectangle.{x + cast(float32)index * (third + 8.0 * scale), y, third, 40.0 * scale}, state.theme == index) {
|
||
state.theme = cast(s32)index
|
||
Save()
|
||
}
|
||
}
|
||
y += 64.0 * scale
|
||
}
|
||
if (controls & ENTITY_ACCENT) != 0 {
|
||
TextLine(31, Label("entity.accent", "Accent"), x, y, width, 20)
|
||
y += 36.0 * scale
|
||
colors: [16]u32 = .[0x7355d9ff, 0x2563ebff, 0x059669ff, 0xdb2777ff, 0xd97706ff, 0x0891b2ff, 0xdc2626ff, 0x7c3aedff,
|
||
0x4f46e5ff, 0x0d9488ff, 0x65a30dff, 0xc026d3ff, 0xea580cff, 0x0284c7ff, 0x9333eaff, 0x475569ff]
|
||
size := (width - 7.0 * 8.0 * scale) / 8.0
|
||
for index: 0..15 {
|
||
if Button(session, ButtonProps.{.key = cast(u64)(300 + index), .id = 300 + cast(s32)index,
|
||
.bounds = Rectangle.{x + cast(float32)(index % 8) * (size + 8.0 * scale), y + cast(float32)(index / 8) * (size + 8.0 * scale), size, size},
|
||
.label = Label("entity.accent", "Accent"), .icon_only = true, .swatch = true, .swatch_color = ColorFromPacked(colors[index]), .selected = state.accent == index}) != 0 {
|
||
state.accent = cast(s32)index
|
||
Save()
|
||
}
|
||
}
|
||
y += 2.0 * (size + 8.0 * scale) + 16.0 * scale
|
||
}
|
||
top.* = y
|
||
}
|