Why doesn't PageComponent respect the right contentInset - framerjs

This is taken (almost) verbatim from PageComponent example (minus the imported Sketch doc), yet in my code, the right contentInset is totally ignored and the cards are offset strangely on each card after the first.
# Set-up PageComponent
page = new PageComponent
width: Screen.width
height: Screen.height
y: 0
scrollVertical: false
contentInset: {top: 32, left: 32, right: 32}
backgroundColor: "pink"
# Variable that adjusts the amount of cards
amount = 4
print page.width
print screen.width
# Create and style the cards within a loop
for i in [0...amount]
card = new Layer
backgroundColor: "#fff"
borderRadius: 8
width: page.width - 64
height: 1040
x: page.width * i
superLayer: page.content
card.style.boxShadow = "0 1px 6px rgba(0,0,0,0.2)"
I'm using Framer Studio ver 1.13.25 (1583)

Seems to be a bug in one of the latest versions of the framerjs library.
You can overpass the bug by putting every page inside a full width wrapper.
Check here a fixed example: http://share.framerjs.com/z09x27iqjce1/​
I hope it helps :)

Related

Last Item added to Scrollview is cut

As Long as all the Items inside the Scrollview are smaler than the screen itself everything is fine, as soon as they get bigger the Last Item at the bottom is beeing cut in half and i cant scroll to see it propperly.
Kivy:
GridLayout:
ScrollView:
size_hint_y: None
pos_hint: {'x':self, 'y':self}
do_scroll_x: False
do_scroll_y: True
size: root.width, root.height / 1.25
GridLayout:
cols:1
padding: 15
spacing:10
height: sum(x.height for x in self.children)
size_hint_y:None
id: Zitate
Python:
btn = Button(text = '\n"' + self.root.ids.Kommentar.text + '"' + "\n ~" + self.root.ids.field.text + "\n", size_hint = (0.8 , None))
self.root.ids.Zitate.add_widget(btn)
Replace:
height: sum(x.height for x in self.children)
with:
height: self.minimum_height
The function that you are trying to use is built in to the GridLayout.
You should also set a specific height for each Button.

How to solve a special "select and transform: resize text" problem?

