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 Board widget for absolute positioning #591

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 116 additions & 117 deletions masonry/src/widget/board.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion masonry/src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod widget_arena;

pub use self::image::Image;
pub use align::Align;
pub use board::{Board, BoardParams, KurboShape, Shape};
pub use board::{Board, BoardParams, ConcreteShape, KurboShape};
pub use button::Button;
pub use checkbox::Checkbox;
pub use flex::{Axis, CrossAxisAlignment, Flex, FlexParams, MainAxisAlignment};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions masonry/src/widget/widget_pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ impl<W: Widget> WidgetPod<W> {
pub fn id(&self) -> WidgetId {
self.id
}

/// Take the inner widget, if it has not been inserted yet.
pub fn inner(self) -> Option<W> {
if let WidgetPodInner::Created(w) = self.inner {
Some(w)
} else {
None
}
}

/// Get access to the inner widget, if it has not been inserted yet.
pub fn as_ref(&self) -> Option<&W> {
if let WidgetPodInner::Created(w) = &self.inner {
Some(w)
} else {
None
}
}

/// Get access to the inner widget, if it has not been inserted yet.
pub fn as_mut(&mut self) -> Option<&mut W> {
if let WidgetPodInner::Created(w) = &mut self.inner {
Some(w)
} else {
None
}
}
}

impl<W: Widget + 'static> WidgetPod<W> {
Expand Down
2 changes: 1 addition & 1 deletion xilem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ crate-type = ["cdylib"]
workspace = true

[dependencies]
xilem_core.workspace = true
xilem_core = { workspace = true, features = ["kurbo"] }
masonry.workspace = true
winit.workspace = true
tracing.workspace = true
Expand Down
8 changes: 3 additions & 5 deletions xilem/examples/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use masonry::{
};
use winit::error::EventLoopError;
use xilem::view::{
board, button, flex, label, Axis, BoardExt, BoardParams, FlexExt as _, FlexSpacer, ShapeExt,
board, button, flex, label, Axis, BoardExt, BoardParams, FlexExt as _, FlexSpacer, GraphicsExt,
};
use xilem::{Color, EventLoop, WidgetView, Xilem};

Expand Down Expand Up @@ -50,10 +50,8 @@ impl AppState {
.into_any_board()
} else {
vello::kurbo::Circle::new((origin + 15., origin + 15.), 15.)
.view()
.fill_brush(Color::NAVY)
.stroke_brush(Color::PAPAYA_WHIP)
.stroke_style(vello::kurbo::Stroke::new(2.))
.fill(Color::NAVY)
.stroke(Color::PAPAYA_WHIP, vello::kurbo::Stroke::new(2.))
.into_any_board()
}
})
Expand Down
Loading
Loading