Skip to content

Commit

Permalink
Fixed Selection list
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Nov 8, 2023
1 parent 1af1814 commit e8bdd33
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ default = [
"tabs",
"time_picker",
"wrap",
#"selection_list",
"selection_list",
#"split",
#"menu",
#"quad",
Expand Down Expand Up @@ -98,7 +98,7 @@ members = [
"examples/time_picker",
"examples/wrap",
"examples/number_input",
#"examples/selection_list",
"examples/selection_list",
#"examples/split",
#"examples/split_scroller",
#"examples/menu",
Expand Down
6 changes: 3 additions & 3 deletions examples/selection_list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ impl Sandbox for Example {
self.manual_select = None;
}
Message::ManualSelection => {
if let Some(option) = self.vec.get(0) {
if let Some(option) = self.vec.get(2) {
self.selected_language = option.to_owned();
self.selected_index = 0;
self.manual_select = Some(0);
self.selected_index = 2;
self.manual_select = Some(2);
}
}
}
Expand Down
36 changes: 23 additions & 13 deletions src/native/selection_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ use crate::style::selection_list::StyleSheet;
use iced_widget::{
container,
core::{
self, event,
self,
alignment::{Horizontal, Vertical},
event,
layout::{Limits, Node},
mouse::{self, Cursor},
renderer,
text::{Paragraph, Text},
widget::Tree,
Clipboard, Element, Event, Layout, Length, Rectangle, Shell, Size, Widget,
Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Size, Widget,
},
graphics,
runtime::Font,
scrollable, text,
text::LineHeight,
Expand Down Expand Up @@ -168,7 +172,7 @@ where
Length::Shrink
}

fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node {
fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node {
use std::f32;

let limits = limits.width(self.width).height(self.height);
Expand All @@ -179,16 +183,20 @@ where

labels
.map(|label| {
let size = renderer.measure(
&label,
self.text_size,
LineHeight::default(),
self.font,
Size::new(f32::INFINITY, f32::INFINITY),
text::Shaping::Advanced,
);
let text = Text {
content: &label,
size: Pixels(self.text_size),
line_height: LineHeight::default(),
bounds: Size::INFINITY,
font: self.font,
horizontal_alignment: Horizontal::Left,
vertical_alignment: Vertical::Top,
shaping: text::Shaping::Advanced,
};

size.width.round() as u32 + self.padding as u32 * 2
let mut paragraph = graphics::text::Paragraph::new();
paragraph.update(text);
paragraph.min_bounds().width.round() as u32 + self.padding as u32 * 2
})
.max()
.unwrap_or(100)
Expand All @@ -198,7 +206,9 @@ where

let limits = limits.max_width(max_width as f32 + self.padding * 2.0);

let content = self.container.layout(renderer, &limits);
let content = self
.container
.layout(&mut tree.children[0], renderer, &limits);
let size = limits.resolve(content.size());
Node::with_children(size, vec![content])
}
Expand Down
38 changes: 21 additions & 17 deletions src/native/selection_list/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use iced_widget::{
tree::{State, Tag},
Tree,
},
Clipboard, Color, Element, Event, Layout, Length, Rectangle, Shell, Size, Widget,
Clipboard, Color, Element, Event, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
Widget,
},
text::LineHeight,
};
Expand Down Expand Up @@ -109,7 +110,12 @@ where
Length::Shrink
}

fn layout(&self, _renderer: &Renderer, limits: &layout::Limits) -> layout::Node {
fn layout(
&self,
_tree: &mut Tree,
_renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
use std::f32;
let limits = limits.height(Length::Fill).width(Length::Fill);

Expand Down Expand Up @@ -255,22 +261,20 @@ where
theme.style(&self.style).text_color
};

renderer.fill_text(core::text::Text {
content: &option.to_string(),
bounds: Rectangle {
x: bounds.x,
y: bounds.center_y(),
width: f32::INFINITY,
..bounds
renderer.fill_text(
core::text::Text {
content: &option.to_string(),
bounds: Size::new(f32::INFINITY, bounds.height),
size: Pixels(self.text_size),
font: self.font,
horizontal_alignment: Horizontal::Left,
vertical_alignment: Vertical::Center,
line_height: LineHeight::default(),
shaping: iced_widget::text::Shaping::Advanced,
},
size: self.text_size,
color: text_color,
font: self.font,
horizontal_alignment: Horizontal::Left,
vertical_alignment: Vertical::Center,
line_height: LineHeight::default(),
shaping: iced_widget::text::Shaping::Advanced,
});
Point::new(bounds.x, bounds.center_y()),
text_color,
);
}
}
}
Expand Down

0 comments on commit e8bdd33

Please sign in to comment.