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

Add LinearLayout #563

Merged
merged 4 commits into from Aug 21, 2021
Merged

Add LinearLayout #563

merged 4 commits into from Aug 21, 2021

Conversation

beansgum
Copy link
Contributor

@beansgum beansgum commented Aug 18, 2021

LinearLayout serves as a wrapper for several gio layout structs and it reduces the amount of code required when applying basic attributes like padding, margin, border, etc to a layout. The number of lines of code used for the most basic layouts can sometimes look very complex due to the multiple nested functions.

This layout code:

return layout.Inset{Top: values.MarginPadding10}.Layout(gtx, func(gtx C) D {
	return layout.Stack{}.Layout(gtx,
		layout.Expanded(func(gtx C) D {
			// // draw background and and clip the background to border radius
			tr := float32(gtx.Px(unit.Dp(Border.Radius.TopRight)))
			tl := float32(gtx.Px(unit.Dp(Border.Radius.TopLeft)))
			br := float32(gtx.Px(unit.Dp(Border.Radius.BottomRight)))
			bl := float32(gtx.Px(unit.Dp(Border.Radius.BottomLeft)))
			clip.RRect{
				Rect: f32.Rectangle{Max: f32.Point{
					X: float32(gtx.Constraints.Min.X),
					Y: float32(gtx.Constraints.Min.Y),
				}},
				NW: tl, NE: tr, SE: br, SW: bl,
			}.Add(gtx.Ops)
			return fill(gtx, bgColor)
		}),
		layout.Stacked(func(gtx C) D {
			return Border{Color: borderColor, Width: values.MarginPadding2}.Layout(gtx, func(gtx C) D {
				return layout.Inset{Top: values.MarginPadding10}.Layout(gtx, func(gtx C) D {
					return layout.E.Layout(gtx, func(gtx C) D {
						return layout.Flex{Axis: layout.Vertical}.Layout(gtx, children...)
					})
				})
			})
		}),
	)
})

Can be replaced by this using the LinearLayout:

decredmaterial.LinearLayout{
	Width:       decredmaterial.MATCH_PARENT,
	Height:      decredmaterial.WRAP_CONTENT,
	Orientation: layout.Vertical,
	Background:  pg.Theme.Color.Orange,
	Margin:      layout.Inset{Top: values.MarginPadding16},
	Padding:     layout.UniformInset(values.MarginPadding16),
	Border:      decredmaterial.Border{Width: values.MarginPadding1, Color: pg.Theme.Color.Danger},
	Direction:   layout.Center,
}

I created an example of LinearLayout here and this is the result:

LinearLayout serves as a wrapper for several gio layout structs and
it reduces the amount of code required when applying basic attributes
like padding, margin, border, etc to a layout.
@beansgum beansgum marked this pull request as ready for review August 18, 2021 14:52
@Sirmorrison
Copy link
Contributor

image

clicking on the receive page, this is the UI that shows up.
I believe you where testing out what you implemented.
This can be done on the testapp package.

ui/page/more_page.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Sirmorrison Sirmorrison left a comment

Choose a reason for hiding this comment

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

You did not add the sample layout code to the test package for code reference.

return layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx C) D {
ll.applyDimension(&gtx)
// // draw background and and clip the background to border radius
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// // draw background and and clip the background to border radius
// draw background and clip the background to border radius

Sirmorrison
Sirmorrison previously approved these changes Aug 20, 2021
@Sirmorrison Sirmorrison moved this from Review in progress to Approved in godcr board Aug 20, 2021
dreacot
dreacot previously approved these changes Aug 20, 2021
@beansgum beansgum dismissed stale reviews from dreacot and Sirmorrison via d2fb8f2 August 20, 2021 16:07
godcr board automation moved this from Approved to Review in progress Aug 20, 2021
godcr board automation moved this from Review in progress to Approved Aug 21, 2021
@Sirmorrison Sirmorrison merged commit 1dea651 into planetdecred:master Aug 21, 2021
godcr board automation moved this from Approved to Done Aug 21, 2021
song50119 pushed a commit to song50119/godcr that referenced this pull request Apr 24, 2022
* Add LinearLayout

LinearLayout serves as a wrapper for several gio layout structs and
it reduces the amount of code required when applying basic attributes
like padding, margin, border, etc to a layout.

* Fix lint

* Fix typo in comment

* Use linear layout in more page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
godcr board
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants