ozdenui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Component: BottomBar - v26.11
|
|
6
|
+
Description: Mobile application bottom bar component that creates buttons from a JSON list.
|
|
7
|
+
Started Date: December 2025
|
|
8
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
9
|
+
|
|
10
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
11
|
+
Licensed under the Apache License, Version 2.0
|
|
12
|
+
SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
|
|
14
|
+
- Design idea from an Instagram post by shahinurstk02
|
|
15
|
+
|
|
16
|
+
NEEDS: comp/badge.js (Badge), loaded before the first item is created.
|
|
17
|
+
ITEMS: { iconFile, selectedIconFile, text, color }. selectedIconFile is the icon of the selected item ("": its iconFile).
|
|
18
|
+
|
|
19
|
+
THE NAME OF THE SELECTED ITEM (labelMode):
|
|
20
|
+
- "inline" (the default): next to its icon, in the selected box.
|
|
21
|
+
- "float": the selected box is only around the icon; the name shows over it in a small pill (style.floatLabel) and
|
|
22
|
+
fades out after floatLabelTime ms. The pill follows the selected box. (Sample: 02-comp-examples/bottom-bar-2.htm)
|
|
23
|
+
- "none": no names.
|
|
24
|
+
ITEM COLORS: items[i].color is the color of the selected box behind that item (else style.selectedBox.color).
|
|
25
|
+
BADGES: the badge param goes to the Badge of every item (its style is the badgeStyle of Badge). An item shows its
|
|
26
|
+
badge after bar.setBadge(index, value); bar.setBadge(index, "") removes it.
|
|
27
|
+
THE SPACE AFTER THE NAME: layout.labelEndSpace (and the empty side of an icon box bigger than its icon) goes after
|
|
28
|
+
the name, so the selected box looks even at both ends.
|
|
29
|
+
KEYBOARD AND SCREEN READERS: every item is a button named by its text ("Tab 1"... without a text); the Tab key
|
|
30
|
+
reaches it, Enter / Space choose it like a click.
|
|
31
|
+
|
|
32
|
+
USAGE:
|
|
33
|
+
const bar = BottomBar({
|
|
34
|
+
top: page.height - 100,
|
|
35
|
+
items: [{ iconFile: "home.png", selectedIconFile: "homes.png", text: "Home" }, { iconFile: "search.png", text: "Search" }],
|
|
36
|
+
onItemClick: function (self, item, index) { println(item.data.text); },
|
|
37
|
+
});
|
|
38
|
+
bar.setBadge(1, 5);
|
|
39
|
+
bar.selectByIndex(0);
|
|
40
|
+
bar.setLabelMode("float");
|
|
41
|
+
|
|
42
|
+
// A tab bar: a white bar, a circle in the color of the item behind the selected
|
|
43
|
+
// icon, its name over it for a moment, a number badge with a white ring (also "0" and "1").
|
|
44
|
+
BottomBar({
|
|
45
|
+
bottom: 0,
|
|
46
|
+
height: 80,
|
|
47
|
+
labelMode: "float",
|
|
48
|
+
items: [{ iconFile: "home.png", text: "Home", color: "#5ABB9F" }, { iconFile: "tasks.png", text: "Tasks" }],
|
|
49
|
+
badge: {
|
|
50
|
+
showZero: 1,
|
|
51
|
+
dotForOne: 0,
|
|
52
|
+
style: { color: "indianred", border: 3, borderColor: "white", textColor: "white" },
|
|
53
|
+
numberStyle: { fontSize: 14, bold: 1, padding: [8, 3], round: 20, top: -10, right: -14 },
|
|
54
|
+
},
|
|
55
|
+
style: {
|
|
56
|
+
container: { gradient: "white" }, // NOTE: gradient is the CSS background of the box: it is written over color.
|
|
57
|
+
background: { gradient: "none", round: 0 },
|
|
58
|
+
layout: { barHeight: 80, padding: 20, itemSpacing: 40, iconGap: 0, selectionPadding: 8 },
|
|
59
|
+
selectedBox: { color: "#141414", border: 0 },
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
"use strict";
|
|
66
|
+
|
|
67
|
+
// Default values:
|
|
68
|
+
const BottomBarDefaults = {
|
|
69
|
+
selectedIndex: 0,
|
|
70
|
+
left: 0,
|
|
71
|
+
width: "100%",
|
|
72
|
+
height: 100,
|
|
73
|
+
items: [], // [{ iconFile: "home.png", selectedIconFile: "homes.png", text: "Home", color: "#5ABB9F" }] (selectedIconFile, color: optional)
|
|
74
|
+
onItemClick: function (self, item, index) { },
|
|
75
|
+
hoverEffect: true, // For desktop usage
|
|
76
|
+
labelMode: "inline", // "inline": the name next to the selected icon, "float": over it for a moment, "none": no names
|
|
77
|
+
allowHtml: 0, // 1: the names of the items are HTML (only for your own texts)
|
|
78
|
+
floatLabelTime: 600, // ms: from the moment the name shows over the selected item to its fade out ("float")
|
|
79
|
+
badge: { // The params of the Badge of every item (comp/badge.js)
|
|
80
|
+
showZero: 0, // 1: a badge set to 0 shows "0" (0: hidden)
|
|
81
|
+
dotForOne: 1, // 1: a dot for 1, 0: the number 1
|
|
82
|
+
maxValue: 99, // More: "99+"
|
|
83
|
+
dotSize: 12,
|
|
84
|
+
style: { color: "#FE5D49" }, // The dot and the number: color, border, borderColor, textColor (badgeStyle of Badge)
|
|
85
|
+
numberStyle: {}, // Only the number, over style: fontSize, bold, padding, round, top, right...
|
|
86
|
+
},
|
|
87
|
+
style: {
|
|
88
|
+
container: {
|
|
89
|
+
color: "transparent",
|
|
90
|
+
gradient: "linear-gradient(to bottom, transparent, whitesmoke)",
|
|
91
|
+
border: 0,
|
|
92
|
+
},
|
|
93
|
+
background: {
|
|
94
|
+
gradient: "linear-gradient(to right, #FFC8C1, #A5E5EB)",
|
|
95
|
+
border: 0,
|
|
96
|
+
round: 100,
|
|
97
|
+
},
|
|
98
|
+
// Layout configuration
|
|
99
|
+
layout: {
|
|
100
|
+
barHeight: 76, // The height of the bar (the background)
|
|
101
|
+
iconBoxSize: 40, // The box of an icon: the button of the item, with its badge
|
|
102
|
+
padding: 40,
|
|
103
|
+
itemSpacing: 20,
|
|
104
|
+
iconGap: 6,
|
|
105
|
+
selectionPadding: 14,
|
|
106
|
+
// px more after the name of the selected item: an icon file has an empty edge at its left, a name has none
|
|
107
|
+
// at its right, so the same padding looked smaller after the name. 0: no more space
|
|
108
|
+
labelEndSpace: 6,
|
|
109
|
+
},
|
|
110
|
+
icon: {
|
|
111
|
+
width: 40,
|
|
112
|
+
height: 40,
|
|
113
|
+
},
|
|
114
|
+
label: {
|
|
115
|
+
textColor: "#FE5D49",
|
|
116
|
+
},
|
|
117
|
+
selectedBox: {
|
|
118
|
+
color: "#EAEAE9", // An item with its own color (items[i].color) gives its color instead.
|
|
119
|
+
round: 100,
|
|
120
|
+
border: 1,
|
|
121
|
+
borderColor: "#FFFFFF",
|
|
122
|
+
height: 56,
|
|
123
|
+
},
|
|
124
|
+
floatLabel: { // labelMode: "float": the pill of the name over the selected item (any prop of a Label)
|
|
125
|
+
fontSize: 14,
|
|
126
|
+
textColor: Black(0.8),
|
|
127
|
+
color: White(0.8),
|
|
128
|
+
border: 1,
|
|
129
|
+
borderColor: Black(0.6),
|
|
130
|
+
round: 6,
|
|
131
|
+
padding: [8, 3],
|
|
132
|
+
space: 20, // px between the selected box and the pill
|
|
133
|
+
},
|
|
134
|
+
focus: {
|
|
135
|
+
ringColor: "rgba(95, 158, 160, 0.8)", // The ring of an item that has the keyboard focus
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const BottomBar = function (params = {}) {
|
|
141
|
+
|
|
142
|
+
// Merge params:
|
|
143
|
+
mergeIntoIfMissing(params, BottomBarDefaults);
|
|
144
|
+
|
|
145
|
+
// BOX: Component container
|
|
146
|
+
const box = startObject(params);
|
|
147
|
+
box.color = box.style.container.color;
|
|
148
|
+
box.border = box.style.container.border;
|
|
149
|
+
box.css.background = box.style.container.gradient;
|
|
150
|
+
|
|
151
|
+
// *** PRIVATE VARIABLES:
|
|
152
|
+
const BAR_WIDTH = 350; // The first width of the bar; refresh() gives it the width of its items.
|
|
153
|
+
const SELECTED_BOX_WIDTH = 142; // The first width; refresh() sets it around the selected item.
|
|
154
|
+
const LABEL_FIRST_LEFT = 12;
|
|
155
|
+
const LABEL_RAISE = 2; // px above the center line: it looks centered next to the icon.
|
|
156
|
+
const HOVER_ICON_OPACITY = 0.5;
|
|
157
|
+
const REFRESH_DELAY = 3; // ms: many changes in a row make one refresh.
|
|
158
|
+
const stillClipContent = box.clipContent; // WHY: "float" lets the pill stand over the bar; another mode puts it back.
|
|
159
|
+
let isFloatLabelWaiting = 1; // 1: the next refresh() shows the name over the selected item (the first view, a selection)
|
|
160
|
+
let isFloatLabelPlaced = 0;
|
|
161
|
+
let cancelFloatLabelHide = null; // The cancel function of the timer that fades the name out (box.after)
|
|
162
|
+
|
|
163
|
+
// *** PUBLIC VARIABLES:
|
|
164
|
+
box.itemObjList = [];
|
|
165
|
+
// NOTE: An item object: { icon (box: icon.i1 normal, icon.i2 selected), label, badge, index, data }
|
|
166
|
+
// NOTE: box.lblFloat is the pill of the name over the selected item (only with labelMode: "float").
|
|
167
|
+
|
|
168
|
+
// *** PRIVATE FUNCTIONS:
|
|
169
|
+
|
|
170
|
+
const setText = function (label, text) {
|
|
171
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
172
|
+
if (box.allowHtml == 1) label.text = value;
|
|
173
|
+
else label.plainText = value;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const isFloatMode = function () {
|
|
177
|
+
return box.labelMode === "float";
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// WHY: "inline" is the default: an unknown mode is "inline".
|
|
181
|
+
const isInlineMode = function () {
|
|
182
|
+
return box.labelMode !== "float" && box.labelMode !== "none";
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// The icon of the selected item: a file of its own, or its icon again.
|
|
186
|
+
const getSelectedIconFile = function (itemData) {
|
|
187
|
+
return itemData.selectedIconFile || itemData.iconFile;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// The name of an item for a screen reader
|
|
191
|
+
const getItemName = function (itemData, index) {
|
|
192
|
+
return itemData.text || ("Tab " + (index + 1));
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// The space after the name, to look like the space before the icon.
|
|
196
|
+
// WHY the icon box: an icon box bigger than its icon has an empty side before the icon, and it counts there too.
|
|
197
|
+
const getLabelEndSpace = function (item) {
|
|
198
|
+
const iconEmptySide = (item.icon.width - box.style.icon.width) / 2;
|
|
199
|
+
return iconEmptySide + box.style.layout.labelEndSpace;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// The width of an item in the bar: the selected one shows its name next to its icon ("inline").
|
|
203
|
+
const getItemWidth = function (item, isSelected) {
|
|
204
|
+
if (!isSelected || !isInlineMode()) return item.icon.width;
|
|
205
|
+
return item.icon.width + box.style.layout.iconGap + item.label.width + getLabelEndSpace(item);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// The label of the selected item is next to its icon ("inline"); the others wait under their icon.
|
|
209
|
+
const getLabelLeft = function (item, isSelected) {
|
|
210
|
+
if (!isSelected || !isInlineMode()) return item.icon.left;
|
|
211
|
+
return item.icon.left + item.icon.width + box.style.layout.iconGap;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// The space at the ends of the bar: layout.padding, or less when the items would not fit on a narrow phone.
|
|
215
|
+
// WHY selectionPadding: the selected box must stay in the bar.
|
|
216
|
+
const getBarPadding = function () {
|
|
217
|
+
const _layout = box.style.layout;
|
|
218
|
+
const itemsWidth = box.itemObjList.reduce(function (sum, item, index) {
|
|
219
|
+
return sum + getItemWidth(item, index == box.selectedIndex);
|
|
220
|
+
}, 0);
|
|
221
|
+
const spacingWidth = _layout.itemSpacing * (box.itemObjList.length - 1);
|
|
222
|
+
const spareWidth = box.width - itemsWidth - spacingWidth - (_layout.padding * 2);
|
|
223
|
+
if (!box.width || spareWidth >= 0) return _layout.padding;
|
|
224
|
+
return Math.max(_layout.selectionPadding, _layout.padding + (spareWidth / 2));
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// PAINT: the selected item shows its selected icon (and its label: "inline").
|
|
228
|
+
const paintItem = function (item, isSelected) {
|
|
229
|
+
item.label.opacity = (isSelected && isInlineMode()) ? 1 : 0;
|
|
230
|
+
item.icon.i1.opacity = isSelected ? 0 : 1;
|
|
231
|
+
item.icon.i2.opacity = isSelected ? 1 : 0;
|
|
232
|
+
item.icon.clickable = isSelected ? 0 : 1;
|
|
233
|
+
item.icon.aria = { pressed: isSelected };
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// The color of the selected box: the color of the selected item, or the color of the style.
|
|
237
|
+
// WHY: Only when an item has a color: a page that paints the box itself (selectedBox.color = ...) keeps its color.
|
|
238
|
+
const paintSelectedBoxColor = function (item) {
|
|
239
|
+
const hasItemColors = box.itemObjList.some((each) => each.data.color);
|
|
240
|
+
if (!hasItemColors) return;
|
|
241
|
+
box.selectedBox.color = item.data.color || box.style.selectedBox.color;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// The selected box is around the icon (and the label: "inline") of the selected item.
|
|
245
|
+
const placeSelectedBox = function (item) {
|
|
246
|
+
const _layout = box.style.layout;
|
|
247
|
+
box.selectedBox.opacity = 1;
|
|
248
|
+
box.selectedBox.left = item.icon.left - _layout.selectionPadding;
|
|
249
|
+
box.selectedBox.width = getItemWidth(item, true) + (_layout.selectionPadding * 2);
|
|
250
|
+
paintSelectedBoxColor(item);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// THE NAME OVER THE SELECTED ITEM (labelMode: "float"):
|
|
254
|
+
|
|
255
|
+
// The props of the pill: the floatLabel style without space.
|
|
256
|
+
// WHY: space is a setter of a Label (its padding); here it is the gap over the selected box.
|
|
257
|
+
const getFloatLabelLook = function () {
|
|
258
|
+
const look = { ...box.style.floatLabel };
|
|
259
|
+
delete look.space;
|
|
260
|
+
return look;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// LABEL: The pill. Its container must be set (createIn).
|
|
264
|
+
const createFloatLabel = function () {
|
|
265
|
+
const label = Label({ ...getFloatLabelLook(), opacity: 0 });
|
|
266
|
+
label.css = { whiteSpace: "nowrap" }; // WHY: A long name stays on one line near the edge of the bar.
|
|
267
|
+
label.aria = { hidden: true }; // WHY: The name is already the name of the item for a screen reader.
|
|
268
|
+
label.setMotion("left 0.3s, opacity 0.3s");
|
|
269
|
+
label.onResize(placeFloatLabel); // WHY: The size of its text is known after it is drawn.
|
|
270
|
+
return label;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Over the middle of the selected box. (In the box of the component: the bar does not cut it.)
|
|
274
|
+
const placeFloatLabel = function () {
|
|
275
|
+
if (!box.lblFloat) return;
|
|
276
|
+
const innerBorder = box.innerBox.border || 0;
|
|
277
|
+
const selectedBoxCenter = box.innerBox.left + innerBorder + box.selectedBox.left + (box.selectedBox.width / 2);
|
|
278
|
+
const selectedBoxTop = box.innerBox.top + innerBorder + box.selectedBox.top;
|
|
279
|
+
if (!isFloatLabelPlaced) box.lblFloat.dontMotion(); // WHY: The first place: it does not fly in from far.
|
|
280
|
+
isFloatLabelPlaced = 1;
|
|
281
|
+
box.lblFloat.left = Math.round(selectedBoxCenter - (box.lblFloat.width / 2));
|
|
282
|
+
box.lblFloat.top = Math.round(selectedBoxTop - box.style.floatLabel.space - box.lblFloat.height);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const hideFloatLabel = function () {
|
|
286
|
+
if (cancelFloatLabelHide) cancelFloatLabelHide();
|
|
287
|
+
cancelFloatLabelHide = null;
|
|
288
|
+
box.lblFloat.opacity = 0;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// The name fades in over the selected item; floatLabelTime ms later it fades out.
|
|
292
|
+
const showFloatLabel = function (item) {
|
|
293
|
+
hideFloatLabel(); // WHY: Its timer starts again.
|
|
294
|
+
if (!item.data.text) return; // No name: no pill
|
|
295
|
+
setText(box.lblFloat, item.data.text);
|
|
296
|
+
placeFloatLabel();
|
|
297
|
+
box.lblFloat.opacity = 1;
|
|
298
|
+
cancelFloatLabelHide = box.after(box.floatLabelTime, hideFloatLabel);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// After refresh(): the name shows after a selection (and at the first view), else the pill only follows.
|
|
302
|
+
const refreshFloatLabel = function () {
|
|
303
|
+
if (!box.lblFloat) return;
|
|
304
|
+
const selectedItem = box.itemObjList[box.selectedIndex];
|
|
305
|
+
if (!isFloatMode() || !selectedItem) {
|
|
306
|
+
hideFloatLabel();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (isFloatLabelWaiting) {
|
|
310
|
+
isFloatLabelWaiting = 0;
|
|
311
|
+
showFloatLabel(selectedItem);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
placeFloatLabel();
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// "float": the pill is made the first time (a bar of another mode has no extra object),
|
|
318
|
+
// and the box of the component lets it stand over the bar.
|
|
319
|
+
const applyLabelMode = function () {
|
|
320
|
+
if (isFloatMode()) {
|
|
321
|
+
box.clipContent = 0;
|
|
322
|
+
if (!box.lblFloat) box.lblFloat = createIn(box, createFloatLabel);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (box.lblFloat) box.clipContent = stillClipContent; // "float" was on before
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// The user chose an item: a click, Enter or Space.
|
|
329
|
+
const selectByUser = function (itemView, index) {
|
|
330
|
+
box.selectedIndex = index;
|
|
331
|
+
isFloatLabelWaiting = 1;
|
|
332
|
+
box.onItemClick(box, itemView, index);
|
|
333
|
+
box.refresh();
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const createButtons = function (items) {
|
|
337
|
+
items.forEach((itemData, index) => {
|
|
338
|
+
createButton(itemData, index);
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// BADGE: The badge param of the bar. Its style is the badgeStyle of Badge.
|
|
343
|
+
// NOTE: The objects are copied: Badge fills its defaults into them, the param of the bar does not change.
|
|
344
|
+
const createItemBadge = function () {
|
|
345
|
+
const { style, numberStyle, ...badgeParams } = box.badge;
|
|
346
|
+
return Badge({
|
|
347
|
+
...badgeParams,
|
|
348
|
+
value: "", // WHY: No value: hidden until setBadge(), also with showZero: 1.
|
|
349
|
+
badgeStyle: { ...style },
|
|
350
|
+
numberStyle: { ...numberStyle },
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// KEYBOARD AND SCREEN READERS: the icon box is the button of the item.
|
|
355
|
+
const makeItemAccessible = function (itemView, itemData, index) {
|
|
356
|
+
const iconBox = itemView.icon;
|
|
357
|
+
iconBox.role = "button";
|
|
358
|
+
iconBox.aria = { label: getItemName(itemData, index) };
|
|
359
|
+
iconBox.tabIndex = 0;
|
|
360
|
+
iconBox.setFocusRing(box.style.focus.ringColor);
|
|
361
|
+
iconBox.on("keydown", function (self, event) {
|
|
362
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
363
|
+
event.preventDefault(); // WHY: Space must not scroll the page.
|
|
364
|
+
if (box.selectedIndex == index) return; // WHY: Like the mouse: the selected item can not be clicked.
|
|
365
|
+
selectByUser(itemView, index);
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// ICON BOX: the normal and the selected icon on each other, and the badge.
|
|
370
|
+
const createItemIcon = function (itemView, itemData, index) {
|
|
371
|
+
|
|
372
|
+
const _iconBoxSize = box.style.layout.iconBoxSize;
|
|
373
|
+
|
|
374
|
+
itemView.icon = startBox({
|
|
375
|
+
width: _iconBoxSize,
|
|
376
|
+
height: _iconBoxSize,
|
|
377
|
+
color: "transparent",
|
|
378
|
+
position: "absolute", // WHY: refresh() places the items itself (left), not a flex layout.
|
|
379
|
+
clipContent: 0, // WHY: A badge can stand out of the corner of the icon (badge.numberStyle top / right).
|
|
380
|
+
});
|
|
381
|
+
box.innerBox.add(itemView.icon);
|
|
382
|
+
itemView.icon.center("top");
|
|
383
|
+
itemView.icon.setMotion("left 0.3s, opacity 0.3s");
|
|
384
|
+
itemView.icon.cursor = "pointer";
|
|
385
|
+
itemView.icon.on("click", function () {
|
|
386
|
+
selectByUser(itemView, index);
|
|
387
|
+
});
|
|
388
|
+
makeItemAccessible(itemView, itemData, index);
|
|
389
|
+
|
|
390
|
+
// ICON: normal (black)
|
|
391
|
+
itemView.icon.i1 = Icon(0, 0, {
|
|
392
|
+
width: box.style.icon.width,
|
|
393
|
+
height: box.style.icon.height,
|
|
394
|
+
position: "absolute",
|
|
395
|
+
});
|
|
396
|
+
itemView.icon.i1.center(); // WHY: An icon box bigger than the icon (layout.iconBoxSize).
|
|
397
|
+
itemView.icon.i1.load(itemData.iconFile);
|
|
398
|
+
itemView.icon.i1.setMotion("opacity 0.3s");
|
|
399
|
+
|
|
400
|
+
// ICON: selected (orange)
|
|
401
|
+
itemView.icon.i2 = Icon(0, 0, {
|
|
402
|
+
width: box.style.icon.width,
|
|
403
|
+
height: box.style.icon.height,
|
|
404
|
+
position: "absolute",
|
|
405
|
+
opacity: 0,
|
|
406
|
+
});
|
|
407
|
+
itemView.icon.i2.center();
|
|
408
|
+
itemView.icon.i2.load(getSelectedIconFile(itemData));
|
|
409
|
+
itemView.icon.i2.setMotion("opacity 0.3s");
|
|
410
|
+
|
|
411
|
+
// Hover effect for icons (for desktop usage)
|
|
412
|
+
if (box.hoverEffect) {
|
|
413
|
+
itemView.icon.on("mouseover", function () {
|
|
414
|
+
itemView.icon.i2.opacity = HOVER_ICON_OPACITY;
|
|
415
|
+
});
|
|
416
|
+
itemView.icon.on("mouseout", function () {
|
|
417
|
+
if (box.selectedIndex != index) itemView.icon.i2.opacity = 0;
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Badge with number
|
|
422
|
+
itemView.badge = createItemBadge();
|
|
423
|
+
|
|
424
|
+
endBox();
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// LABEL: shown only when the item is selected ("inline").
|
|
428
|
+
const createItemLabel = function (itemView, itemData) {
|
|
429
|
+
itemView.label = Label({
|
|
430
|
+
left: LABEL_FIRST_LEFT,
|
|
431
|
+
width: "auto",
|
|
432
|
+
height: "auto",
|
|
433
|
+
color: "transparent",
|
|
434
|
+
textColor: box.style.label.textColor,
|
|
435
|
+
position: "absolute", // WHY: refresh() places the items itself (left), not a flex layout.
|
|
436
|
+
opacity: 0,
|
|
437
|
+
});
|
|
438
|
+
setText(itemView.label, itemData.text);
|
|
439
|
+
itemView.label.css = { whiteSpace: "nowrap" }; // WHY: A name of two words broke while the bar was growing.
|
|
440
|
+
box.innerBox.add(itemView.label);
|
|
441
|
+
itemView.label.center("top");
|
|
442
|
+
itemView.label.top -= LABEL_RAISE;
|
|
443
|
+
itemView.label.setMotion("left 0.3s, opacity 0.3s");
|
|
444
|
+
itemView.label.aria = { hidden: true }; // WHY: The text is the name of the button of the item (its icon box).
|
|
445
|
+
itemView.label.onResize(box.refreshOneTime); // WHY: The width of the label is known only after it is drawn.
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const createButton = function (itemData, index) {
|
|
449
|
+
const itemView = {};
|
|
450
|
+
createItemIcon(itemView, itemData, index);
|
|
451
|
+
createItemLabel(itemView, itemData);
|
|
452
|
+
itemView.index = index;
|
|
453
|
+
itemView.data = itemData;
|
|
454
|
+
|
|
455
|
+
box.itemObjList.push(itemView);
|
|
456
|
+
box.refreshOneTime();
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// *** PUBLIC FUNCTIONS:
|
|
460
|
+
|
|
461
|
+
// Many calls in a row make one refresh().
|
|
462
|
+
// NOTE: box.after() is a timer of the box: it can not run after remove().
|
|
463
|
+
box.refreshOneTime = function () {
|
|
464
|
+
if (box.refreshTimeout) box.refreshTimeout();
|
|
465
|
+
box.refreshTimeout = box.after(REFRESH_DELAY, function () { box.refresh(); });
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// value: a number; "" removes the badge.
|
|
469
|
+
box.setBadge = function (index, value) {
|
|
470
|
+
box.itemObjList[index].badge.setValue(value);
|
|
471
|
+
};
|
|
472
|
+
// USAGE: bar.setBadge(1, 5)
|
|
473
|
+
|
|
474
|
+
box.selectNone = function () {
|
|
475
|
+
box.selectedIndex = -1;
|
|
476
|
+
box.refreshOneTime();
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
box.selectByIndex = function (index) {
|
|
480
|
+
box.selectedIndex = index;
|
|
481
|
+
isFloatLabelWaiting = 1; // The name shows over it ("float").
|
|
482
|
+
box.refreshOneTime();
|
|
483
|
+
};
|
|
484
|
+
// USAGE: get: bar.selectedIndex, set: bar.selectByIndex(2)
|
|
485
|
+
|
|
486
|
+
box.setLabelMode = function (mode) {
|
|
487
|
+
box.labelMode = mode;
|
|
488
|
+
applyLabelMode();
|
|
489
|
+
box.refreshOneTime();
|
|
490
|
+
};
|
|
491
|
+
// USAGE: get: bar.labelMode, set: bar.setLabelMode("float") // "inline", "float", "none"
|
|
492
|
+
|
|
493
|
+
// Places the items from the left: the selected one is wider ("inline": icon + label), then the bar takes their width.
|
|
494
|
+
box.refresh = function () {
|
|
495
|
+
|
|
496
|
+
const _layout = box.style.layout;
|
|
497
|
+
const _barPadding = getBarPadding();
|
|
498
|
+
let _currentLeft = _barPadding;
|
|
499
|
+
|
|
500
|
+
if (box.selectedIndex == -1) box.selectedBox.opacity = 0;
|
|
501
|
+
|
|
502
|
+
box.itemObjList.forEach((item, index) => {
|
|
503
|
+
const isSelected = (index == box.selectedIndex);
|
|
504
|
+
item.icon.left = _currentLeft;
|
|
505
|
+
item.label.left = getLabelLeft(item, isSelected);
|
|
506
|
+
paintItem(item, isSelected);
|
|
507
|
+
if (isSelected) placeSelectedBox(item);
|
|
508
|
+
_currentLeft += getItemWidth(item, isSelected) + _layout.itemSpacing;
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
_currentLeft += _barPadding - _layout.itemSpacing;
|
|
512
|
+
box.innerBox.width = _currentLeft;
|
|
513
|
+
box.innerBox.center();
|
|
514
|
+
|
|
515
|
+
refreshFloatLabel();
|
|
516
|
+
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// *** OBJECT VIEW:
|
|
520
|
+
|
|
521
|
+
// BOX: The bar (the items are added into it by createButton)
|
|
522
|
+
box.innerBox = startBox({
|
|
523
|
+
round: box.style.background.round,
|
|
524
|
+
width: BAR_WIDTH,
|
|
525
|
+
height: box.style.layout.barHeight,
|
|
526
|
+
border: box.style.background.border,
|
|
527
|
+
});
|
|
528
|
+
box.innerBox.css.background = box.style.background.gradient;
|
|
529
|
+
box.innerBox.setMotion("width 0.3s, left 0.3s");
|
|
530
|
+
|
|
531
|
+
// BOX: Behind the selected item
|
|
532
|
+
box.selectedBox = Box(0, 0, SELECTED_BOX_WIDTH, box.style.selectedBox.height, box.style.selectedBox);
|
|
533
|
+
box.selectedBox.opacity = 0;
|
|
534
|
+
box.selectedBox.setMotion("left 0.3s, width 0.3s, opacity 0.3s, background-color 0.3s");
|
|
535
|
+
box.selectedBox.center("top");
|
|
536
|
+
|
|
537
|
+
endBox();
|
|
538
|
+
|
|
539
|
+
// NOTE: The pill of the name (box.lblFloat, "float") is made by applyLabelMode(), over the bar.
|
|
540
|
+
|
|
541
|
+
// *** OBJECT INIT CODE:
|
|
542
|
+
applyLabelMode();
|
|
543
|
+
createButtons(box.items);
|
|
544
|
+
box.onResize(function () {
|
|
545
|
+
box.innerBox.dontMotion();
|
|
546
|
+
box.innerBox.center();
|
|
547
|
+
box.refreshOneTime(); // WHY: A narrower screen (a phone turned) may need a smaller padding.
|
|
548
|
+
if (!box.lblFloat) return;
|
|
549
|
+
box.lblFloat.dontMotion();
|
|
550
|
+
placeFloatLabel();
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
return endObject(box);
|
|
554
|
+
|
|
555
|
+
};
|