Skip to content

Commit

Permalink
number input fixed icon button being oversized. fixes #126
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Aug 4, 2023
1 parent 18e2a95 commit 8295448
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DynamicHeight to menu bar @latidoremi .
- [Breaking] Custom Style Options for all widgets.
- Align Option for modal @wiiznokes .
- width setting to `NumberInput`.`

### Changed
- Changed current width to content_width for `NumberInput`.

### Fixed
- TabBars hieght issue within container.
- number input buttons not rendering correctly when they are oversized.

## [0.6.0] - 2023-07-28

Expand Down
2 changes: 1 addition & 1 deletion examples/number_input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum Message {

fn main() -> iced::Result {
NumberInputDemo::run(Settings {
default_text_size: 14.0,
default_text_size: 65.0,
window: window::Settings {
size: (250, 200),
..Default::default()
Expand Down
21 changes: 16 additions & 5 deletions src/native/number_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ where
style: <Renderer::Theme as number_input::StyleSheet>::Style,
/// The font text of the [`NumberInput`](NumberInput).
font: Renderer::Font,
/// The Width to use for the NumberBox Default is Length::Fill
width: Length,
}

impl<'a, T, Message, Renderer> NumberInput<'a, T, Message, Renderer>
Expand Down Expand Up @@ -124,6 +126,7 @@ where
on_change: Box::new(on_changed),
style: <Renderer::Theme as number_input::StyleSheet>::Style::default(),
font: Renderer::Font::default(),
width: Length::Fill,
}
}

Expand Down Expand Up @@ -176,6 +179,13 @@ where
/// Sets the width of the [`NumberInput`].
#[must_use]
pub fn width(mut self, width: Length) -> Self {
self.width = width;
self
}

/// Sets the content width of the [`NumberInput`].
#[must_use]
pub fn content_width(mut self, width: Length) -> Self {
self.content = self.content.width(width);
self
}
Expand Down Expand Up @@ -289,7 +299,7 @@ where
}

fn width(&self) -> Length {
Length::Fill
self.width
}

fn height(&self) -> Length {
Expand All @@ -302,7 +312,8 @@ where
.width(self.width())
.height(Length::Shrink)
.pad(padding);
let content = self.content.layout(renderer, &limits.loose());
let content = self.content.layout(renderer, &limits);
let limits2 = Limits::new(Size::new(0.0, 0.0), content.size());
let txt_size = self.size.unwrap_or_else(|| renderer.default_size());

let icon_size = txt_size * 2.5 / 4.0;
Expand All @@ -317,17 +328,17 @@ where
.width(Length::Shrink)
.push(btn_mod('+'))
.push(btn_mod('-'))
.layout(renderer, &limits.loose())
.layout(renderer, &limits2.loose())
} else {
Column::<(), Renderer>::new()
.spacing(1)
.width(Length::Shrink)
.push(btn_mod('▲'))
.push(btn_mod('▼'))
.layout(renderer, &limits.loose())
.layout(renderer, &limits2.loose())
};
let intrinsic = Size::new(
content.size().width - 3.0,
content.size().width - 1.0,
content.size().height.max(modifier.size().height),
);
modifier.align(Alignment::End, Alignment::Center, intrinsic);
Expand Down

0 comments on commit 8295448

Please sign in to comment.