Skip to content

Commit

Permalink
xilem: replace Into<Label> with impl<T> From<T> for Label where T: In…
Browse files Browse the repository at this point in the history
…to<ArcStr>
  • Loading branch information
Artyom Sinyugin committed Dec 19, 2024
1 parent 46bc44d commit 406641d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
20 changes: 11 additions & 9 deletions xilem/src/view/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use masonry::widget;
pub use masonry::PointerButton;

use crate::core::{DynMessage, Mut, View, ViewMarker};
use crate::{MessageResult, Pod, ViewCtx, ViewId};
use crate::view::Label;
use crate::{MessageResult, Pod, ViewCtx, ViewId};

/// A button which calls `callback` when the primary mouse button (normally left) is pressed.
pub fn button<State, Action>(
Expand Down Expand Up @@ -51,14 +51,16 @@ where
type ViewState = ();

fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) {
ctx.with_leaf_action_widget(|ctx| ctx.new_pod(
widget::Button::from_label(widget::Label::new(self.label.label.clone())
.with_brush(self.label.text_brush.clone())
.with_alignment(self.label.alignment)
.with_style(StyleProperty::FontSize(self.label.text_size))
.with_style(StyleProperty::FontWeight(self.label.weight))
.with_style(StyleProperty::FontStack(self.label.font.clone())),
)))
ctx.with_leaf_action_widget(|ctx| {
ctx.new_pod(widget::Button::from_label(
widget::Label::new(self.label.label.clone())
.with_brush(self.label.text_brush.clone())
.with_alignment(self.label.alignment)
.with_style(StyleProperty::FontSize(self.label.text_size))
.with_style(StyleProperty::FontWeight(self.label.weight))
.with_style(StyleProperty::FontStack(self.label.font.clone())),
))
})
}

fn rebuild(
Expand Down
17 changes: 7 additions & 10 deletions xilem/src/view/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,13 @@ impl Label {
}
}

impl Into<Label> for &str {
fn into(self) -> Label {
label(self)
}
}

impl Into<Label> for String {
fn into(self) -> Label {
label(self)
}
impl<T> From<T> for Label
where
T: Into<ArcStr>,
{
fn from(text: T) -> Label {
label(text)
}
}

impl ViewMarker for Label {}
Expand Down

0 comments on commit 406641d

Please sign in to comment.