Skip to content

Commit

Permalink
Use layout = self.#text_field
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jan 21, 2025
1 parent a2a48d4 commit 02d5598
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 36 deletions.
9 changes: 1 addition & 8 deletions crates/kas-core/src/decorations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl_scope! {
#[derive(Clone, Debug, Default)]
#[widget {
Data = ();
layout = self.text;
}]
pub(crate) struct Label {
core: widget_core!(),
Expand All @@ -121,18 +122,10 @@ impl_scope! {
}

impl Layout for Self {
fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
sizer.text_rules(&mut self.text, axis)
}

fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect, hints: AlignHints) {
self.core.rect = rect;
self.text.set_rect(cx, rect, hints.combine(AlignHints::CENTER));
}

fn draw(&mut self, mut draw: DrawCx) {
draw.text(self.rect(), &self.text);
}
}

impl Events for Self {
Expand Down
10 changes: 1 addition & 9 deletions crates/kas-core/src/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl_scope! {
#[derive(Clone, Debug, Default)]
#[widget {
Data = ();
layout = self.text;
}]
pub struct StrLabel {
core: widget_core!(),
Expand All @@ -44,19 +45,10 @@ impl_scope! {
}

impl Layout for Self {
#[inline]
fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
sizer.text_rules(&mut self.text, axis)
}

fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect, hints: AlignHints) {
self.core.rect = rect;
self.text.set_rect(cx, rect, hints.combine(AlignHints::VERT_CENTER));
}

fn draw(&mut self, mut draw: DrawCx) {
draw.text(self.rect(), &self.text);
}
}

impl Events for Self {
Expand Down
23 changes: 4 additions & 19 deletions crates/kas-widgets/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl_scope! {
#[derive(Clone, Debug)]
#[widget {
Data = ();
layout = self.text;
}]
pub struct Label<T: FormattableText + 'static> {
core: widget_core!(),
Expand Down Expand Up @@ -111,19 +112,10 @@ impl_scope! {
}

impl Layout for Self {
#[inline]
fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
sizer.text_rules(&mut self.text, axis)
}

fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect, hints: AlignHints) {
self.core.rect = rect;
self.text.set_rect(cx, rect, hints.combine(AlignHints::VERT_CENTER));
}

fn draw(&mut self, mut draw: DrawCx) {
draw.text(self.rect(), &self.text);
}
}

impl Events for Self {
Expand Down Expand Up @@ -185,7 +177,9 @@ impl_scope! {
/// Line-wrapping is enabled by default.
#[impl_default]
#[derive(Clone, Debug)]
#[widget]
#[widget {
layout = self.text;
}]
pub struct AccessLabel {
core: widget_core!(),
text: Text<AccessString>,
Expand Down Expand Up @@ -264,19 +258,10 @@ impl_scope! {
}

impl Layout for Self {
#[inline]
fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
sizer.text_rules(&mut self.text, axis)
}

fn set_rect(&mut self, cx: &mut ConfigCx, rect: Rect, hints: AlignHints) {
self.core.rect = rect;
self.text.set_rect(cx, rect, hints.combine(AlignHints::VERT_CENTER));
}

fn draw(&mut self, mut draw: DrawCx) {
draw.text(self.rect(), &self.text);
}
}

impl Events for Self {
Expand Down

0 comments on commit 02d5598

Please sign in to comment.