Skip to content
This repository was archived by the owner on Apr 16, 2023. It is now read-only.

Commit 4cfaff5

Browse files
committed
* Added horizontal lines to improve design
* Check differences both ways
1 parent 9d6b4f3 commit 4cfaff5

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

src/view.rs

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::filereader::FileReader;
22
use crate::style;
3-
use iced::alignment;
3+
use iced::{alignment, scrollable, Rule};
44
use iced::{
55
button, text_input, Alignment, Button, Column, Container, Element, Length, Radio, Row, Sandbox,
66
Text, TextInput,
@@ -27,6 +27,7 @@ pub struct ApplicationContext {
2727
pub btn_select_first_file: button::State,
2828
pub btn_select_second_file: button::State,
2929
pub btn_compare: button::State,
30+
pub scrollable: scrollable::State,
3031
pub differences: Vec<String>,
3132
}
3233

@@ -127,6 +128,22 @@ impl Sandbox for ApplicationContext {
127128
}
128129
}
129130

131+
for f in &lines_second_file {
132+
let mut included = false;
133+
for d in &lines_first_file {
134+
if f.eq(d) {
135+
included = true;
136+
}
137+
}
138+
139+
if !included {
140+
let n = String::from(f);
141+
if !diff.contains(&n) {
142+
diff.push(n);
143+
}
144+
}
145+
}
146+
130147
self.differences = diff;
131148
}
132149
Message::ThemeChanged(d) => self.theme = d,
@@ -136,21 +153,24 @@ impl Sandbox for ApplicationContext {
136153
fn view(&mut self) -> Element<'_, Self::Message> {
137154
let title = Text::new("text-diff")
138155
.width(Length::Fill)
139-
.size(100)
156+
.size(85)
140157
.color([0.5, 0.5, 0.5])
141158
.horizontal_alignment(alignment::Horizontal::Center);
142159

143160
let choose_theme = style::Theme::ALL.iter().fold(
144-
Column::new().spacing(10).push(Text::new("Choose a theme:")),
145-
|column, theme| {
146-
column.push(
161+
Row::new()
162+
.width(Length::Fill)
163+
.align_items(Alignment::Center)
164+
.spacing(10),
165+
|row, theme| {
166+
row.push(
147167
Radio::new(
148168
*theme,
149169
format!("{:?}", theme),
150170
Some(self.theme),
151171
Message::ThemeChanged,
152172
)
153-
.style(self.theme),
173+
.style(self.theme),
154174
)
155175
},
156176
);
@@ -161,37 +181,37 @@ impl Sandbox for ApplicationContext {
161181
&self.first_file,
162182
Message::FirstFileInputChanged,
163183
)
164-
.padding(10)
165-
.size(20)
166-
.style(self.theme);
184+
.padding(10)
185+
.size(20)
186+
.style(self.theme);
167187

168188
let btn_select_first_file = Button::new(
169189
&mut self.btn_select_first_file,
170190
Text::new("...").horizontal_alignment(alignment::Horizontal::Center),
171191
)
172-
.padding(10)
173-
.min_width(60)
174-
.on_press(Message::SelectFirstFilePressed)
175-
.style(self.theme);
192+
.padding(10)
193+
.min_width(60)
194+
.on_press(Message::SelectFirstFilePressed)
195+
.style(self.theme);
176196

177197
let second_file_input = TextInput::new(
178198
&mut self.second_file_input,
179199
"/path/to/second/file.txt",
180200
&self.second_file,
181201
Message::SecondFileInputChanged,
182202
)
183-
.padding(10)
184-
.size(20)
185-
.style(self.theme);
203+
.padding(10)
204+
.size(20)
205+
.style(self.theme);
186206

187207
let btn_select_second_file = Button::new(
188208
&mut self.btn_select_second_file,
189209
Text::new("...").horizontal_alignment(alignment::Horizontal::Center),
190210
)
191-
.padding(10)
192-
.min_width(60)
193-
.on_press(Message::SelectSecondFilePressed)
194-
.style(self.theme);
211+
.padding(10)
212+
.min_width(60)
213+
.on_press(Message::SelectSecondFilePressed)
214+
.style(self.theme);
195215

196216
let btn_compare = Button::new(&mut self.btn_compare, Text::new("Compare"))
197217
.padding(10)
@@ -203,7 +223,7 @@ impl Sandbox for ApplicationContext {
203223
.padding(20)
204224
.max_width(800)
205225
.push(title)
206-
.push(choose_theme)
226+
.push(Rule::horizontal(20).style(self.theme))
207227
.push(
208228
Row::new()
209229
.spacing(10)
@@ -228,15 +248,21 @@ impl Sandbox for ApplicationContext {
228248

229249
if !self.differences.is_empty() {
230250
let choose_theme = self.differences.iter().fold(
231-
Column::new().spacing(10).push(Text::new("Differences:")),
232-
|column, theme| {
233-
column.push(Text::new(format!("{}", theme)))
234-
},
251+
Column::new()
252+
.spacing(10)
253+
.push(Text::new("Differences:").size(30)),
254+
|column, theme| column.push(Text::new(format!("{}", theme))),
235255
);
236256

237-
content = content.push(choose_theme);
257+
content = content
258+
.push(Rule::horizontal(20).style(self.theme))
259+
.push(choose_theme);
238260
}
239261

262+
content = content
263+
.push(Rule::horizontal(20).style(self.theme))
264+
.push(choose_theme);
265+
240266
Container::new(content)
241267
.width(Length::Fill)
242268
.height(Length::Fill)

0 commit comments

Comments
 (0)