Skip to content

Commit 23963d3

Browse files
authored
Various documentation-related fixes (#2301)
1 parent b138b01 commit 23963d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+807
-420
lines changed

CONTRIBUTING.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# How to contribute
22

3-
We'd love to accept your patches and contributions to this project. There are
4-
just a few small guidelines you need to follow.
3+
**IMPORTANT:** The Druid project is being discontinued. While we will still accept
4+
all contributions, we'll prefer bugfixes and documentations improvements to new
5+
features.
6+
7+
If you still want to contribute, here are the guidelines you need to follow.
58

69
## Changelog
710

@@ -102,7 +105,7 @@ adds Druid as a dependency and it won't even compile.
102105
For that reason our CI testing always uses the highest version that is still compatible.
103106
This mimics what a new developer would experience when they start using Druid.
104107

105-
What about the the minimum supported version or all the versions between the minimum and maximum?
108+
What about the minimum supported version or all the versions between the minimum and maximum?
106109
It is not practical for us to test all the combinations of possible sub-dependency versions.
107110
Without testing there can easily be mistakes. Let's say our `Cargo.toml` specifies that
108111
we depend on the package `foo` version `^1.1.1` and the latest `foo` version is `1.1.3`.

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ performance, a rich palette of interactions (hence a widget library to support
1313
them), and playing well with the native platform.
1414
See the [goals section](#Goals) for more details.
1515

16-
Druid's current development is largely driven by its use in [Runebender], a new
17-
font editor.
16+
**IMPORTANT:** The Druid project is being discontinued. While we will still accept
17+
all contributions, we'll prefer bugfixes and documentations improvements to new
18+
features. Current development effort is focused on [Xilem](https://github.com/linebender/xilem).
1819

19-
We have been doing periodic releases of Druid on crates.io, but it is under
20-
active development and its API might change. All changes are documented
20+
We have been doing periodic releases of Druid on crates.io, but the API is still unstable. All changes are documented
2121
in [the changelog](https://github.com/linebender/druid/blob/master/CHANGELOG.md).
2222

2323
For an overview of some key concepts, see the (work in progress) [Druid book].
@@ -130,7 +130,7 @@ the Rust community is working on a variety of different libraries with
130130
different goals, so here are some of Druid's non-goals and possible
131131
alternatives that can offer those capabilities:
132132

133-
- Use the the platform-native widgets or mimic them. ([Relm], [Slint])
133+
- Use the platform-native widgets or mimic them. ([Relm], [Slint])
134134
- Embed easily into custom render pipelines. ([Conrod])
135135
- Adhere to a specific architectural style such as Elm. ([Iced], [Relm])
136136
- Support rendering to HTML when targeting the web. ([Iced], [Moxie])

docs/book_examples/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ authors = ["Colin Rofls <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
druid = { path = "../../druid" }
8+
druid = { path = "../../druid", features = [ "im" ] }
9+
im = { version = "15.0.0" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#![allow(unused)]
2+
3+
// ANCHOR: example_1_imports
4+
use druid::widget::Label;
5+
use druid::{AppLauncher, Widget, WindowDesc};
6+
// ANCHOR_END: example_1_imports
7+
8+
// ANCHOR: example_2_imports
9+
use druid::widget::{Container, Flex, Split};
10+
use druid::Color;
11+
// ANCHOR_END: example_2_imports
12+
13+
// ANCHOR: example_3_imports
14+
use im::Vector;
15+
// ANCHOR_END: example_3_imports
16+
17+
// ANCHOR: example_3b_imports
18+
use druid::widget::List;
19+
// ANCHOR_END: example_3b_imports
20+
21+
// ANCHOR: example_4_imports
22+
use im::vector;
23+
// ANCHOR_END: example_4_imports
24+
25+
// ANCHOR: example_5_imports
26+
use druid::widget::Button;
27+
// ANCHOR_END: example_5_imports
28+
29+
// ---
30+
31+
// ANCHOR: example_6_imports
32+
use druid::{Data, Lens};
33+
// ANCHOR_END: example_6_imports
34+
35+
// ANCHOR: example_6_derive
36+
#[derive(Clone, Data, Lens)]
37+
// ANCHOR_END: example_6_derive
38+
39+
// ANCHOR: example_6_struct
40+
struct TodoList {
41+
items: Vector<String>,
42+
next_item: String,
43+
}
44+
// ANCHOR_END: example_6_struct
45+
46+
// ANCHOR: example_7_imports
47+
use druid::widget::LensWrap;
48+
// ANCHOR_END: example_7_imports
49+
50+
fn build_example_7() -> impl Widget<TodoList> {
51+
// ANCHOR: example_7
52+
// Replace previous List with:
53+
LensWrap::new(
54+
List::new(|| Label::dynamic(|data, _| format!("List item: {}", data))),
55+
TodoList::items,
56+
)
57+
// ANCHOR_END: example_7
58+
}
59+
60+
fn build_example_7b() -> impl Widget<TodoList> {
61+
// ANCHOR: example_7b
62+
// Replace previous Button with:
63+
Button::new("Add item").on_click(|_, data: &mut TodoList, _| {
64+
data.items.push_back(data.next_item.clone());
65+
data.next_item = String::new();
66+
})
67+
// ANCHOR_END: example_7b
68+
}
69+
70+
// ANCHOR: example_8_imports
71+
use druid::widget::TextBox;
72+
// ANCHOR_END: example_8_imports
73+
74+
fn build_example_8() -> impl Widget<TodoList> {
75+
// ANCHOR: example_8
76+
// Replace `Label::new("Textbox placeholder")` with
77+
LensWrap::new(TextBox::new(), TodoList::next_item)
78+
// ANCHOR_END: example_8
79+
}
80+
81+
// ANCHOR: complete_code
82+
fn build_ui() -> impl Widget<TodoList> {
83+
Split::columns(
84+
Container::new(
85+
// Dynamic list of Widgets
86+
LensWrap::new(
87+
List::new(|| Label::dynamic(|data, _| format!("List item: {}", data))),
88+
TodoList::items,
89+
),
90+
)
91+
.border(Color::grey(0.6), 2.0),
92+
Container::new(
93+
Flex::column()
94+
.with_flex_child(
95+
Button::new("Add item").on_click(|_, data: &mut TodoList, _| {
96+
data.items.push_back(data.next_item.clone());
97+
data.next_item = String::new();
98+
}),
99+
1.0,
100+
)
101+
.with_flex_child(LensWrap::new(TextBox::new(), TodoList::next_item), 1.0),
102+
)
103+
.border(Color::grey(0.6), 2.0),
104+
)
105+
}
106+
107+
fn main() {
108+
let main_window = WindowDesc::new(build_ui())
109+
.window_size((600.0, 400.0))
110+
.title("My first Druid App");
111+
let initial_data = TodoList {
112+
items: vector![
113+
"first item".into(),
114+
"second item".into(),
115+
"third item".into(),
116+
"foo".into(),
117+
"bar".into(),
118+
],
119+
next_item: String::new(),
120+
};
121+
122+
AppLauncher::with_window(main_window)
123+
.launch(initial_data)
124+
.expect("Failed to launch application");
125+
}
126+
// ANCHOR_END: complete_code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#![allow(clippy::let_unit_value)]
2+
3+
// ANCHOR: example_1_imports
4+
use druid::widget::Label;
5+
use druid::{AppLauncher, Widget, WindowDesc};
6+
// ANCHOR_END: example_1_imports
7+
8+
// ANCHOR: example_2_imports
9+
use druid::widget::{Container, Flex, Split};
10+
use druid::Color;
11+
// ANCHOR_END: example_2_imports
12+
13+
// ANCHOR: example_3_imports
14+
use im::Vector;
15+
// ANCHOR_END: example_3_imports
16+
17+
// ANCHOR: example_3b_imports
18+
use druid::widget::List;
19+
// ANCHOR_END: example_3b_imports
20+
21+
// ANCHOR: example_4_imports
22+
use im::vector;
23+
// ANCHOR_END: example_4_imports
24+
25+
// ANCHOR: example_5_imports
26+
use druid::widget::Button;
27+
// ANCHOR_END: example_5_imports
28+
29+
// ANCHOR: example_1
30+
fn build_ui() -> impl Widget<()> {
31+
Label::new("Hello world")
32+
}
33+
34+
fn main() {
35+
let main_window = WindowDesc::new(build_ui())
36+
.window_size((600.0, 400.0))
37+
.title("My first Druid App");
38+
let initial_data = ();
39+
40+
AppLauncher::with_window(main_window)
41+
.launch(initial_data)
42+
.expect("Failed to launch application");
43+
}
44+
// ANCHOR_END: example_1
45+
46+
fn build_example_2() -> impl Widget<()> {
47+
// ANCHOR: example_2_builder
48+
Split::columns(
49+
Container::new(
50+
Flex::column()
51+
.with_flex_child(Label::new("first item"), 1.0)
52+
.with_flex_child(Label::new("second item"), 1.0)
53+
.with_flex_child(Label::new("third item"), 1.0)
54+
.with_flex_child(Label::new("fourth item"), 1.0),
55+
)
56+
.border(Color::grey(0.6), 2.0),
57+
Container::new(
58+
Flex::column()
59+
.with_flex_child(Label::new("Button placeholder"), 1.0)
60+
.with_flex_child(Label::new("Textbox placeholder"), 1.0),
61+
)
62+
.border(Color::grey(0.6), 2.0),
63+
)
64+
// ANCHOR_END: example_2_builder
65+
}
66+
67+
type TodoList = Vector<String>;
68+
69+
fn build_example_3() -> impl Widget<TodoList> {
70+
// ANCHOR: example_3_builder
71+
Split::columns(
72+
Container::new(
73+
// Dynamic list of Widgets
74+
List::new(|| Label::dynamic(|data, _| format!("List item: {}", data))),
75+
)
76+
.border(Color::grey(0.6), 2.0),
77+
Container::new(
78+
Flex::column()
79+
.with_flex_child(Label::new("Button placeholder"), 1.0)
80+
.with_flex_child(Label::new("Textbox placeholder"), 1.0),
81+
)
82+
.border(Color::grey(0.6), 2.0),
83+
)
84+
// ANCHOR_END: example_3_builder
85+
}
86+
87+
fn example_4_main() {
88+
fn build_ui() -> impl Widget<TodoList> {
89+
build_example_3()
90+
}
91+
92+
// ANCHOR: example_4_main
93+
let main_window = WindowDesc::new(build_ui())
94+
.window_size((600.0, 400.0))
95+
.title("My first Druid App");
96+
let initial_data = vector![
97+
"first item".into(),
98+
"second item".into(),
99+
"third item".into(),
100+
"foo".into(),
101+
"bar".into(),
102+
];
103+
104+
AppLauncher::with_window(main_window)
105+
.launch(initial_data)
106+
.expect("Failed to launch application");
107+
// ANCHOR_END: example_4_main
108+
}
109+
110+
fn build_example_5a() -> impl Widget<TodoList> {
111+
// ANCHOR: example_5a_button
112+
// Replace `Label::new("Button placeholder")` with
113+
Button::new("Add item")
114+
// ANCHOR_END: example_5a_button
115+
}
116+
117+
fn build_example_5b() -> impl Widget<TodoList> {
118+
// ANCHOR: example_5b_button
119+
Button::new("Add item")
120+
.on_click(|_, data: &mut Vector<String>, _| data.push_back("New item".into()))
121+
// ANCHOR_END: example_5b_button
122+
}

docs/book_examples/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
mod custom_widgets_md;
66
mod data_md;
77
mod env_md;
8+
mod getting_started_2_md;
9+
mod getting_started_md;
810
mod lens_md;
911
mod widget_md;

docs/src/intro.md docs/src/01_overview.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Druid
22

3+
**Note:** Druid is being discontinued in favor of other projects based on the same general principles, such as [Xilem](https://github.com/linebender/xilem/).
4+
35
Druid is a framework for building simple graphical applications.
46

57
Druid is composed of a number of related projects. [`druid-shell`] is a
@@ -8,17 +10,17 @@ current OS & window manager. [`piet`] is an abstraction for doing 2D graphics;
810
[`kurbo`] is a library for 2D geometry; and [`druid`] itself is an opinionated set of
911
high-level APIs for building cross-platform desktop applications.
1012

11-
Druid is *data oriented*. It shares many ideas (and is directly inspired by)
13+
The framework is *data oriented*. It shares many ideas (and is directly inspired by)
1214
contemporary declarative UI frameworks such as [Flutter], [Jetpack Compose],
1315
and [SwiftUI], while also attempting to be conceptually simple and largely
1416
*non-magical*. A programmer familiar with Rust should be able to understand how
1517
Druid works without special difficulty.
1618

17-
## Goals and Status
19+
## Prerequisites
1820

19-
The current goal of Druid is to make it easy to write a program in Rust that
20-
can present a GUI and accept user input. Running your program should be as
21-
simple as `cargo run`.
21+
This tutorial assumes basic familliarity with Rust and a working setup with the basic tooling like
22+
Rustup and Cargo. This tutorial will use stable Rust (v1.65.0 at the time of writing) and the latest
23+
released version of Druid (v0.8).
2224

2325
## Key Concepts
2426

0 commit comments

Comments
 (0)