1. Background:
I use konvajs to create a "table" component:
structure:
Stage
|
Layer
|
+-----+--------------+
| |
Group(tableGroup) Group(tableGroup)
|
+--------------+--------+
| |
Group(cellGroup) Group(cellGroup)
|
+----+----+
| |
Shape(Rect) Shape(Text)
image:
table component
2. Target:
I want every text shape to be width adaptive.
I found it in the official documents of konvajs:
How to change width of the text with transforming tool? https://konvajs.org/docs/select_and_transform/Resize_Text.html
Scenario 1: add all "cellGroup" to "transformer"
// My code
tableGroup.on('click', function (e) { // Click the selected table
tr.nodes([])
tableGroup.getChildren().map(function(item) {
tr.nodes(tr.nodes().concat(item)); // Add all cellGroups to transformer
item.off('transform')
item.on('transform', (e) => {
item.setAttrs({
width: item.width() * item.scaleX(),
height: item.height() * item.scaleY(),
scaleX: 1,
scaleY: 1,
});
item.getChildren().map(function(child){
child.setAttrs({
width: item.width() * item.scaleX(),
height: item.height() * item.scaleY(),
scaleX: 1,
scaleY: 1,
});
})
})
})
});
Scheme 2: add "tablegroup" to "transformer"
// My code
tableGroup.on('click', function (e) { // Click the selected table
tr.nodes([tableGroup]) // Add all tableGroup to transformer
tableGroup.on('transform', (e) => {
tableGroup.getChildren().map(function(item) {
item.setAttrs({
width: item.width() * item.scaleX(),
height: item.height() * item.scaleY(),
scaleX: 1,
scaleY: 1,
});
item.getChildren().map(function(child){
child.setAttrs({
width: item.width() * item.scaleX(),
height: item.height() * item.scaleY(),
scaleX: 1,
scaleY: 1,
});
})
})
})
});
conclusion: Scheme 1 is feasible, but scheme 2 is not.My requirement is to add "tableGroup" to transformer and realize text width adaptation.Find a solution, thank you very much.
3. Other:
Q: Why must "tableGroup" be added to "transformer"?
A: Because when moving a "Group" or "Shape" with "Transformer", the coordinates (x, y) of the "Group" or "Shape" will be changed. I don't want to change the coordinates of "cellGroup", I want to change the coordinates of "tableGroup" (x, y). Or you have a better solution.Find a solution, thank you very much.
Here is a solution using two groups - one for the table outline and a second to contain the cells. The cell group has its attrs set to follow the table group as it is transformed - excluding the scale!
This is not a perfect solution that you can cut & paste as a usable component but should show you a potential alternative.
/*
* From here onwards we set up the stage and its contents.
*/
const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
}),
layer = new Konva.Layer(),
tblGroup = new Konva.Group({draggable: true}),
cellGroup = new Konva.Group(),
cellRect = new Konva.Rect({strokeWidth: 1, stroke: 'black', name: 'cellRect'}),
cellText = new Konva.Text({fontName: "Arial", fontSize: 20, fill: 'black', name: 'cellText'}),
tr = new Konva.Transformer();
stage.add(layer);
layer.add(tr);
// Using this plain JS objet to define the table and relative cell positions.
const tblData = {
position: { x: 100, y: 100, width: 202, height: 82},
cells: [
{x: 1, y: 1, width: 100, height: 40, text: 'Cell 1-1'},
{x: 101, y: 1, width: 100, height: 40, text: 'Cell 1-2'},
{x: 1, y: 41, width: 100, height: 40, text: 'Cell 2-1'},
{x: 101, y: 41, width: 100, height: 40, text: 'Cell 2-2'},
]
}
const tableGroup = tblGroup.clone({x: tblData.position.x, y: tblData.position.y}),
tblPosGroup = tableGroup.clone(), // position exactly as tableGroup.
tblRect = cellRect.clone({x:0, y: 0, width: tblData.position.width, height: tblData.position.height});
tblRect.stroke('red');
tableGroup.add(tblRect);
// add the cells.
for (let i = 0; i < tblData.cells.length; i++){
const
cell = cellGroup.clone({}),
rect = cellRect.clone(tblData.cells[i]),
text = cellText.clone(tblData.cells[i]);
// Note we stach the positioning data into the Konva shape instances in a custom attr - used in the transform event
rect.setAttrs({posData: tblData.cells[i]});
text.setAttrs({posData: tblData.cells[i]});
cell.add(rect,text);
tblPosGroup.add(cell);
}
layer.add(tableGroup, tblPosGroup);
tableGroup.on('transform', (e) => {
// make the cells group follow the tbl group as it is transformed
tblPosGroup.setAttrs({position: tableGroup.position(), rotation: tableGroup.rotation()});
// find all the objects we want to manager - using the shape name() attr which we search with a dot prefix.
tblPosGroup.find('.cellRect, .cellText').map(function(item) {
const cellPos = item.getAttr("posData");
// set the position and size of the cells referring to original position & size data and applying scale from transformer.
item.setAttrs({
x: cellPos.x * tableGroup.scaleX(),
y: cellPos.y * tableGroup.scaleY(),
width: cellPos.width * tableGroup.scaleX(),
height: cellPos.height * tableGroup.scaleY()
});
})
})
tblPosGroup.on('click', function (e) { // When the table is clicked - actually we listen on the cells group as this will get the click
tr.nodes([tableGroup]); // Add all tableGroup to transformer
e.cancelBubble = true;
})
stage.on('click', function (e) {
tr.nodes([]);
})
body {
margin: 20px;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
<script src="https://unpkg.com/konva#8/konva.min.js"></script>
<p>A table-like construction. The aim was to keep cell contents unchanged in size and scale whilst allowing a transformer to be used.</p>
<p>Solution is two groups. Group#1 is the main table rect and group#2 is the cells. Group#2 attrs are set to follow group#1 attrs in the group#1.onTransform event listener.</p>
<div id="container"></div>

Prawn::Errors::CannotFit: Table's width was set too small to contain its contents

I am trying to create a table in Prawn using the following code however the columns widths do not suite well for me with columns width I have now. Given that I still have some free space, I want to expand a little bit the second and last columns so I increased both of them to 55.mm and 20.mm accordingly but I am getting an error
Prawn::Errors::CannotFit: Table's width was set too small to contain its contents (min width 450.70866141732284, requested 442).
Why does expanding a column width throws Tabe too small error?
I have calculated the total width of the columns:
9.mm + 45.mm + 20.mm + 20.mm + 20.mm + 30.mm + 15.mm + 20.mm #=> 507.40157480314963
I don't understand it. What am I doing wrong?
bounding_box [0, 792], width: 612, height: 792 do
bounding_box [30, 792], width: 442, height: 792 do
line_items_table
end
end
def line_items_table
table line_item_rows, table_options do
row(0).background_color = TABLE_BACKGROUND_COLOR
columns(2..-1).align = :right
end
end
def table_options
{
cell_style: { border_width: 0 },
column_widths: TABLE_COLUMN_WIDTHS,
header: true,
# width: 160.mm
}
end
def line_item_rows
[TABLE_HEADERS]
end
TABLE_COLUMN_WIDTHS = { 0 => 9.mm, 1 => 45.mm, 2 => 20.mm, 3 => 20.mm, 4 => 30.mm, 5 => 15.mm, 6 => 15.mm }.freeze
TABLE_HEADERS = [I18n.t('pdf.headers.row_num'), I18n.t('pdf.headers.name'),
I18n.t('pdf.headers.quantity'), I18n.t('pdf.headers.price_net_amount'), I18n.t('pdf.headers.net_amount'),
I18n.t('pdf.headers.vat'), I18n.t('pdf.headers.gross_amount')].freeze
#Table headers above are: 'No', 'Name', 'Qauntity', 'Net Sale', 'Net amount', 'Gross amount', 'VAT'
Table's width was set too small to contain its contents (min width 450.7, requested 442)
meaning your total column width must below 442, and your total currently is 450.7,
you should change it to below 442
you have line code that set 442
bounding_box [30, 792], width: 442, height: 792 do
if you want to set bigger then my suggestion you should change it first

Is there a workaround for using the CSS Calc property on Safari Mobile?

I have a bootstrap site that I have used the Calc css function. I understand that it is not supported by Safari Mobile. Is there a popular workaround? I couldn't find much when I searched the site.
left: calc(50% + 5px);
left: -moz-calc(50% + 5px);
left: -webkit-calc(50% + 5px);
-
width: calc(100% - 1em);
width: -moz-calc(100% - 1em);
width: -webkit-calc(100% - 1em);

Wrong astarNode.x and astarNode.y using Phaser + AStar Plugin

I was having a little trouble trying to use AStar + Phaser. I debugged it a bit and discovered a little bug. The X and Y of the astarNode property are wrong. I'm still trying to fix it, but you guys maybe help me to find the problem faster.
Code:
preload: function() {
this.game.load.tilemap('map', 'assets/tilemap.json', null, Phaser.Tilemap.TILED_JSON);
this.game.load.image('RPGPackSheet', 'assets/sprites/RPGPackSheet.png');
},
create: function() {
this.map = this.game.add.tilemap('map');
this.map.addTilesetImage('RPGPackSheet');
this.layer = this.map.createLayer('LayerName');
this.astar = this.game.plugins.add(Phaser.Plugin.AStar);
this.astar.setAStarMap(this.map, 'LayerName', 'RPGPackSheet');
console.log(this.map.layers[0].data[4][6].properties.astarNode);
},
tilemap.json
The output on the console should be:
f: 0,
g: 0,
h: 0,
walkable: false,
x: 4, // equals to the second index of layers[0].data
y: 6 // equals to the first index of layers[0].data
But is giving me:
f: 0,
g: 0,
h: 0,
walkable: false,
x: 24,
y: 13
UPDATE: I found out something more. My tilemap.json uses only 2 tiles (42 and 52). So when the setAStarMap() is called, he updates the X and Y of every astarNode with the current x and y that it is on the for loop (to understand better check updateMap() of AStarPlugin). In the end, every astarNode that uses 42 will have x set to 24 and y set to 13 (which is the coordinates of the last astarNode using tile 42), and every astarNode that uses 52 will have x set to 13 and y set to 12 (again, coordinates of the last astarNode using tile 52). I just can't figure out why this is happening...
From what I know, world size in tiles of your map is supposed to be in a square size, so from what I see your world size in tiles is 25x14. So you can add a blank tiles to fill up your world map in order to get it to size 25x25

Resources