From 8f388e974ecf8460a9dcdee59bfab6ae347ab1ae Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 9 May 2020 18:12:53 +0200 Subject: [PATCH] menu: menu alignment options --- src/client/widgets/basics/menu.js | 14 ++++++++++---- src/scss/widgets/basics.scss | 30 +++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/client/widgets/basics/menu.js b/src/client/widgets/basics/menu.js index e5e4e8f6..1014c4fe 100644 --- a/src/client/widgets/basics/menu.js +++ b/src/client/widgets/basics/menu.js @@ -22,7 +22,8 @@ class Menu extends MenuBase { '- If `layout` is `circular`: diameter (in px)', '- Else: square size or `[width, height]` array', ]}, - align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Set to `left` or `right` to change text alignment (otherwise center)'}, + alignV: {type: 'string', value: 'center', choices: ['center', 'top', 'bottom'], help: 'Set to `top` or `bottom` to change menu alignment (otherwise center)'}, + alignH: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Set to `left` or `right` to change menu alignment (otherwise center)'}, layout: {type: 'string', value: 'circular', choices: ['circular', 'horizontal', 'vertical', 'grid'], help: [ 'Defines whether the menu\'s layout should be rendered in a circle or in a box' ]}, @@ -36,7 +37,8 @@ class Menu extends MenuBase { weights: {type: 'array', value: '', help: [ '`Array` of `number` defining the weights of each value in `values`', 'Ignored when `mode` is `grid`' - ]} + ]}, + textAlign: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Set to `left` or `right` to change text alignment (otherwise center)'}, }) @@ -52,8 +54,9 @@ class Menu extends MenuBase { `}) - if (this.getProp('align') === 'left') this.widget.classList.add('left') - if (this.getProp('align') === 'right') this.widget.classList.add('right') + this.widget.classList.add('text-align-' + this.getProp('textAlign')) + this.widget.classList.add('menu-align-h-' + this.getProp('alignH')) + this.widget.classList.add('menu-align-v-' + this.getProp('alignV')) this.menu = html`` this.text = DOM.get(this.widget, '.text')[0] @@ -270,6 +273,9 @@ class Menu extends MenuBase { parent = parent.parent } + scrollX += parent.widget.scrollLeft + scrollY += parent.widget.scrollTop + this.container.style.setProperty('--parent-scroll-x', scrollX + 'px') this.container.style.setProperty('--parent-scroll-y', scrollY + 'px') diff --git a/src/scss/widgets/basics.scss b/src/scss/widgets/basics.scss index 69ae2b12..ee9dd12e 100644 --- a/src/scss/widgets/basics.scss +++ b/src/scss/widgets/basics.scss @@ -149,16 +149,32 @@ position: relative; @include pseudo-stroke(); - &.right .text { + &.text-align-right .text { justify-content: flex-end; } - &.left .text{ + &.text-align-left .text{ justify-content: flex-start; } + + + &.menu-align-h-right { + justify-content: flex-end; + } + &.menu-align-h-left{ + justify-content: flex-start; + } + &.menu-align-v-top { + align-items: flex-start; + } + &.menu-align-v-bottom{ + align-items: flex-end; + } + } .text { flex: 1; + height: 100%; text-align: center; display: flex; justify-content: center; @@ -190,10 +206,11 @@ menu { // animation: menu-widget-fade .1s forwards; - position: fixed; z-index: 999999999; + margin-left: calc(-1 * var(--parent-scroll-x)); + margin-top: calc(-1 * var(--parent-scroll-y)); overflow: hidden; @@ -223,8 +240,7 @@ border-radius: 100%; width:var(--size); height:var(--size); - margin-left: calc(-1 * var(--parent-scroll-x)); - margin-top: calc(-1 * var(--parent-scroll-y)); + &:after { content:""; @@ -298,10 +314,6 @@ width:var(--size-box-w); height:var(--size-box-h); - margin-left: calc(var(--x) - var(--size-box-w) / 2); - margin-top: calc(var(--y) - var(--size-box-h) / 2); - // top:var(--size-box-h); - // margin-top: 0; display: flex;