Skip to content

Commit 54595f0

Browse files
Merge pull request #46 from iShape-Rust/feature/update_example
fix overlay_editor up iced to 0.14.0
2 parents 9da3cc9 + 334260e commit 54595f0

File tree

21 files changed

+226
-161
lines changed

21 files changed

+226
-161
lines changed

examples/overlay_editor/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib"]
1515
[dependencies]
1616

1717
#iced = { path = "../../../../iced", features = ["wgpu", "advanced"] }
18-
iced = { git = "https://github.com/iced-rs/iced", branch = "master", features = ["wgpu", "advanced", "fira-sans"] }
18+
iced = { version = "0.14.0", features = ["wgpu", "advanced", "fira-sans"] }
1919

2020
serde = { version = "^1.0", features = ["derive"] }
2121
serde_json = "^1.0"
@@ -32,4 +32,4 @@ i_triangle = { version = "^0.35.0", features = ["serde"] }
3232
#i_triangle = { path = "../../../../iShape/iTriangle/iTriangle", default-features = true, features = ["serde"] }
3333
#i_mesh = { path = "../../../../iShape/iMesh/iMesh" }
3434

35-
#ICED_BACKEND=wgpu cargo r -r
35+
#ICED_BACKEND=wgpu cargo r -r

examples/overlay_editor/src/app/boolean/content.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ pub(crate) enum BooleanMessage {
4141
impl EditorApp {
4242
fn boolean_sidebar(&self) -> Column<AppMessage> {
4343
let count = self.app_resource.boolean.count;
44-
let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0)));
44+
let mut column = Column::new().push(
45+
Space::new()
46+
.width(Length::Fill)
47+
.height(Length::Fixed(2.0)),
48+
);
4549
for index in 0..count {
4650
let is_selected = self.state.boolean.test == index;
4751

@@ -62,7 +66,7 @@ impl EditorApp {
6266
column
6367
}
6468

65-
pub(crate) fn boolean_content(&self) -> Row<AppMessage> {
69+
pub(crate) fn boolean_content(&self) -> Row<'_, AppMessage> {
6670
Row::new()
6771
.push(
6872
scrollable(
@@ -223,4 +227,3 @@ impl BooleanState {
223227
self.update_solution();
224228
}
225229
}
226-

examples/overlay_editor/src/app/boolean/control.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iced::{Alignment, Length};
77
use iced::widget::{Column, Container, pick_list, Row, Space, Text};
88

99
impl EditorApp {
10-
pub(crate) fn boolean_control(&self) -> Column<AppMessage> {
10+
pub(crate) fn boolean_control(&self) -> Column<'_, AppMessage> {
1111
let solver_pick_list =
1212
Row::new()
1313
.push(Text::new("Solver:")
@@ -64,9 +64,17 @@ impl EditorApp {
6464

6565
Column::new()
6666
.push(solver_pick_list)
67-
.push(Space::new(Length::Shrink, Length::Fixed(4.0)))
67+
.push(
68+
Space::new()
69+
.width(Length::Shrink)
70+
.height(Length::Fixed(4.0)),
71+
)
6872
.push(fill_pick_list)
69-
.push(Space::new(Length::Shrink, Length::Fixed(4.0)))
73+
.push(
74+
Space::new()
75+
.width(Length::Shrink)
76+
.height(Length::Fixed(4.0)),
77+
)
7078
.push(mode_pick_list)
7179
}
7280
}
@@ -142,4 +150,4 @@ impl std::fmt::Display for ModeOption {
142150
}
143151
)
144152
}
145-
}
153+
}

examples/overlay_editor/src/app/boolean/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) struct WorkspaceState {
2525
}
2626

