xilem_masonry: Add Label widget#226
Conversation
| BoxConstraints, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, Point, PointerEvent, | ||
| Size, StatusChange, TextEvent, Widget, WidgetId, WidgetPod, | ||
| }; | ||
| pub use masonry::{widget::Axis, Color, TextAlignment}; |
There was a problem hiding this comment.
I'm shamelessly reexporting all these attributes to the root of the library (since I think they're mostly unambiguous), not sure what our policy here is.
There was a problem hiding this comment.
This is probably #223 again. I think this addition is fine, but we need to reason out a final policy for this, rather than making ad-hoc decisions
| let mut splice = VecSplice::new(&mut elements, &mut scratch); | ||
| let seq_state = self.sequence.build(cx, &mut splice); | ||
| let mut view = widget::Flex::column(); | ||
| let mut view = widget::Flex::for_axis(self.axis); |
There was a problem hiding this comment.
I didn't expose this intentionally, because Masonry doesn't support changing the axis at runtime.
We do not want to have views which give different final trees in build and rebuild
There was a problem hiding this comment.
Oh, haven't checked that closely yet. That's unfortunate, and I agree, all attributes that are able to set in the view should of course change the widget tree.
In that case maybe stick to something like h_flex or h_stack something a like (open for naming suggestions)?
There was a problem hiding this comment.
Or, well just implement it in masonry, checking that now...
There was a problem hiding this comment.
So I've implemented it in masonry, and checked it via
let axis = if count % 2 == 0 {
Axis::Horizontal
} else {
Axis::Vertical
};
...
flex(()).direction(axis)(but have hardcoded the values in the example)
| fn len(&self) -> usize { | ||
| // This is not correct because of the spacer items. Is `len` actually needed? | ||
| self.element.len() - self.ix | ||
| self.ix |
There was a problem hiding this comment.
Sure! I suspect that we'll probably just remove len, anyway; but this is more correct
There was a problem hiding this comment.
Yeah probably makes sense, doesn't seem to be needed anymore (I'll probably look into this more deeply, whether that is indeed the case).
There was a problem hiding this comment.
It's used in old xilem::view::List, so I guess we still need this, in case we don't exactly know the size of a ViewSequence in the view logic (e.g. lazy loading of items in a list, not sure currently whether that should happen in the xilem reactive layer?)
There was a problem hiding this comment.
I don't think its use in List is necessary, but I haven't remade the List ViewSequence yet, so I'm not certain
| pub fn label(label: impl Into<ArcStr>) -> Label { | ||
| Label { | ||
| label: label.into(), | ||
| text_color: Color::default(), |
There was a problem hiding this comment.
Hmm, Color implementing Default is weird - the default would surely depend on the use case?
There was a problem hiding this comment.
I can instead make it black (which seems to be the default) to be more clear. I agree, looking at it more closely, because default for the alpha value seems to be 0 (which I don't think is a good default). Maybe remove Default for peniko::Color alltogether (or make it explicitely black with opaque alpha)?
There was a problem hiding this comment.
Yeah, removing that Default is worth a PR, at worst to get a reason it should stay
There was a problem hiding this comment.
I've made it Color::BLACK for now in this PR.
There was a problem hiding this comment.
if we kept Default, this could just use functional record update syntax,
since label is the only non-default field. Agree about the alpha value.
Label {
label: label.into(),
..Default::default()
}
There was a problem hiding this comment.
I'm not sure I follow. Label: Default would not be a good API, because there's nearly no use for an empty label.
(Plus, I think that would allocate without need, which isn't great.)
There was a problem hiding this comment.
Of course, I just momentarily forgot functional record update syntax requires the structure itself to be Default not just the fields.
| self.ctx.request_layout(); | ||
| } | ||
|
|
||
| /// Set disabled |
There was a problem hiding this comment.
What does it even mean for a label to be disabled?
There was a problem hiding this comment.
I guess it makes more sense in combination with a checkbox. But basically, that it's not clickable in HTML jargon at least
There was a problem hiding this comment.
Right, so e.g. the contents can't be clicked and dragged? I guess it also would have consequences for the accessibility metadata
There was a problem hiding this comment.
Yeah I guess that is indeed the case.
DJMcNab
left a comment
There was a problem hiding this comment.
I still think we need some way to check the flex direction change works as expected.
Are you willing to add a Masonry level test for it? I've not dug into the test suite myself, so I'm not sure what that would involve.
If not, I think we can just merge this for expedience.
We do also need to add some xilem_masonry level tests. It would be awesome if you could get that started (although feel free to work on whichever features you want, of course)
| data.count = -1_000_000; | ||
| }), | ||
| )) | ||
| .direction(Axis::Horizontal), |
There was a problem hiding this comment.
Should we have a dynamically toggling axis in the same widget here?
There was a problem hiding this comment.
Not sure, it jumps around the layout, which I didn't find satisfying, but I added it for the +n buttons when data.active changes, which is less annoying.
…g on active state
I can look into that some time soon, but I think focus on "bling bling" right now seems more appropriate ? |
Probably 😆. It would be nice to have at least some tests we can point to, but I see your point As I say, merging-as-is is fine, although I've not run this myself |
I think I would do that, but for me locally a lot of the tests are failing, because I suspect a different font is chosen for me (new test snapshots are generated, with slightly different looking font), not sure currently how to force one specific font (I haven't looked into it, but I think it makes sense to include a font in the repo, and force it in the tests?) Anyway, it should be easy to add a test for the direction, but I'd rather merge this now and do that in different PR. |
|
Yeah, we can probably postpone tests until we figure out how to get a reliable font stack. Overall LGTM. |
Adds the label widget to
xilem_masonrywith some (but not all) attribute setters, and methods to disable the label in masonry.Also slightly extends the
Flexview, by being able to specify the direction (and a small fix inFlexSplice).