question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTIONS] resizable, using unitWidth in px output into percent.

See original GitHub issue

Hi @artf,

Thanks for making this amazing framework. Recently I made a custom component based on your flexbox plugin.

demo The red arrow is the actual value of the model. The green arrow is what I expected to be.

Is that possible to set unitWidth as px but the output to be percent? Here is what I’ve tried

  1. I separated them as 2 component,
  • grid component, only as a container that will then I set the display into flex,
  • column component, which I put the resizable.
  1. set resizable
const keyWidth = 'width'
const step = 1
const minDim = 1
const unitWidth = 'px'

const resizerRight = {
    ...resizerBtm,
    tl: 0,
    tc: 0,
    tr: 0,
    cl: 0,
    cr: 1,
    bl: 0,
    bc: 0,
    br: 0,
    keyWidth,
    currentUnit,
    minDim,
    step
    unitWidth
 }
  1. Makes the column listen to the resizing event. (I am not sure if this was correct, I might need to make a new different post for this question)
init () {
  this.listenTo(this, 'change:style ', this.updateWidth)

  //...
}
  1. I want to update the model width from pixel into percent using simple math.
updateWidth(model) {
  //...
  model.setStyle({
    width: parseFloat(selectedWidth, 10) / containerWidth * 100 + '%'
  })
  //...
}

I am aware that the code above would create an infinite resizing. So, I am looking for another solution which leads me to the resizable source code.

I am wondering if I could make use of the methods listed there

var defaultOpts = {
  // ...
  mousePosFetcher: null,
  // Indicates custom target updating strategy
  updateTarget: null,
  // Function which gets HTMLElement as an arg and returns it relative position
  ratioDefault: 0,
  posFetcher: null,
  onStart: null,
  onMove: null,
  onEnd: null,
 
  // ...
}

here is the demo link and the code

Sorry for this long post, I just want to make it easier for you to understand my case.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
afdallahcommented, May 2, 2019

You are the man!!! 👍 👍 Thank you so much @artf.

1reaction
artfcommented, May 1, 2019

Ah wait, my fault, opts is the 3rd one updateWidth(model, value, opts = {}) { btw the second argument in setStyle are options (eg, { silent: true } to avoid triggering change listeners) and you get those options also in the callback of your listeners so I just placed a custom key fromPxToPerc to know when the change is triggered from your custom logic

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change correctly font-size:x% with pt or px?
The code from here seems to be close to what you need, specifically: switch (unitSize.Unit.Type) { case UnitType.Pixel: result = (int)Math.Round(unitSize.
Read more >
Solved: Resizing layers using pixels instead of percentage...
Right now the info panel shows only percentages. I would like to know the current pixel size, height and width, so I know...
Read more >
Resize and position items using percents or pixels
Resize and position items using percents or pixels. You can resize layout items (images, overlay text, and multiple video sources) using the percent/pixel...
Read more >
<percentage> - CSS: Cascading Style Sheets - MDN Web Docs
Numerous properties can use percentages, such as width, height, ... a real value (such as a width in pixels for a <length> value)...
Read more >
How to resize image with percent in powertoys - Super User
I am using the image resizer tool in powertoys to resize multiple images at once. The problem is when I switch the unit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found