Skip to content

Move .width(…) and .height(…) into ui.element() #94

Description

@twilit-jack

Summary

Looking for feedback about moving the .width(…) and .height(…) methods directly into .ui.element().

Motivation

.width(…) and .height(…) are two of the most frequently seen methods in a Ply codebase. Almost every element has them. And omitting them is a bit unclear on functionality (I believe the default is fit-sizing, though this seems more like an implementation detail rather than something to rely on, and is a bit unclear to the reader anyway).

Furthermore, rustfmt formats long method chains vertically, and .width(…) and .height(…) takes up two extra lines. And if our brains might want to do something like ui.element().width(…).height(…) on one line, but rustfmt won't exactly allow that. And turning off rustfmt for this one single thing has in my experience been not worth it.

And both of the properties mostly show up in the same order, or at least, it's clearer if they do. So why not get rid of the .width and .height parts and inline them directly in the ui.element() method?

Proposed API

ui.element(fixed!(180), grow!()) // Sizing defined inline here
	.background_color(0xaaa0be) // Rest of the methods continuing down here
	.layout(|l| l.direction(TopToBottom))
	.children(|ui| {
		ui.text("My cool sidebar without any buttons", |t| t.font_size(14).color(0xffffff));
	});
// Currently it would be this long method chain
ui.element()
	.width(fixed!(180))
	.height(grow!())
	.background_color(0xaaa0be)
	.layout(|l| l.direction(TopToBottom))
	.children(|ui| {
		ui.text("My cool sidebar without any buttons", |t| t.font_size(14).color(0xffffff));
	});

// Or this workaround while disabling rustfmt
ui.element().width(fixed!(180)).height(grow!())
	.background_color(0xaaa0be)
	.layout(|l| l.direction(TopToBottom))
	.children(|ui| {
		ui.text("My cool sidebar without any buttons", |t| t.font_size(14).color(0xffffff));
	});

Notes

  • This is just looking for feedback. I see a few reasons why someone might not want this (e.g. being a slight bit opaque to people looking at the lib for the first time, though this one is a bit of a minor concern in my opinion).
  • I was unsure how to label this issue, I just went for copying the feature request template (though this isn't a feature per se), and putting this as an idea.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaA loose idea

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions