mirror of
https://github.com/danbulant/cushy
synced 2026-06-20 06:51:07 +00:00
While this was a workaround for a docs.rs issue (Px/Lp are not linked), I decided having the shorter import path would look better in the examples. It probably wasn't necessary to update all of the references in the internal code, but I decided it was worth the consistency.
53 lines
1.2 KiB
Rust
53 lines
1.2 KiB
Rust
use figures::units::UPx;
|
|
use figures::Size;
|
|
use kludgine::Color;
|
|
|
|
use crate::context::{GraphicsContext, LayoutContext};
|
|
use crate::value::{IntoValue, Value};
|
|
use crate::widget::Widget;
|
|
use crate::ConstraintLimit;
|
|
|
|
/// A widget that occupies space, optionally filling it with a color.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Space {
|
|
color: Value<Color>,
|
|
}
|
|
|
|
impl Default for Space {
|
|
fn default() -> Self {
|
|
Self::clear()
|
|
}
|
|
}
|
|
|
|
impl Space {
|
|
/// Returns a widget that draws nothing.
|
|
#[must_use]
|
|
pub const fn clear() -> Self {
|
|
Self {
|
|
color: Value::Constant(Color::CLEAR_BLACK),
|
|
}
|
|
}
|
|
|
|
/// Returns a widget that fills its space with `color`.
|
|
#[must_use]
|
|
pub fn colored(color: impl IntoValue<Color>) -> Self {
|
|
Self {
|
|
color: color.into_value(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Widget for Space {
|
|
fn redraw(&mut self, context: &mut GraphicsContext<'_, '_, '_, '_, '_>) {
|
|
let color = self.color.get_tracking_redraw(context);
|
|
context.fill(color);
|
|
}
|
|
|
|
fn layout(
|
|
&mut self,
|
|
_available_space: Size<ConstraintLimit>,
|
|
_context: &mut LayoutContext<'_, '_, '_, '_, '_>,
|
|
) -> Size<UPx> {
|
|
Size::default()
|
|
}
|
|
}
|