-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wired up some more existing masonry flex properties so they can be set on the flex view. I was messing around with a dummy example to try out the v0.1 and noticed I couldn't easily center something because flex was only exposing direction not alignment/cross-alignment. It looked like all the logic already exists in masonry so it was just a matter of wiring it up. This is my first contribution so sorry if I missed some steps. Sidenote: I didn't see any examples of testing that a view updates the underlying element so I am guessing that is still tbd. If someone has a suggestion for a good way to do that I am happy to try it out. I'm also not sure what the etiquette is on adding/editing examples so I just included the example I was using to verify it worked but no stress if you want to remove it.
- Loading branch information
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2024 the Xilem Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use masonry::widget::{CrossAxisAlignment, MainAxisAlignment}; | ||
use winit::error::EventLoopError; | ||
use xilem::{ | ||
view::{button, flex, label}, | ||
MasonryView, Xilem, | ||
}; | ||
|
||
fn app_logic(data: &mut i32) -> impl MasonryView<i32> { | ||
flex(( | ||
button("-", |data| { | ||
*data -= 1; | ||
}), | ||
label(format!("count: {}", data)), | ||
button("+", |data| { | ||
*data += 1; | ||
}), | ||
)) | ||
.direction(xilem::Axis::Horizontal) | ||
.cross_axis_alignment(CrossAxisAlignment::Center) | ||
.main_axis_alignment(MainAxisAlignment::Center) | ||
} | ||
|
||
fn main() -> Result<(), EventLoopError> { | ||
let app = Xilem::new(0, app_logic); | ||
app.run_windowed("Centered Flex".into())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters