Code Monkey home page Code Monkey logo

flexlayout's Introduction

FlexLayout

中文介绍

FlexLayout is an C implementation of Flexible Box layout. It follows the standard algorithm and supports almost all features.

FlexLayout is battle tested. Please feel free to use.

Usage

C/C++

    FlexNodeRef root = Flex_newNode();
    
    FlexNodeRef child1 = Flex_newNode();
    Flex_setWidth(child1, 50);
    Flex_setHeight(child1, 50);
    Flex_addChild(root, child1);

    FlexNodeRef child2 = Flex_newNode();
    Flex_setWidth(child2, 50);
    Flex_setHeight(child2, 50);
    Flex_addChild(root, child2);

    Flex_layout(root, FlexUndefined, FlexUndefined, 1);
    Flex_print(root, FlexPrintDefault);

    Flex_freeNodeRecursive(root);

Javascript

FlexLayout has ported to javascript by using nbind.

    var root = new flex.Node();
    root.direction = flex.Vertical;

    var child1 = new flex.Node();
    child1.width = new flex.Length(50);
    child1.height = new flex.Length(50);
    root.add(child1);

    var child2 = new flex.Node();
    child2.setMeasure(function(size){return new flex.Size(10, 10);});
    root.add(child2);

    root.layout(NaN, NaN);
    root.print();

Features

  • margin/padding
  • min/max size
  • flex-direction
  • wrap
  • align-items
  • align-self
  • align-content
  • justify-content
  • flex-basis
  • flex-grow
  • flex-shrink
  • percentage

Additions

FlexLayout added some useful properties:

  • spacing / line-spacing spacing between items/lines
  • fixed do not participate the flex layout,like position: absolute
  • lines maximum number of lines
  • items-per-line maximum number of items in each line

Known Issues

  • min-width/min-height do not support auto
  • order is not supported

License

Licensed under the MIT License.


中文介绍

FlexLayoutFlexible Box 布局算法的 C 语言实现。按照标准算法实现,几乎支持所有特性。

FlexLayout 经过充分测试,请放心食用。

使用

C/C++

    FlexNodeRef root = Flex_newNode();
    
    FlexNodeRef child1 = Flex_newNode();
    Flex_setWidth(child1, 50);
    Flex_setHeight(child1, 50);
    Flex_addChild(root, child1);

    FlexNodeRef child2 = Flex_newNode();
    Flex_setWidth(child2, 50);
    Flex_setHeight(child2, 50);
    Flex_addChild(root, child2);

    Flex_layout(root, FlexUndefined, FlexUndefined, 1);
    Flex_print(root, FlexPrintDefault);

    Flex_freeNodeRecursive(root);

Javascript

FlexLayout 使用 nbind 移植了 javascript 版本。

    var root = new flex.Node();
    root.direction = flex.Vertical;

    var child1 = new flex.Node();
    child1.width = new flex.Length(50);
    child1.height = new flex.Length(50);
    root.add(child1);

    var child2 = new flex.Node();
    child2.setMeasure(function(size){return new flex.Size(10, 10);});
    root.add(child2);

    root.layout(NaN, NaN);
    root.print();

支持的特性

  • margin/padding
  • min/max size
  • flex-direction
  • wrap
  • align-items
  • align-self
  • align-content
  • justify-content
  • flex-basis
  • flex-grow
  • flex-shrink
  • 百分比

扩展属性

FlexLayout 增加了以下扩展属性:

  • spacing / line-spacing 为每两个元素/行之间增加间距
  • fixed 元素不参与 flex 布局,类似于 position: absolute
  • lines 最大行数
  • items-per-line 每行最大元素个数

已知问题

  • min-width/min-height 不支持设置为 auto
  • 不支持 order 属性

协议

遵循 MIT 协议。

flexlayout's People

Contributors

sleen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flexlayout's Issues

when reLayout ui and the result is not change

I want to relayout my ui, but the result is not change. Like this, first I set child1 height is 50, But when the context is too much, I will set child1 is 150. So I set Height is 150, I hope reLayout the root. But is not change. code like as follows:
FlexNodeRef root = Flex_newNode();
Flex_setDirection(root, FlexVertical);
FlexNodeRef child1 = Flex_newNode();
Flex_setWidth(child1, 50);
Flex_setHeight(child1, 50);
Flex_addChild(root, child1);
FlexNodeRef child2 = Flex_newNode();
Flex_setWidth(child2, 50);
Flex_setHeight(child2, 50);
Flex_addChild(root, child2);
Flex_layout(root, FlexUndefined, FlexUndefined, 1);
// re-layout child1
Flex_setHeight(child1, 150);
Flex_layout(root, FlexUndefined, FlexUndefined, 1);
Flex_print(root, FlexPrintDefault);

the running result in vscode like this:
First printLayout:
{
direction: vertical
result-width: 50.0
result-height: 100.0
children: [
{
width: 50.0
height: 50.0
result-width: 50.0
result-height: 50.0
}
{
width: 50.0
height: 50.0
result-y: 50.0
result-width: 50.0
result-height: 50.0
}
]
}
Second printLayout:
{
direction: vertical
result-width: 50.0
result-height: 100.0
children: [
{
width: 50.0
height: 150.0
result-width: 50.0
result-height: 50.0
}
{
width: 50.0
height: 50.0
result-y: 50.0
result-width: 50.0
result-height: 50.0
}
]
}
Second layout child2 result-y is still 50, it should be 150. cause i change child1 height 150. I don't know how to do this, maybe is not use this method to relayout. Can u help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.