Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd UiButton and UiButtonBuilder #613
Conversation
jojolepro
requested changes
Mar 29, 2018
Consider adding a "ToEntities" trait which can be re-used between ui components to get a Vec from a UiButton or UiComponentName.
Most of it looks good though :)
| + /// Construct a new UiButtonBuilder. | ||
| + /// This allows easy use of default values for text and button appearance and allows the user | ||
| + /// to easily set other UI-related options. | ||
| + pub fn new(name: &'a str, world: &'b mut World) -> Self { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| + ); | ||
| + let text = UiText::new(font, "".to_string(), [0.0, 0.0, 0.0, 1.0], 32.0); | ||
| + let grey = loader.load_from_data( | ||
| + [0.82, 0.83, 0.83, 1.0].into(), |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Mar 29, 2018
Contributor
Review status: 0 of 11 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.
amethyst_ui/src/button.rs, line 33 at r1 (raw file):
Previously, jojolepro (Joël Lupien) wrote…
I think that having the text is an essential parameter here.
Will do
amethyst_ui/src/button.rs, line 46 at r1 (raw file):
Previously, jojolepro (Joël Lupien) wrote…
Why the 0.82 and 0.83?
That was just a RGB color I found that is light gray
Comments from Reviewable
|
Review status: 0 of 11 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. amethyst_ui/src/button.rs, line 33 at r1 (raw file): Previously, jojolepro (Joël Lupien) wrote…
Will do amethyst_ui/src/button.rs, line 46 at r1 (raw file): Previously, jojolepro (Joël Lupien) wrote…
That was just a RGB color I found that is light gray Comments from Reviewable |
| +use specs::Entity; | ||
| +/// Ui elements will define this trait to allow easier addition to other | ||
| +/// elements and to the world. | ||
| +pub trait ToEntities { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Mar 29, 2018
Collaborator
That's good, but I also just realized that there's the Into<Vec> trait that could be implemented directly on the components. I'm not sure which one is preferable.
jojolepro
Mar 29, 2018
Collaborator
That's good, but I also just realized that there's the Into<Vec> trait that could be implemented directly on the components. I'm not sure which one is preferable.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Mar 29, 2018
Contributor
I'm not sure either. I think I'm leaning more towards "ToEntities" because it feels more explicit in its usage. Into might be more flexible though, and it is standard. I'll defer that to the group.
Hittherhod
Mar 29, 2018
Contributor
I'm not sure either. I think I'm leaning more towards "ToEntities" because it feels more explicit in its usage. Into might be more flexible though, and it is standard. I'll defer that to the group.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Mar 29, 2018
Contributor
It isn't used. @jojolepro said it might be nice to have a trait to deconstruct Ui elements into their constituent entities so I added it in after the initial request. In the UI example we don't do anything to the button, so this trait isn't currently used.
Hittherhod
Mar 29, 2018
Contributor
It isn't used. @jojolepro said it might be nice to have a trait to deconstruct Ui elements into their constituent entities so I added it in after the initial request. In the UI example we don't do anything to the button, so this trait isn't currently used.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
torkleyy
Mar 30, 2018
Member
@jojolepro Why exactly do you think such an ToEntities trait is useful?
|
@jojolepro Why exactly do you think such an |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Mar 30, 2018
Collaborator
When you have multiple menu and want to change between them, you need to remove the first menu before adding the second. (maybe the multiple World idea was good, after all). To easily do so, you can create all your ui inside a vec like so
fn create_ui(....) -> Vec<Entity>{
vec![
UiButton::new(.......).to_entities(),
...
]
}
fn change_menu(){
for e in old_entities{
entities.delete(e);
}
}
|
When you have multiple menu and want to change between them, you need to remove the first menu before adding the second. (maybe the multiple World idea was good, after all). To easily do so, you can create all your ui inside a vec like so
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
If they all have one ui node as parent, wouldn't that be better? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Mar 30, 2018
Collaborator
Technically I think there will always be a root entity and the rest as childs, so it could return only a single entity.
|
Technically I think there will always be a root entity and the rest as childs, so it could return only a single entity. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Could you walk the tree to get all the entities you want? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
If not, that functionality should be added. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Mar 30, 2018
Collaborator
We can't really walk from parent to child without iterating over all entities.
|
We can't really walk from parent to child without iterating over all entities. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Mar 31, 2018
Contributor
Would you already know a fairly local parent (like, say, the menu) that you could use as the root of your search?
|
Would you already know a fairly local parent (like, say, the menu) that you could use as the root of your search? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Mar 31, 2018
Collaborator
Well actually, you just made me realize we could use a "root" ui entity to delete a menu all at once.
When you delete an entity, all the childs are deleted automatically by the parent/layout system, so I would guess that by using UiButton::new(...).with_parent(root_menu) and then deleting the root_menu entity, the problem is fixed, and we don't need the ToEntities trait.
|
Well actually, you just made me realize we could use a "root" ui entity to delete a menu all at once. When you delete an entity, all the childs are deleted automatically by the parent/layout system, so I would guess that by using UiButton::new(...).with_parent(root_menu) and then deleting the root_menu entity, the problem is fixed, and we don't need the ToEntities trait. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Okay. I'll delete the |
| + /// Construct a new UiButtonBuilder. | ||
| + /// This allows easy use of default values for text and button appearance and allows the user | ||
| + /// to easily set other UI-related options. | ||
| + pub fn new<S: ToString>(name: &'a str, text: S, world: &'b mut World) -> Self { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| + }) | ||
| + .with_anchored(Anchored::new(Anchor::TopMiddle)) | ||
| + .with_parent(Parent { | ||
| + entity: background.clone(), | ||
| }) | ||
| .build(); | ||
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Mar 31, 2018
Collaborator
Could you add another button showing a less heavy syntax?
e.g: UiButtonBuilder::new("btn2", "Simple Button").with_font(font.clone()).with_position(50.0,50.0).build(&mut world);
jojolepro
Mar 31, 2018
Collaborator
Could you add another button showing a less heavy syntax?
e.g: UiButtonBuilder::new("btn2", "Simple Button").with_font(font.clone()).with_position(50.0,50.0).build(&mut world);
Rhuagh
reviewed
Mar 31, 2018
Passing world to build instead of new, and adding a build method for LazyUpdate aswell as one for World would be good. And make the new() function take only the resources it needs rather than World (Loader, AssetStorage, AssetStorage)
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Rhuagh
Mar 31, 2018
Member
Basically, my concern is that we should make it possible to use the builder without access to the full world (for creation from inside systems)
|
Basically, my concern is that we should make it possible to use the builder without access to the full world (for creation from inside systems) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 2, 2018
Contributor
@Rhuagh Could you explain more about LazyUpdate? I've never seen it in use, so I'm not sure how to work with it.
|
@Rhuagh Could you explain more about LazyUpdate? I've never seen it in use, so I'm not sure how to work with it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
There's an example |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 2, 2018
Contributor
Review status: 0 of 12 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.
amethyst_ui/src/button.rs, line 33 at r4 (raw file):
Previously, torkleyy (Thomas Schaller) wrote…
Can we pass the
Worldtobuildinstead ofnew?
Done.
examples/ui/main.rs, line 203 at r4 (raw file):
Previously, jojolepro (Joël Lupien) wrote…
Could you add another button showing a less heavy syntax?
e.g: UiButtonBuilder::new("btn2", "Simple Button").with_font(font.clone()).with_position(50.0,50.0).build(&mut world);
Done.
Comments from Reviewable
|
Review status: 0 of 12 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. amethyst_ui/src/button.rs, line 33 at r4 (raw file): Previously, torkleyy (Thomas Schaller) wrote…
Done. examples/ui/main.rs, line 203 at r4 (raw file): Previously, jojolepro (Joël Lupien) wrote…
Done. Comments from Reviewable |
| +const DEFAULT_TXT_COLOR: [f32; 4] = [0.0, 0.0, 0.0, 1.0]; | ||
| +const DEFAULT_FONT_NAME: &'static str = "font/square.ttf"; | ||
| + | ||
| +/// Container that wraps the resources we need to initialize button defaults |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| @@ -27,4 +27,4 @@ shrev = "0.8.1" | ||
| specs = "0.10" | ||
| unicode-normalization = "0.1" | ||
| unicode-segmentation = "1.2" | ||
| -winit = "0.10" | ||
| +winit = "0.11" |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| @@ -22,17 +22,19 @@ extern crate unicode_segmentation; | ||
| extern crate winit; |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 2, 2018
Contributor
Done. I needed to add shred as well to make the compiler be quiet.
Hittherhod
Apr 2, 2018
Contributor
Done. I needed to add shred as well to make the compiler be quiet.
| +impl <'a> UiButtonResources<'a> { | ||
| + /// Grab the resources we need from the world. | ||
| + pub fn from_world(world: &World) -> UiButtonResources { | ||
| + UiButtonResources { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| + } | ||
| + | ||
| + /// Create the UiButton based on provided configuration parameters. | ||
| + pub fn build(mut self, world: &mut World) -> UiButton { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Rhuagh
Apr 2, 2018
Member
Make another of the "Resources" structs, that contain the storages required for creating a button (WriteStorage<'a, UiImage> etc), and make the build function take that resources struct. Make the resources struct contain Entities<'a> so you can create entities.
Rhuagh
Apr 2, 2018
Member
Make another of the "Resources" structs, that contain the storages required for creating a button (WriteStorage<'a, UiImage> etc), and make the build function take that resources struct. Make the resources struct contain Entities<'a> so you can create entities.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 2, 2018
Contributor
How do I create replicate the current World centric functionality with Storages and Entities? Does this new Resources struct also need to derive SystemData?
Hittherhod
Apr 2, 2018
Contributor
How do I create replicate the current World centric functionality with Storages and Entities? Does this new Resources struct also need to derive SystemData?
| +const DEFAULT_TXT_COLOR: [f32; 4] = [0.0, 0.0, 0.0, 1.0]; | ||
| +const DEFAULT_FONT_NAME: &'static str = "font/square.ttf"; | ||
| + | ||
| +/// Container that wraps the resources we need to initialize button defaults |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| + } | ||
| + | ||
| + /// Create the UiButton based on provided configuration parameters. | ||
| + pub fn build(mut self, world: &mut World) -> UiButton { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 2, 2018
Contributor
How do I create replicate the current World centric functionality with Storages and Entities? Does this new Resources struct also need to derive SystemData?
Hittherhod
Apr 2, 2018
Contributor
How do I create replicate the current World centric functionality with Storages and Entities? Does this new Resources struct also need to derive SystemData?
| @@ -22,17 +22,19 @@ extern crate unicode_segmentation; | ||
| extern crate winit; |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 2, 2018
Contributor
Done. I needed to add shred as well to make the compiler be quiet.
Hittherhod
Apr 2, 2018
Contributor
Done. I needed to add shred as well to make the compiler be quiet.
jojolepro
referenced this pull request
Apr 3, 2018
Merged
Update winit, glutin and gfx_window_glutin. #620
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 4, 2018
Contributor
@Rhuagh I've added changes to use the WriteStorage resources structure. How would this work with a LazyUpdate?
|
@Rhuagh I've added changes to use the WriteStorage resources structure. How would this work with a LazyUpdate? |
| + /// Create the UiButton based on provided configuration parameters. | ||
| + pub fn build_from_world(self, world: &World) -> UiButton { | ||
| + self.build(UiButtonBuilderResources::from_world(world)) | ||
| + } | ||
| /// Lazily build the UiButton. Need to call `World::maintain` to have the values actually added. | ||
| pub fn lazy_build(mut self, res: UiButtonLazyResources) -> UiButton { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Rhuagh
Apr 5, 2018
Member
You can remove this, it's no longer needed, and LazyUpdate might disappear soon (or atleast be redesigned since), since it has issues.
Rhuagh
Apr 5, 2018
Member
You can remove this, it's no longer needed, and LazyUpdate might disappear soon (or atleast be redesigned since), since it has issues.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 7, 2018
Contributor
@Rhuagh Any feedback on the changes? I've removed the LazyUpdate structure. I want to add an example of having the button text update if you click on the button, but my click events aren't registering (the "you clicked on this element" isn't getting printed). @jojolepro Could this be another Mac specific issue?
|
@Rhuagh Any feedback on the changes? I've removed the LazyUpdate structure. I want to add an example of having the button text update if you click on the button, but my click events aren't registering (the "you clicked on this element" isn't getting printed). @jojolepro Could this be another Mac specific issue? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Apr 7, 2018
Collaborator
@Hittherhod You are not adding the MouseReactive component to the button's image.
You are not reading the UiEvents either.
|
@Hittherhod You are not adding the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 7, 2018
Contributor
Where do I read the UiEvents? I was trying to modify the UiEventHandlerSystem in main.rs, but it's not pushed because I didn't want to add a broken commit.
|
Where do I read the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Apr 7, 2018
Collaborator
Actually, the example is in fact reading for events :P my bad
https://github.com/jojolepro/amethyst/blob/develop/examples/ui/main.rs#L295
You are still missing MouseReactive tho
|
Actually, the example is in fact reading for events :P my bad You are still missing MouseReactive tho |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 7, 2018
Contributor
So, I added the MouseReactive and I see HoverStart and HoverStop events, but I'm not seeing click events.
|
So, I added the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
I see the clicks |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 7, 2018
Contributor
Okay. I'll refrain from adding that because I can't test it, but it'd be a nice to have for another PR.
|
Okay. I'll refrain from adding that because I can't test it, but it'd be a nice to have for another PR. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
We're waiting for a bugfix in winit that triggers the retina bugs. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Rhuagh
Apr 10, 2018
Member
Theres a compile issue in amethyst_input/src/local_virtual_key_code.rs:157:5, Caret is defined twice, which cause compilation to fail.
|
Theres a compile issue in amethyst_input/src/local_virtual_key_code.rs:157:5, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 10, 2018
Contributor
@Rhuagh Fixed it. Something weird happened with rebasing on upstream and Caret was defined at the end of the KeyCodes section as well as in the correct alphabetical ordering. I tried to keep things current throughout the pull request, but I think next time I'll just do a final one at the end.
|
@Rhuagh Fixed it. Something weird happened with rebasing on upstream and Caret was defined at the end of the KeyCodes section as well as in the correct alphabetical ordering. I tried to keep things current throughout the pull request, but I think next time I'll just do a final one at the end. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
torkleyy
Apr 10, 2018
Member
Doesn't seem to be fixed really. Could you also try to clean up the commit history?
|
Doesn't seem to be fixed really. Could you also try to clean up the commit history? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Ah the build is just failing because of Travis. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 10, 2018
Contributor
|
Sure. I’ll try to squash things to just include the major fixes.
…On Tue, Apr 10, 2018 at 7:43 AM Thomas Schaller ***@***.***> wrote:
Ah the build is just failing because of Travis.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#613 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABVdnk890ayzXv6CtmZgpJ6NI7wZCqGVks5tnJrpgaJpZM4TAc6d>
.
|
and others
added some commits
Mar 6, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Hittherhod
Apr 11, 2018
Contributor
@Rhuagh I tried to clean it up so that it only reports the significant updates rather than every little change.
|
@Rhuagh I tried to clean it up so that it only reports the significant updates rather than every little change. |
| + | ||
| +/// Container for all the resources the builder needs to make a new UiButton. | ||
| +#[derive(SystemData)] | ||
| +struct UiButtonBuilderResources<'a> { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Apr 11, 2018
Collaborator
Resources is a confusing name, could you use something like "parameters"?
jojolepro
Apr 11, 2018
Collaborator
Resources is a confusing name, could you use something like "parameters"?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Apr 11, 2018
Collaborator
I do not know how to remove a message from my phone, ignore this.
jojolepro
Apr 11, 2018
Collaborator
I do not know how to remove a message from my phone, ignore this.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Looks good to me :) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Is there some way to make this merge? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Xaeroxe
Apr 13, 2018
Member
@jojolepro @Rhuagh @torkleyy Since you've all marked this as approved can one of you 3 r+ this? I'm hesitant to do so myself as I haven't reviewed it yet but if there are any pending change requests can we change the review status to reflect that?
|
@jojolepro @Rhuagh @torkleyy Since you've all marked this as approved can one of you 3 r+ this? I'm hesitant to do so myself as I haven't reviewed it yet but if there are any pending change requests can we change the review status to reflect that? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
bors r=torkleyy,Rhuagh |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
|
Rhuagh
added
status: ready
and removed
status: working
labels
Apr 13, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
bors r=torkleyy,Rhuagh |
bot
added a commit
that referenced
this pull request
Apr 13, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
bot
merged commit 8a7e9b9
into
amethyst:develop
Apr 13, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Congratz! |


Hittherhod commentedMar 29, 2018
•
edited by torkleyy
Edited 1 time
-
torkleyy
edited Mar 29, 2018 (most recent)
It's not showing up properly on my Mac, but I'd like to get a chance to iterate over the API and defaults.
This change is