Skip to content

Commit

Permalink
Temporarily fix checkbox alignment
Browse files Browse the repository at this point in the history
Also tweaking/improving other examples as I test them
  • Loading branch information
ecton committed Nov 29, 2024
1 parent e93639a commit 21ef700
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
17 changes: 12 additions & 5 deletions examples/dynamic-fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use cushy::figures::units::Px;
use cushy::fonts::FontCollection;
use cushy::styles::components::{FontFamily, FontWeight, LineHeight, TextSize};
use cushy::styles::{Component, DynamicComponent, FamilyOwned, FontFamilyList};
use cushy::value::{Dynamic, Source};
use cushy::value::{Destination, Dynamic, Source};
use cushy::widget::MakeWidget;
use cushy::widgets::input::InputValue;
use cushy::window::DropEvent;
use cushy::Run;

fn main() -> cushy::Result<()> {
Expand Down Expand Up @@ -39,9 +40,8 @@ fn main() -> cushy::Result<()> {
Some(Component::FontWeight(face.weight))
});

let mut window = file_path
.into_input()
.validation(font_data.clone())
let mut window = "Path to font: (Dropping a font on this window also works)"
.and(file_path.to_input().validation(font_data.clone()))
.and(
"The quick brown fox jumps over the lazy dog."
.with(&TextSize, Px::new(36))
Expand All @@ -50,7 +50,14 @@ fn main() -> cushy::Result<()> {
.with_dynamic(&FontWeight, family_weight),
)
.into_rows()
.into_window();
.into_window()
.on_file_drop(move |event| {
if let DropEvent::Dropped(path) = event.drop {
if let Some(path) = path.to_str() {
file_path.set(path.to_string());
}
}
});
window.fonts = fonts;
window.run()
}
17 changes: 13 additions & 4 deletions examples/easings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::iter;

use cushy::animation::easings::StandardEasing;
use cushy::context::GraphicsContext;
use cushy::kludgine::shapes::{PathBuilder, Shape, StrokeOptions};
use cushy::widget::{MakeWidget, WidgetList};
use cushy::widgets::Canvas;
use cushy::widgets::{Canvas, Expand};
use cushy::Run;
use easing_function::Easing;
use figures::units::{Lp, Px};
Expand All @@ -26,9 +28,16 @@ fn main() -> cushy::Result {
.collect::<Vec<_>>()
.chunks(3)
.map(|widgets| {
WidgetList::from_iter(widgets.iter().map(|w| w.clone().expand()))
.into_columns()
.height(Lp::inches(3))
WidgetList::from_iter(
widgets
.iter()
.map(|w| w.clone().expand())
// Fill the last row with empty spaces
.chain(iter::repeat(Expand::empty()))
.take(3),
)
.into_columns()
.height(Lp::inches(3))
})
.collect::<WidgetList>()
.into_wrap()
Expand Down
19 changes: 14 additions & 5 deletions src/widgets/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use super::indicator::{Indicator, IndicatorBehavior, IndicatorState};
use crate::animation::{LinearInterpolate, ZeroToOne};
use crate::context::{GraphicsContext, LayoutContext, WidgetContext};
use crate::styles::components::{
CornerRadius, FocusColor, LineHeight, OutlineColor, OutlineWidth, TextColor, WidgetAccentColor,
WidgetBackground,
CornerRadius, FocusColor, LineHeight, OutlineColor, OutlineWidth, TextColor, VerticalAlignment,
WidgetAccentColor, WidgetBackground,
};
use crate::styles::{ColorExt, Dimension};
use crate::styles::{ColorExt, Dimension, VerticalAlign};
use crate::value::{Destination, Dynamic, DynamicReader, IntoDynamic, IntoValue, Source, Value};
use crate::widget::{MakeWidget, MakeWidgetWithTag, Widget, WidgetInstance};
use crate::widgets::button::ButtonKind;
Expand Down Expand Up @@ -82,7 +82,12 @@ impl MakeWidgetWithTag for Checkbox {
value: self.state.create_reader(),
};
let button_label = if let Some(label) = self.label {
adornment.and(label).into_columns().make_widget()
// TODO Set this to Baseline.
adornment
.and(label)
.into_columns()
.with(&VerticalAlignment, VerticalAlign::Center)
.make_widget()
} else {
adornment.make_widget()
};
Expand All @@ -105,7 +110,11 @@ impl MakeWidgetWithTag for Checkbox {
if let Some(label) = self.label {
indicator = indicator.labelled_by(label);
}
indicator.make_with_tag(id)
indicator
.make_with_tag(id)
// TODO Set this to Baseline.
.with(&VerticalAlignment, VerticalAlign::Center)
.make_widget()
}
}
}
Expand Down

0 comments on commit 21ef700

Please sign in to comment.