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

Dynamically set the width and height of a component #248

Open
wants to merge 1 commit into
base: dev
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
18 changes: 16 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ declare module '@lightningjs/blits' {

export type ComponentBase = {
/**
* Check if a component has focus
* Indicates whether the component currently has focus
*
* @returns Boolean
*/
hasFocus: boolean,

Expand Down Expand Up @@ -244,11 +246,23 @@ declare module '@lightningjs/blits' {
* Deprecated: use `this.$trigger()` instead
*/
trigger: (key: string) => void

/**
* Router instance
*/
$router: Router
/**
* Dynamically set the size of a component holder node
*/
$size: (dimensions: {
/**
* Component width
*/
w: number,
/**
* Component height
*/
h: number
}) => void
Comment on lines +256 to +265

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @michielvandergeest,

Also If possible I would like to pass props to the element with only one object.

Just for example;

:props: $props, 

Example props objects

 const props1 = {
  fontFamily: 'Arial',
  fontSize: 20,
 }

const props2 = {
   x: 1,
   y: 2,
   w: 100,
   h: 100,
 }

}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/component/base/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import symbols from '../../lib/symbols.js'
import { renderer } from '../../launch.js'

export default {
$size: {
value: function (dimensions = { w: 0, h: 0 }) {
this[symbols.holder].set('w', dimensions.w || 0)
this[symbols.holder].set('height', dimensions.h || 0)
},
writable: false,
enumerable: true,
configurable: false,
},
[symbols.renderer]: {
value: () => renderer,
writable: false,
Expand Down