Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

remove Env type and Data trait #53

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
24 changes: 12 additions & 12 deletions examples/blocking_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl MainWidget {
}

impl Widget for MainWidget {
fn on_event(&mut self, ctx: &mut EventCtx, event: &Event, env: &Env) {
fn on_event(&mut self, ctx: &mut EventCtx, event: &Event) {
match event {
Event::MouseDown(_) => {
if !ctx.is_disabled() {
Expand All @@ -62,7 +62,7 @@ impl Widget for MainWidget {
.expect("command failed to submit");
});

self.content.on_event(ctx, event, env);
self.content.on_event(ctx, event);
let mut flex_mut = ctx.get_mut(&mut self.content);
flex_mut.clear();
flex_mut.add_child(Spinner::new());
Expand All @@ -74,7 +74,7 @@ impl Widget for MainWidget {
Event::Command(cmd) if cmd.is(FINISH_SLOW_FUNCTION) => {
let value = *cmd.get(FINISH_SLOW_FUNCTION);

self.content.on_event(ctx, event, env);
self.content.on_event(ctx, event);

let mut flex_mut = ctx.get_mut(&mut self.content);
flex_mut.clear();
Expand All @@ -87,23 +87,23 @@ impl Widget for MainWidget {
}
_ => (),
}
self.content.on_event(ctx, event, env);
self.content.on_event(ctx, event);
}

fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange, _env: &Env) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}

fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, env: &Env) {
self.content.lifecycle(ctx, event, env);
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
self.content.lifecycle(ctx, event);
}

fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, env: &Env) -> Size {
let content_size = self.content.layout(ctx, bc, env);
ctx.place_child(&mut self.content, Point::ORIGIN, env);
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
let content_size = self.content.layout(ctx, bc);
ctx.place_child(&mut self.content, Point::ORIGIN);
content_size
}

fn paint(&mut self, ctx: &mut PaintCtx, env: &Env) {
self.content.paint(ctx, env);
fn paint(&mut self, ctx: &mut PaintCtx) {
self.content.paint(ctx);
}

fn children(&self) -> SmallVec<[WidgetRef<'_, dyn Widget>; 16]> {
Expand Down
23 changes: 11 additions & 12 deletions examples/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::Arc;

use masonry::widget::{Align, CrossAxisAlignment, Flex, Label, SizedBox, WidgetRef};
use masonry::{
Action, AppDelegate, AppLauncher, BoxConstraints, Color, Env, Event, EventCtx, LayoutCtx,
Action, AppDelegate, AppLauncher, BoxConstraints, Color, Event, EventCtx, LayoutCtx,
LifeCycle, LifeCycleCtx, PaintCtx, Point, Size, StatusChange, Widget, WidgetPod,
WindowDescription,
};
Expand Down Expand Up @@ -138,7 +138,7 @@ impl CalcButton {
}

impl Widget for CalcButton {
fn on_event(&mut self, ctx: &mut EventCtx, event: &Event, env: &Env) {
fn on_event(&mut self, ctx: &mut EventCtx, event: &Event) {
match event {
Event::MouseDown(_) => {
if !ctx.is_disabled() {
Expand All @@ -160,10 +160,10 @@ impl Widget for CalcButton {
}
_ => (),
}
self.inner.on_event(ctx, event, env);
self.inner.on_event(ctx, event);
}

fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange, _env: &Env) {
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
match event {
StatusChange::HotChanged(true) => {
ctx.get_mut(&mut self.inner).set_border(Color::WHITE, 3.0);
Expand All @@ -178,19 +178,19 @@ impl Widget for CalcButton {
}
}

fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, env: &Env) {
self.inner.lifecycle(ctx, event, env)
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
self.inner.lifecycle(ctx, event)
}

fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, env: &Env) -> Size {
let size = self.inner.layout(ctx, bc, env);
ctx.place_child(&mut self.inner, Point::ORIGIN, env);
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
let size = self.inner.layout(ctx, bc);
ctx.place_child(&mut self.inner, Point::ORIGIN);

size
}

fn paint(&mut self, ctx: &mut PaintCtx, env: &Env) {
self.inner.paint(ctx, env);
fn paint(&mut self, ctx: &mut PaintCtx) {
self.inner.paint(ctx);
}

fn children(&self) -> SmallVec<[WidgetRef<'_, dyn Widget>; 16]> {
Expand All @@ -209,7 +209,6 @@ impl AppDelegate for CalcState {
_window_id: masonry::WindowId,
_widget_id: masonry::WidgetId,
action: Action,
_env: &Env,
) {
match action {
Action::Other(payload) => match payload.downcast_ref::<CalcAction>().unwrap() {
Expand Down
14 changes: 7 additions & 7 deletions examples/custom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use masonry::piet::{FontFamily, ImageFormat, InterpolationMode, Text, TextLayout
use masonry::text::{FontDescriptor, TextLayout};
use masonry::widget::WidgetRef;
use masonry::{
Affine, AppLauncher, BoxConstraints, Color, Env, Event, EventCtx, LayoutCtx, LifeCycle,
Affine, AppLauncher, BoxConstraints, Color, Event, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, Point, Rect, RenderContext, Size, StatusChange, Widget,
WindowDescription,
};
Expand All @@ -26,13 +26,13 @@ struct CustomWidget(String);
// (and lifecycle) methods as well to make sure it works. Some things can be filtered,
// but a general rule is to just pass it through unless you really know you don't want it.
impl Widget for CustomWidget {
fn on_event(&mut self, _ctx: &mut EventCtx, _event: &Event, _env: &Env) {}
fn on_event(&mut self, _ctx: &mut EventCtx, _event: &Event) {}

fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle, _env: &Env) {}
fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle) {}

fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange, _env: &Env) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}

fn layout(&mut self, _layout_ctx: &mut LayoutCtx, bc: &BoxConstraints, _env: &Env) -> Size {
fn layout(&mut self, _layout_ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
// BoxConstraints are passed by the parent widget.
// This method can return any Size within those constraints:
// bc.constrain(my_size)
Expand All @@ -55,7 +55,7 @@ impl Widget for CustomWidget {
// The paint method gets called last, after an event flow.
// It goes event -> update -> layout -> paint, and each method can influence the next.
// Basically, anything that changes the appearance of a widget causes a paint.
fn paint(&mut self, ctx: &mut PaintCtx, env: &Env) {
fn paint(&mut self, ctx: &mut PaintCtx) {
// Clear the whole widget with the color of your choice
// (ctx.size() returns the size of the layout rect we're painting in)
// Note: ctx also has a `clear` method, but that clears the whole context,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Widget for CustomWidget {
let mut layout = TextLayout::<String>::from_text(&self.0);
layout.set_font(FontDescriptor::new(FontFamily::SERIF).with_size(24.0));
layout.set_text_color(fill_color);
layout.rebuild_if_needed(ctx.text(), env);
layout.rebuild_if_needed(ctx.text());

// Let's rotate our text slightly. First we save our current (default) context:
ctx.with_save(|ctx| {
Expand Down
1 change: 0 additions & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl AppDelegate for Delegate {
_window_id: WindowId,
_widget_id: WidgetId,
action: Action,
_env: &Env,
) {
if let Action::ButtonPressed = action {
println!("Hello");
Expand Down
18 changes: 9 additions & 9 deletions examples/promise_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use masonry::text::TextLayout;
use masonry::widget::prelude::*;
use masonry::widget::WidgetRef;
use masonry::{AppLauncher, WindowDescription};
use masonry::{ArcStr, Color, KeyOrValue, Point};
use masonry::{ArcStr, Color, Point};
use smallvec::SmallVec;
use tracing::{trace, trace_span, Span};

Expand All @@ -28,7 +28,7 @@ pub struct PromiseButton {
line_break_mode: LineBreaking,
promise_token: PromiseToken<u32>,

default_text_color: KeyOrValue<Color>,
default_text_color: Color,
}

/// Options for handling lines that are too wide for the label.
Expand Down Expand Up @@ -63,7 +63,7 @@ impl PromiseButton {
// --- TRAIT IMPLS ---

impl Widget for PromiseButton {
fn on_event(&mut self, ctx: &mut EventCtx, event: &Event, _env: &Env) {
fn on_event(&mut self, ctx: &mut EventCtx, event: &Event) {
match event {
Event::MouseUp(_event) => {
let value = self.value;
Expand Down Expand Up @@ -97,13 +97,13 @@ impl Widget for PromiseButton {
}
}

fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange, _env: &Env) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}

fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, _env: &Env) {
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
match event {
LifeCycle::DisabledChanged(disabled) => {
let color = if *disabled {
KeyOrValue::Key(masonry::theme::DISABLED_TEXT_COLOR)
masonry::theme::DISABLED_TEXT_COLOR
} else {
self.default_text_color.clone()
};
Expand All @@ -114,14 +114,14 @@ impl Widget for PromiseButton {
}
}

fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, env: &Env) -> Size {
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
let width = match self.line_break_mode {
LineBreaking::WordWrap => bc.max().width - LABEL_X_PADDING * 2.0,
_ => f64::INFINITY,
};

self.text_layout.set_wrap_width(width);
self.text_layout.rebuild_if_needed(ctx.text(), env);
self.text_layout.rebuild_if_needed(ctx.text());

let text_metrics = self.text_layout.layout_metrics();
ctx.set_baseline_offset(text_metrics.size.height - text_metrics.first_baseline);
Expand All @@ -133,7 +133,7 @@ impl Widget for PromiseButton {
size
}

fn paint(&mut self, ctx: &mut PaintCtx, _env: &Env) {
fn paint(&mut self, ctx: &mut PaintCtx) {
let origin = Point::new(LABEL_X_PADDING, 0.0);
let label_size = ctx.size();

Expand Down
1 change: 0 additions & 1 deletion examples/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl AppDelegate for Delegate {
_window_id: WindowId,
_widget_id: WidgetId,
action: Action,
_env: &Env,
) {
match action {
Action::ButtonPressed => {
Expand Down
3 changes: 1 addition & 2 deletions examples/to_do_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use masonry::widget::{
Button, CrossAxisAlignment, Flex, Label, Portal, SizedBox, TextBox, WidgetMut,
};
use masonry::{
Action, AppDelegate, AppLauncher, Color, DelegateCtx, Env, WidgetId, WindowDescription,
Action, AppDelegate, AppLauncher, Color, DelegateCtx, WidgetId, WindowDescription,
WindowId,
};

Expand All @@ -23,7 +23,6 @@ impl AppDelegate for Delegate {
_window_id: WindowId,
_widget_id: WidgetId,
action: Action,
_env: &Env,
) {
match action {
Action::ButtonPressed | Action::TextEntered(_) => {
Expand Down
10 changes: 4 additions & 6 deletions src/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::command::{Command, CommandQueue};
use crate::ext_event::{ExtEventQueue, ExtEventSink};
use crate::widget::{StoreInWidgetMut, WidgetMut, WidgetRef};
use crate::{
Env, Event, Handled, SingleUse, Target, Widget, WidgetId, WindowDescription, WindowId,
Event, Handled, SingleUse, Target, Widget, WidgetId, WindowDescription, WindowId,
WindowRoot,
};

Expand Down Expand Up @@ -82,7 +82,6 @@ pub trait AppDelegate {
ctx: &mut DelegateCtx,
window_id: WindowId,
event: &Event,
env: &Env,
) -> Handled {
#![allow(unused)]
Handled::No
Expand All @@ -92,7 +91,7 @@ pub trait AppDelegate {
///
/// This function receives all command events, before they are passed down
/// the tree. If it returns [`Handled::Yes`], commands are short-circuited.
fn on_command(&mut self, ctx: &mut DelegateCtx, cmd: &Command, env: &Env) -> Handled {
fn on_command(&mut self, ctx: &mut DelegateCtx, cmd: &Command) -> Handled {
#![allow(unused)]
Handled::No
}
Expand All @@ -106,7 +105,6 @@ pub trait AppDelegate {
window_id: WindowId,
widget_id: WidgetId,
action: Action,
env: &Env,
) {
#![allow(unused)]
}
Expand All @@ -115,14 +113,14 @@ pub trait AppDelegate {
///
/// This function is called after a window has been added,
/// allowing you to customize the window creation behavior of your app.
fn on_window_added(&mut self, ctx: &mut DelegateCtx, id: WindowId, env: &Env) {
fn on_window_added(&mut self, ctx: &mut DelegateCtx, id: WindowId) {
#![allow(unused)]
}

/// The handler for window deletion events.
///
/// This function is called after a window has been removed.
fn on_window_removed(&mut self, ctx: &mut DelegateCtx, id: WindowId, env: &Env) {
fn on_window_removed(&mut self, ctx: &mut DelegateCtx, id: WindowId) {
#![allow(unused)]
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/app_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::app_delegate::AppDelegate;
use crate::app_root::AppRoot;
use crate::ext_event::{ExtEventQueue, ExtEventSink};
use crate::platform::{MasonryAppHandler, WindowDescription};
use crate::Env;

/// Handles initial setup of an application, and starts the runloop.
pub struct AppLauncher {
Expand Down Expand Up @@ -88,7 +87,6 @@ impl AppLauncher {
self.windows,
self.app_delegate,
self.ext_event_queue,
Env::with_theme(),
)?;
let handler = MasonryAppHandler::new(state);

Expand Down
Loading
Loading