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

docs: views API: child views and layout engine #271

Closed
wants to merge 1 commit into from
Closed

Conversation

zcbenz
Copy link
Contributor

@zcbenz zcbenz commented Apr 16, 2020

This specs defines APIs to add/remove child views, and proposes to use YogaLayout as layout engine.

This is an example that implements a text editor with sidebar:

(The Button and TextEdit classes are not yet defined and only for demonstration purpose.)

const win = new TopLevelWindow({})

// The content view has its children arranged horizontally.
const content = new View()
content.setStyle({flexDirection: 'row'})
win.setContentView(content)

// The sidebar is a child of content view and has 5px paddings.
const sidebar = new View()
sidebar.setStyle({padding: 5})
contentView.addChildView(sidebar)

// The buttons in the sidebar, they shows images instead of text.
const open = new Button('')
open.setImage('open@2x.png')
open.setStyle({marginBottom: 5})
sidebar.addChildView(open)
const save = new Button('')
save.setImage('open@2x.png')
sidebar.addChildView(save)

// Make the sidebar have a fixed width which is enough to show all the buttons.
sidebar.setStyle({width: sidebar.getPreferredSize().width})

// The text edit view would take all remaining spaces.
const edit = new TextEdit()
edit.setStyle({flex: 1})
contentView.addChildView(edit)

@zcbenz
Copy link
Contributor Author

zcbenz commented Jun 15, 2020

Closing for now, will prepare a new spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant