-
Notifications
You must be signed in to change notification settings - Fork 569
Listiter impl #1641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Listiter impl #1641
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
413e6ca
adding ListIter implementations and examples
Lejero 520202c
Changed example name, added modifying via buttons.
Lejero 9671032
handling changes of Key for OrdMap and HashMap
Lejero 73e5bba
Added lejero user, pull request detail
Lejero 99167ef
changelog edit
Lejero b52fe80
github spelling mistake
Lejero 2c95175
change log overwrite
Lejero e6e963a
Merge pull request #1 from linebender/master
Lejero 6a75243
formatting, adhering to standards
Lejero bb980b5
Merge branch 'listiter-impl' of https://github.com/Lejero/druid into …
Lejero a8d193f
adding changelog entry
Lejero 5466798
Added PR
Lejero 0967ccc
Added web examples entry for list_sources.rs
Lejero cb03997
Removed HashMap ListIter implementation.
Lejero e261ab3
Update CHANGELOG.md
Lejero 49741ac
Update druid/examples/list_sources.rs
Lejero 8c1f29d
Removed Unnecessary Clone
Lejero 88794e0
Removed HashMap Key and Value impl for ListIter and list_sources.rs e…
Lejero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright 2019 The Druid Authors. | ||
Lejero marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! Demos alternative iterable data type for the List widget, im::OrdMap | ||
| //! Two ListIter implementations provide a version which only concerns | ||
| //! itself with the values, and another which concerns itself with both | ||
| //! keys and vales. | ||
|
|
||
| use druid::im::{ordmap, OrdMap}; | ||
| use druid::widget::{Button, CrossAxisAlignment, Flex, Label, List, Scroll}; | ||
| use druid::{ | ||
| AppLauncher, Color, Data, Lens, LocalizedString, UnitPoint, Widget, WidgetExt, WindowDesc, | ||
| }; | ||
|
|
||
| #[derive(Clone, Data, Lens)] | ||
| struct AppData { | ||
| adding_index: usize, | ||
| om_values: OrdMap<u32, String>, | ||
| om_keys_values: OrdMap<String, u64>, | ||
| } | ||
|
|
||
| pub fn main() { | ||
| let main_window = WindowDesc::new(ui_builder()) | ||
| .window_size((1200.0, 600.0)) | ||
| .title( | ||
| LocalizedString::new("list-sources-demo-window-title") | ||
| .with_placeholder("List Sources Demo"), | ||
| ); | ||
| // Set our initial data. | ||
| let om_values = ordmap! {3 => String::from("Apple"), 1 => String::from("Pear"), 2 => String::from("Orange")}; | ||
| let om_keys_values = ordmap! {String::from("Russia") => 17098242, String::from("Canada") => 9984670, | ||
| String::from("China") => 956960}; | ||
| let data = AppData { | ||
| adding_index: om_values.len(), | ||
| om_values, | ||
| om_keys_values, | ||
| }; | ||
| AppLauncher::with_window(main_window) | ||
| .use_env_tracing() | ||
| .launch(data) | ||
| .expect("launch failed"); | ||
| } | ||
|
|
||
| fn ui_builder() -> impl Widget<AppData> { | ||
| let mut root = Flex::column(); | ||
|
|
||
| //Buttons to test adding and removing entries from the lists | ||
| root.add_child( | ||
| Button::new("Add") | ||
| .on_click(|_, data: &mut AppData, _| { | ||
| data.adding_index += 1; | ||
| data.om_values.insert( | ||
| data.adding_index as u32, | ||
| format!("Fruit #{}", data.adding_index), | ||
| ); | ||
| data.om_keys_values | ||
| .insert(format!("Country #{}", data.adding_index), 42); | ||
| }) | ||
| .fix_height(30.0) | ||
| .expand_width(), | ||
| ); | ||
| root.add_child( | ||
| Button::new("Remove First") | ||
| .on_click(|_, data: &mut AppData, _| { | ||
| if !data.om_values.is_empty() { | ||
| if let Some(k) = data.om_values.clone().iter().next() { | ||
| data.om_values.remove(&k.0.clone()); | ||
| } | ||
| } | ||
| if !data.om_keys_values.is_empty() { | ||
| if let Some(k) = data.om_keys_values.clone().iter().next() { | ||
| data.om_keys_values.remove(&k.0.clone()); | ||
| } | ||
| } | ||
| }) | ||
| .fix_height(30.0) | ||
| .expand_width(), | ||
| ); | ||
|
|
||
| let mut lists = Flex::row().cross_axis_alignment(CrossAxisAlignment::Start); | ||
|
|
||
| // Build a list values from an ordmap | ||
| // The display order will be based on the Ord trait of the keys | ||
| lists.add_flex_child( | ||
| Flex::column() | ||
| .with_child(Label::new("List from im::OrdMap Values")) | ||
| .with_child( | ||
| Scroll::new(List::new(|| { | ||
| Label::new(|item: &String, _env: &_| item.to_string()) | ||
| .align_vertical(UnitPoint::LEFT) | ||
| .padding(10.0) | ||
| .expand() | ||
| .height(50.0) | ||
| .background(Color::rgb(0.5, 0.5, 0.5)) | ||
| })) | ||
| .vertical() | ||
| .lens(AppData::om_values), | ||
| ), | ||
| 1.0, | ||
| ); | ||
|
|
||
| // Build a list of key value pairs from an ordmap | ||
| // The display order will be based on the Ord trait of the keys | ||
| lists.add_flex_child( | ||
| Flex::column() | ||
| .with_child(Label::new("List from im::OrdMap Keys and Values")) | ||
| .with_child( | ||
| Scroll::new(List::new(|| { | ||
| Label::new(|item: &(String, u64), _env: &_| { | ||
| format!("{0}: {1} square kilometres", item.0, item.1) | ||
| }) | ||
| .align_vertical(UnitPoint::LEFT) | ||
| .padding(10.0) | ||
| .expand() | ||
| .height(50.0) | ||
| .background(Color::rgb(0.5, 0.0, 0.5)) | ||
| })) | ||
| .vertical() | ||
| .lens(AppData::om_keys_values), | ||
| ), | ||
| 1.0, | ||
| ); | ||
|
|
||
| root.add_flex_child(lists, 1.0); | ||
|
|
||
| root | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.