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

Fix/bugs #644

Merged
merged 4 commits into from
Oct 29, 2024
Merged
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
- **core**: Nodes created by a class implementation may not be disposed of when switching to another class. (#637 @M-Adoo)
- **core**: When merge multiple `MixBuiltin` widgets, there may be a premature dropping of the outer `MixBuiltin` before it should occur. (#639 @M-Adoo)
- **core**: `watch!` does not notify the initial value. (#640 @M-Adoo)

- **core**: fix watch multi builtin events not work (#641 @wjian23)

- **core**: fix widget layout when h_algin and v_align are embedded in each other (#641 @wjian23)
- **painter**: fix elements may not be painted after window resize. (#644 @M-Adoo)

### Breaking

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ quote = "1.0.16"
rayon = "1.5.1"
rctree = "0.5.0"
rustybuzz = "0.11.0"
rxrust = { version="1.0.0-beta.8", default-features = false, features = ["futures-scheduler"]}
rxrust = { version="1.0.0-beta.9", default-features = false, features = ["futures-scheduler"]}
scoped_threadpool = "0.1.9"
triomphe = "0.1.12"
serde = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions core/src/builtin_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct FatObj<T> {
host: T,
host_id: LazyWidgetId,
id: LazyWidgetId,
class: Option<State<Class>>,
padding: Option<State<Padding>>,
fitted_box: Option<State<FittedBox>>,
constrained_box: Option<State<ConstrainedBox>>,
Expand All @@ -124,7 +125,6 @@ pub struct FatObj<T> {
transform: Option<State<TransformWidget>>,
opacity: Option<State<Opacity>>,
visibility: Option<State<Visibility>>,
class: Option<State<Class>>,
h_align: Option<State<HAlignWidget>>,
v_align: Option<State<VAlignWidget>>,
relative_anchor: Option<State<RelativeAnchor>>,
Expand Down Expand Up @@ -175,6 +175,7 @@ impl<T> FatObj<T> {
host: f(self.host),
host_id: self.host_id,
id: self.id,
class: self.class,
mix_builtin: self.mix_builtin,
request_focus: self.request_focus,
fitted_box: self.fitted_box,
Expand All @@ -191,7 +192,6 @@ impl<T> FatObj<T> {
v_align: self.v_align,
relative_anchor: self.relative_anchor,
global_anchor: self.global_anchor,
class: self.class,
painting_style: self.painting_style,
text_style: self.text_style,
visibility: self.visibility,
Expand Down Expand Up @@ -929,6 +929,7 @@ impl<'a> FatObj<Widget<'a>> {
compose_builtin_widgets!(
host
+ [
class,
padding,
fitted_box,
constrained_box,
Expand All @@ -943,7 +944,6 @@ impl<'a> FatObj<Widget<'a>> {
transform,
opacity,
visibility,
class,
h_align,
v_align,
relative_anchor,
Expand Down
24 changes: 17 additions & 7 deletions macros/src/distinct_pipe_macro.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
use proc_macro2::TokenStream;
use quote::quote;
use quote::quote_spanned;
use syn::spanned::Spanned;

use crate::{pipe_macro, symbol_process::DollarRefsCtx};
use crate::{
error::result_to_token_stream, symbol_process::DollarRefsCtx, watch_macro::process_watch_body,
};

pub fn gen_code(input: TokenStream, refs_ctx: &mut DollarRefsCtx) -> proc_macro::TokenStream {
let mut tokens = pipe_macro::gen_code(input, refs_ctx);
tokens.extend(quote! {
.value_chain(|s| s.distinct_until_changed().box_it())
pub fn gen_code(input: TokenStream, refs_ctx: &mut DollarRefsCtx) -> TokenStream {
let span = input.span();
let res = process_watch_body(input, refs_ctx).map(|(upstream, map_handler)| {
quote_spanned! {span =>
MapPipe::new(
ModifiesPipe::new(#upstream.box_it()),
#map_handler
)
// Since the pipe has an initial value, we skip the initial notification.
.value_chain(|s| s.distinct_until_key_changed(|v: &(_, _)| v.1).skip(1).box_it())
}
});
tokens.into()
result_to_token_stream(res)
}
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn style_class(input: TokenStream) -> TokenStream {
/// changes made to it.
#[proc_macro]
pub fn distinct_pipe(input: TokenStream) -> TokenStream {
distinct_pipe_macro::gen_code(input.into(), &mut DollarRefsCtx::top_level())
distinct_pipe_macro::gen_code(input.into(), &mut DollarRefsCtx::top_level()).into()
}

/// The `watch!` macro converts an expression into an `Observable` stream. Use
Expand Down
52 changes: 30 additions & 22 deletions macros/src/part_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct PartWriter {
writer: Ident,
dot: Token![.],
part_expr: PartExpr,
tail_dot: Option<Token![.]>,
tail_expr: Option<Expr>,
}

enum PartExpr {
Expand All @@ -46,31 +48,35 @@ impl Parse for PartWriter {
fn parse(input: ParseStream) -> Result<Self> {
let and_token = input.parse()?;
let mutability = input.parse()?;
let writer = input.parse()?;
let writer = if input.peek(Token![self]) {
let this = input.parse::<Token![self]>()?;
Ident::from(this)
} else {
input.parse()?
};
let dot = input.parse()?;

let part_expr = if input.peek(syn::LitInt) {
PartExpr::Member(input.parse()?)
} else {
let name = input.parse::<Ident>()?;
if input.is_empty() {
PartExpr::Member(Member::Named(name))
let part_expr = if input.peek2(Token![::]) || input.peek2(Paren) {
let method = input.parse()?;
let turbofish = if input.peek(Token![::]) {
Some(AngleBracketedGenericArguments::parse_turbofish(input)?)
} else {
let turbofish = if input.peek(Token![::]) {
Some(AngleBracketedGenericArguments::parse_turbofish(input)?)
} else {
None
};
let content;
PartExpr::Method {
method: name,
turbofish,
paren_token: parenthesized!(content in input),
args: content.parse_terminated(Expr::parse, Token![,])?,
}
None
};
let content;
PartExpr::Method {
method,
turbofish,
paren_token: parenthesized!(content in input),
args: content.parse_terminated(Expr::parse, Token![,])?,
}
} else {
PartExpr::Member(input.parse()?)
};
Ok(Self { and_token, mutability, writer, dot, part_expr })

let tail_dot = input.parse()?;
let tail_expr = if input.is_empty() { None } else { Some(input.parse()?) };
Ok(Self { and_token, mutability, writer, dot, part_expr, tail_dot, tail_expr })
}
}

Expand All @@ -93,7 +99,7 @@ impl PartWriter {
}

fn gen_tokens(&self, writer_info: &DollarRef, refs_ctx: &DollarRefsCtx) -> TokenStream {
let Self { and_token, mutability, writer, dot, part_expr } = self;
let Self { and_token, mutability, writer, dot, part_expr, tail_dot, tail_expr } = self;
let part_expr = match part_expr {
PartExpr::Member(member) => member.to_token_stream(),
PartExpr::Method { method, turbofish, paren_token, args } => {
Expand All @@ -111,7 +117,9 @@ impl PartWriter {
};

quote_spanned! { writer.span() =>
#host #dot map_writer(|w| PartData::from_ref_mut(#and_token #mutability w #dot #part_expr))
#host #dot map_writer(
|w| PartData::from_ref_mut(#and_token #mutability w #dot #part_expr #tail_dot #tail_expr)
)
}
}
}
2 changes: 1 addition & 1 deletion macros/src/symbol_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl Fold for DollarRefsCtx {
mac.tokens = crate::pipe_macro::gen_code(mac.tokens, self);
mark_macro_expanded(&mut mac);
} else if mac.path.is_ident(KW_DISTINCT_PIPE) {
mac.tokens = crate::distinct_pipe_macro::gen_code(mac.tokens, self).into();
mac.tokens = crate::distinct_pipe_macro::gen_code(mac.tokens, self);
mark_macro_expanded(&mut mac);
} else if mac.path.is_ident(KW_RDL) {
self.mark_used_ctx();
Expand Down
6 changes: 2 additions & 4 deletions painter/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{
/// X-axis values progress toward the right edge of the canvas, while Y-axis
/// values increase towards the bottom edge of the canvas.
pub struct Painter {
viewport: Rect,
init_state: PainterState,
state_stack: Vec<PainterState>,
commands: Vec<PaintCommand>,
Expand Down Expand Up @@ -178,7 +177,6 @@ impl Painter {
init_state,
commands: vec![],
path_builder: Path::builder(),
viewport,
}
}

Expand All @@ -191,11 +189,11 @@ impl Painter {
self.reset();
}

pub fn viewport(&self) -> &Rect { &self.viewport }
pub fn viewport(&self) -> &Rect { &self.init_state.bounds }

/// Change the bounds of the painter can draw.But it won't take effect until
/// the next time you call [`Painter::reset`]!.
pub fn set_viewport(&mut self, bounds: Rect) { self.viewport = bounds; }
pub fn set_viewport(&mut self, bounds: Rect) { self.init_state.bounds = bounds; }

pub fn intersection_paint_bounds(&self, rect: &Rect) -> Option<Rect> {
self.paint_bounds().intersection(rect)
Expand Down
Loading