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

Introduce viewport widget #114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions crates/yakui-widgets/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod state;
mod text;
mod textbox;
mod unconstrained_box;
mod viewport;
mod window;

pub use self::align::*;
Expand Down Expand Up @@ -58,4 +59,5 @@ pub use self::state::*;
pub use self::text::*;
pub use self::textbox::*;
pub use self::unconstrained_box::*;
pub use self::viewport::*;
pub use self::window::*;
44 changes: 44 additions & 0 deletions crates/yakui-widgets/src/widgets/viewport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use yakui_core::{
geometry::{Constraints, FlexFit, Vec2},
widget::{LayoutContext, Widget},
Response,
};

/// Occupies the largest possible space, draws nothing, and consumes no inputs
///
/// Capture `Viewport.show().id`, then look it up in the final `LayoutDom` to find its
/// dimensions. Useful identifying a viewport for non-GUI rendering.
#[derive(Debug, Default)]
pub struct Viewport;

impl Viewport {
pub fn show(&self) -> Response<Self> {
crate::util::widget::<Self>(())
}
}

impl Widget for Viewport {
type Props = ();
type Response = ();

fn new() -> Self {
Self
}

fn update(&mut self, (): ()) {}

fn layout(&self, _: LayoutContext<'_>, constraints: Constraints) -> Vec2 {
constraints
.max
.as_ref()
.map(|x| match x.is_infinite() {
true => 0.0,
false => x,
})
.into()
}

fn flex(&self) -> (u32, FlexFit) {
(1, FlexFit::Tight)
}
}
Loading