Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENT] Coordinate button placement #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 19 additions & 35 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ body {
.menu-screen {
padding: 4px;
background-image: linear-gradient(rgb(66 79 157), rgb(126 170 220));
display: inline-block;
margin-right: 10px;
display: grid;
grid-template-columns: repeat(5, 60px);
grid-template-rows: repeat(8, 55px);
gap: 6px;
}

.menu-screen-path {
padding-top: 20px;
margin: 0px auto;
width: 100%;
display: block;
text-align: center;
white-space: nowrap;

display: flex;
justify-content: center;
}

.search-bar {
display: grid;
grid-template-columns: 200px auto 200px;
Expand Down Expand Up @@ -86,43 +89,18 @@ body {

@keyframes blinker {
50% {
opacity: .1;
background-color: white;
}
}

.menu-row {
height: 61px;
}

.menu-button {
position: relative;
display: inline-block;
background-color: white;
color: black;
height: 55px;
margin: 2px;
border: 1px solid white;
}

.menu-button > .background {
position: absolute;
z-index: 100;
width: 100%;
height: 100%;
}

.menu-button.selected-true > .background {
animation: blinker 1s linear infinite !important;
}

.menu-button > .foreground {
position: absolute;
z-index: 110;
width: 100%;
height: 100%;
/* white-space: nowrap; */
/* text-align: center; */
/* vertical-align: middle; */
box-sizing: border-box;

font-size: 9px;
font-weight: bold;
font-family: helvetica;
Expand All @@ -132,12 +110,18 @@ body {
justify-content: center;
}

.menu-button.selected-true {
animation: blinker 1s linear infinite !important;
}

.menu-button.span-1 {
width: 60px;
grid-column: span 1;
grid-row: span 1;
}

.menu-button.span-2 {
width: 124px;
grid-column: span 2;
grid-row: span 1;
}

.text-color-black {
Expand Down
154 changes: 26 additions & 128 deletions src/data/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,166 +366,64 @@
"backColor": "yellow",
"keywords": [
"CHEESE"
]
],
"x": 1,
"y": 1
},
{
"label": "FUNGHI\n PIZZE",
"backColor": "yellow",
"keywords": [
"MUSHROOM"
]
],
"x": 2,
"y": 1
},
{
"label": "SALAMI\n RICCOTA",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
"backColor": "yellow",
"x": 3,
"y": 1
},
{
"label": "ZUCCHIN\nI PIZZE",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
"backColor": "yellow",
"x": 5,
"y": 1
},
{
"label": "CAPS/GO\nATS\n PIZZE",
"backColor": "yellow",
"comments": "is CAPS = CAPSICUM? What is GOATS?"
},
{
"label": "",
"backColor": "yellow"
"comments": "is CAPS = CAPSICUM? What is GOATS?",
"x": 2,
"y": 2
},
{
"label": "ZATAR\n PIZZA",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
"backColor": "yellow",
"x": 4,
"y": 2
},
{
"label": "SALAMI/\nFUNGHI",
"backColor": "yellow",
"keywords": [
"MUSHROOM"
]
],
"x": 1,
"y": 3
},
{
"label": "SALAMI/\nOLIVES",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
},
{
"label": "",
"backColor": "yellow"
"backColor": "yellow",
"x": 2,
"y": 3
},
{
"label": "FOOD INST",
"backColor": "white",
"x": 4,
"y": 8,
"span": 2
}
]
Expand Down
14 changes: 10 additions & 4 deletions src/modules/pure-components/MenuButton.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const MenuButton = () => ({ item, selected = false }) => {
const { label, backColor, textColor = 'black', span = 1 } = item;
const buttonText = { __html: label.replaceAll('\n', '<br>') };
return <div className={`menu-button span-${span} selected-${selected}`}>
<div className={`background back-color-${backColor}`}></div>
<div className={`foreground text-color-${textColor}`} dangerouslySetInnerHTML={buttonText}></div>
</div>;
const gridColumn = item.x ? `${item.x} / span ${span}` : undefined;
const gridRow = item.y ? `${item.y} / span 1` : undefined;
return <div
style={{gridColumn, gridRow}}
className={`
menu-button
span-${span} selected-${selected}
back-color-${backColor}
text-color-${textColor}
`} dangerouslySetInnerHTML={buttonText} />
}

export default MenuButton;
37 changes: 27 additions & 10 deletions src/modules/pure-components/MenuScreen.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
const MenuScreen = ({ pureComponents, menuReader }) => ({ path, selectedItem }) => {
const MAX_NUMBER_OF_BUTTONS=40;

const getSum = (total, item) => {
const width = item.span ?? 1;
return total + width;
}

const MenuScreen =
({ pureComponents, menuReader }) =>
({ path, selectedItem }) => {
const submenu = menuReader.getSubmenu(path);
if (!submenu.rows) return null;
if (!submenu.items) return null;

const numberButtons = submenu.items.reduce(getSum, 0);

const spacers = [...Array(MAX_NUMBER_OF_BUTTONS - numberButtons)].map(i => {
return <pureComponents.SpacerButton backColor={submenu.backColor}/>;
});

const isSelected = menuReader.isSelected(selectedItem);

const rows = submenu.rows.map((row, index) => {
const buttons = row.map(item => {
const selected = isSelected(item);
return <pureComponents.MenuButton key={item.id} selected={selected} item={item} />
});
return <div key={index} className="menu-row">{buttons}</div>;
const items = submenu.items.map((item) => {
const selected = isSelected(item);
return (
<pureComponents.MenuButton
key={item.id}
selected={selected}
item={item}
/>
);
});

return <div className="menu-screen">{rows}</div>;
}
return <div className="menu-screen">{items}{spacers}</div>;
};

export default MenuScreen;
19 changes: 13 additions & 6 deletions src/modules/pure-components/MenuScreenPath.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
const MenuScreenPath = ({ pureComponents, util }) => ({ selectedItem }) => {

const MenuScreenPath =
({ pureComponents, util }) =>
({ selectedItem }) => {
if (!selectedItem) return null;

const pathIncrements = util.inflate(selectedItem.pathArray);

const menuScreens = pathIncrements.map(path => {
return <pureComponents.MenuScreen key={path} path={path} selectedItem={selectedItem} />
const menuScreens = pathIncrements.map((path) => {
return (
<pureComponents.MenuScreen
key={path}
path={path}
selectedItem={selectedItem}
/>
);
});

return <div className="menu-screen-path">{menuScreens}</div>
}
return <div className="menu-screen-path">{menuScreens}</div>;
};

export default MenuScreenPath;
14 changes: 14 additions & 0 deletions src/modules/pure-components/SpacerButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const SpacerButton = () => ({ backColor }) => {
if (!backColor) {
return null;
}

return <div
className={`
menu-button
span-1
back-color-${backColor}
`} />
}

export default SpacerButton;
Loading