Skip to content

Commit

Permalink
LayoutContext
Browse files Browse the repository at this point in the history
measure() now is layout(). LayoutContext can either persist layout
information or be used temporarily for measurement. While this caching
is constantly thrown out currently, this is a step towards being able to
only re-layout widgets if they've been invalidated.
  • Loading branch information
ecton committed Nov 5, 2023
1 parent 6f5ffd8 commit 0f6d383
Show file tree
Hide file tree
Showing 26 changed files with 960 additions and 797 deletions.
4 changes: 2 additions & 2 deletions examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use gooey::animation::{AnimationHandle, AnimationTarget, IntoAnimate, Spawn};
use gooey::value::Dynamic;
use gooey::widgets::{Button, Label, Stack};
use gooey::{widgets, Run, WithClone};
use gooey::{children, Run, WithClone};

fn main() -> gooey::Result {
let animation = Dynamic::new(AnimationHandle::new());
Expand All @@ -17,7 +17,7 @@ fn main() -> gooey::Result {
.on_complete(|| println!("Gooey animations are neat!"))
.launch();

Stack::columns(widgets![
Stack::columns(children![
Button::new("To 0").on_click(animate_to(&animation, &value, 0)),
Label::new(label),
Button::new("To 100").on_click(animate_to(&animation, &value, 100)),
Expand Down
4 changes: 2 additions & 2 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::string::ToString;

use gooey::value::Dynamic;
use gooey::widgets::{Align, Button, Expand, Label, Resize, Stack};
use gooey::{widgets, Run};
use gooey::{children, Run};
use kludgine::figures::units::Lp;

fn main() -> gooey::Result {
let counter = Dynamic::new(0i32);
let label = counter.map_each(ToString::to_string);
Expand::new(Align::centered(Stack::columns(widgets![
Expand::new(Align::centered(Stack::columns(children![
Resize::width(Lp::points(100), Label::new(label)),
Button::new("+").on_click(counter.with_clone(|counter| {
move |_| {
Expand Down
42 changes: 24 additions & 18 deletions examples/gameui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gooey::children;
use gooey::value::Dynamic;
use gooey::widget::{HANDLED, IGNORED};
use gooey::widget::{MakeWidget, HANDLED, IGNORED};
use gooey::widgets::{Canvas, Expand, Input, Label, Scroll, Stack};
use gooey::{widgets, Run};
use kludgine::app::winit::event::ElementState;
use kludgine::app::winit::keyboard::Key;
use kludgine::figures::{Point, Rect};
Expand All @@ -12,9 +12,26 @@ fn main() -> gooey::Result {
let chat_log = Dynamic::new("Chat log goes here.\n".repeat(100));
let chat_message = Dynamic::new(String::new());

Expand::new(Stack::rows(widgets![
Expand::new(Stack::columns(widgets![
Expand::new(Scroll::vertical(Label::new(chat_log.clone()))),
let input = Input::new(chat_message.clone())
.on_key({
let chat_log = chat_log.clone();
move |input| match (input.state, input.logical_key) {
(ElementState::Pressed, Key::Enter) => {
let new_message = chat_message.map_mut(|text| std::mem::take(text));
chat_log.map_mut(|chat_log| {
chat_log.push_str(&new_message);
chat_log.push('\n');
});
HANDLED
}
_ => IGNORED,
}
})
.make_widget();

Expand::new(Stack::rows(children![
Expand::new(Stack::columns(children![
Expand::new(Scroll::vertical(Label::new(chat_log))),
Expand::weighted(
2,
Canvas::new(|context| {
Expand All @@ -28,19 +45,8 @@ fn main() -> gooey::Result {
})
)
])),
Input::new(chat_message.clone()).on_key(move |input| {
match (input.state, input.logical_key) {
(ElementState::Pressed, Key::Enter) => {
let new_message = chat_message.map_mut(|text| std::mem::take(text));
chat_log.map_mut(|chat_log| {
chat_log.push_str(&new_message);
chat_log.push('\n');
});
HANDLED
}
_ => IGNORED,
}
}),
input.clone(),
]))
.with_next_focus(input)
.run()
}
4 changes: 2 additions & 2 deletions examples/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use gooey::styles::components::TextColor;
use gooey::styles::Styles;
use gooey::widget::{Widget, Widgets};
use gooey::widget::{Children, MakeWidget, Widget};
use gooey::widgets::stack::Stack;
use gooey::widgets::{Button, Style};
use gooey::window::Window;
Expand All @@ -10,7 +10,7 @@ use kludgine::Color;
fn main() -> gooey::Result {
Window::for_widget(
Stack::rows(
Widgets::new()
Children::new()
.with_widget(Button::new("Default"))
.with_widget(red_text(Button::new("Styled"))),
)
Expand Down
Loading

0 comments on commit 0f6d383

Please sign in to comment.