2727
impl EditorApp {
28-
pub(crate) fn boolean_workspace(&self) -> Container<AppMessage> {
28+
pub(crate) fn boolean_workspace(&self) -> Container<'_, AppMessage> {
2929
Container::new({
3030
let mut stack = Stack::new();
3131
stack = stack.push(

examples/overlay_editor/src/app/design.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Design {
2323
}
2424

2525
pub(crate) fn negative_color() -> Color {
26-
if iced::Theme::default().extended_palette().is_dark {
26+
if Theme::Dark.extended_palette().is_dark {
2727
Color::from_rgb8(224, 224, 224)
2828
} else {
2929
Color::from_rgb8(32, 32, 32)
@@ -58,23 +58,22 @@ impl Design {
5858

5959
pub(super) fn style_sidebar_button(theme: &Theme, status: button::Status) -> button::Style {
6060
let palette = theme.extended_palette();
61+
let text_color = theme.palette().text;
6162
let base = button::Style {
62-
background: Some(Background::Color(palette.primary.strong.color)),
63-
text_color: palette.primary.strong.text,
63+
background: Some(Background::Color(Color::TRANSPARENT)),
64+
text_color,
6465
border: border::rounded(6),
6566
..button::Style::default()
6667
};
6768

6869
match status {
69-
button::Status::Pressed => base,
70-
button::Status::Hovered => button::Style {
71-
background: Some(Background::Color(palette.background.weak.color.scale_alpha(0.2))),
72-
..base
73-
},
74-
button::Status::Disabled | button::Status::Active => button::Style {
75-
background: Some(Background::Color(Color::TRANSPARENT)),
70+
button::Status::Pressed | button::Status::Hovered => button::Style {
71+
background: Some(Background::Color(
72+
palette.background.weak.color.scale_alpha(0.2),
73+
)),
7674
..base
7775
},
76+
button::Status::Disabled | button::Status::Active => base,
7877
}
7978
}
8079

@@ -127,9 +126,9 @@ pub(super) fn style_separator(theme: &Theme) -> rule::Style {
127126

128127
rule::Style {
129128
color,
130-
width: 1,
131129
radius: border::Radius::new(0),
132130
fill_mode: rule::FillMode::Padded(0),
131+
snap: true,
133132
}
134133
}
135134

@@ -139,4 +138,4 @@ pub(super) fn style_sheet_background(theme: &Theme) -> container::Style {
139138
} else {
140139
container::Style::default().background(Color::WHITE.scale_alpha(0.4))
141140
}
142-
}
141+
}

examples/overlay_editor/src/app/main.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::app::stroke::content::StrokeState;
99
use iced::event::Event as MainEvent;
1010
use iced::keyboard::key::Named;
1111
use iced::keyboard::Key;
12-
use iced::widget::{vertical_rule, Space};
12+
use iced::widget::{rule, Space};
1313
use iced::widget::{Button, Column, Container, Row, Text};
1414
use iced::{keyboard, Alignment, Element, Length};
1515
use iced::{Subscription, Task};
@@ -118,16 +118,13 @@ impl EditorApp {
118118
}
119119

120120
pub fn subscription(&self) -> Subscription<AppMessage> {
121-
keyboard::on_key_press(|key, _mods| {
122-
match key.as_ref() {
123-
Key::Named(Named::ArrowDown) => {
124-
Some(AppMessage::NextTest)
125-
}
126-
Key::Named(Named::ArrowUp) => {
127-
Some(AppMessage::PrevTest)
128-
}
121+
keyboard::listen().filter_map(|event| match event {
122+
keyboard::Event::KeyPressed { key, .. } => match key {
123+
Key::Named(Named::ArrowDown) => Some(AppMessage::NextTest),
124+
Key::Named(Named::ArrowUp) => Some(AppMessage::PrevTest),
129125
_ => None,
130-
}
126+
},
127+
_ => None,
131128
})
132129
}
133130

@@ -145,7 +142,7 @@ impl EditorApp {
145142
}
146143
}
147144

148-
pub fn view(&self) -> Element<AppMessage> {
145+
pub fn view(&self) -> Element<'_, AppMessage> {
149146
let content = Row::new().push(
150147
Container::new(self.main_navigation())
151148
.width(Length::Fixed(160.0))
@@ -155,25 +152,29 @@ impl EditorApp {
155152

156153
let content = match self.state.selected_action {
157154
MainAction::Boolean => content
158-
.push(vertical_rule(1).style(style_separator))
155+
.push(rule::vertical(1).style(style_separator))
159156
.push(self.boolean_content()),
160157
MainAction::String => content
161-
.push(vertical_rule(1).style(style_separator))
158+
.push(rule::vertical(1).style(style_separator))
162159
.push(self.string_content()),
163160
MainAction::Stroke => content
164-
.push(vertical_rule(1).style(style_separator))
161+
.push(rule::vertical(1).style(style_separator))
165162
.push(self.stroke_content()),
166163
MainAction::Outline => content
167-
.push(vertical_rule(1).style(style_separator))
164+
.push(rule::vertical(1).style(style_separator))
168165
.push(self.outline_content()),
169166
};
170167

171168
content.height(Length::Fill).into()
172169
}
173170

174-
fn main_navigation(&self) -> Column<AppMessage> {
171+
fn main_navigation(&self) -> Column<'_, AppMessage> {
175172
self.main_actions.iter().fold(
176-
Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0))),
173+
Column::new().push(
174+
Space::new()
175+
.width(Length::Fill)
176+
.height(Length::Fixed(2.0)),
177+
),
177178
|column, item| {
178179
let is_selected = self.state.selected_action.eq(item);
179180
column.push(

examples/overlay_editor/src/app/outline/content.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ pub(crate) enum OutlineMessage {
3939
}
4040

4141
impl EditorApp {
42-
fn outline_sidebar(&self) -> Column<AppMessage> {
42+
fn outline_sidebar(&self) -> Column<'_, AppMessage> {
4343
let count = self.app_resource.outline.count;
44-
let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0)));
44+
let mut column = Column::new().push(
45+
Space::new()
46+
.width(Length::Fill)
47+
.height(Length::Fixed(2.0)),
48+
);
4549
for index in 0..count {
4650
let is_selected = self.state.outline.test == index;
4751
column = column.push(
@@ -70,7 +74,7 @@ impl EditorApp {
7074
column
7175
}
7276

73-
pub(crate) fn outline_content(&self) -> Row<AppMessage> {
77+
pub(crate) fn outline_content(&self) -> Row<'_, AppMessage> {
7478
Row::new()
7579
.push(
7680
scrollable(

examples/overlay_editor/src/app/outline/control.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl std::fmt::Display for JoinOption {
3030
}
3131

3232
impl EditorApp {
33-
pub(crate) fn outline_control(&self) -> Column<AppMessage> {
33+
pub(crate) fn outline_control(&self) -> Column<'_, AppMessage> {
3434
let outer_offset_list = Row::new()
3535
.push(
3636
Text::new("Outer Offset:")
@@ -103,7 +103,11 @@ impl EditorApp {
103103
Column::new()
104104
.push(outer_offset_list)
105105
.push(inner_offset_list)
106-
.push(Space::new(Length::Shrink, Length::Fixed(4.0)))
106+
.push(
107+
Space::new()
108+
.width(Length::Shrink)
109+
.height(Length::Fixed(4.0)),
110+
)
107111
.push(join_pick_list)
108112
}
109113
}
@@ -122,4 +126,4 @@ fn on_select_join(option: JoinOption) -> AppMessage {
122126

123127
fn on_update_join_value(value: u8) -> AppMessage {
124128
AppMessage::Outline(OutlineMessage::JoinValueUpdated(value))
125-
}
129+
}

examples/overlay_editor/src/app/outline/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) struct WorkspaceState {
2222
}
2323

2424
impl EditorApp {
25-
pub(crate) fn outline_workspace(&self) -> Container<AppMessage> {
25+
pub(crate) fn outline_workspace(&self) -> Container<'_, AppMessage> {
2626
Container::new({
2727
let mut stack = Stack::new();
2828
stack = stack.push(

examples/overlay_editor/src/app/string/content.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ pub(crate) enum StringMessage {
4040
}
4141

4242
impl EditorApp {
43-
fn string_sidebar(&self) -> Column<AppMessage> {
43+
fn string_sidebar(&self) -> Column<'_, AppMessage> {
4444
let count = self.app_resource.string.count;
45-
let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0)));
45+
let mut column = Column::new().push(
46+
Space::new()
47+
.width(Length::Fill)
48+
.height(Length::Fixed(2.0)),
49+
);
4650
for index in 0..count {
4751
let is_selected = self.state.string.test == index;
4852
column = column.push(
@@ -62,7 +66,7 @@ impl EditorApp {
6266
column
6367
}
6468

65-
pub(crate) fn string_content(&self) -> Row<AppMessage> {
69+
pub(crate) fn string_content(&self) -> Row<'_, AppMessage> {
6670
Row::new()
6771
.push(
6872
scrollable(
@@ -232,4 +236,3 @@ impl StringState {
232236
self.update_solution();
233237
}
234238
}
235-

0 commit comments

Comments
 (0)