Skip to content

Commit 040ce04

Browse files
committed
update examples
1 parent ea1c010 commit 040ce04

6 files changed

Lines changed: 62 additions & 254 deletions

File tree

sugarloaf/examples/f16_test.rs

Lines changed: 0 additions & 195 deletions
This file was deleted.

sugarloaf/examples/image.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ApplicationHandler for Application {
7575
.expect("Sugarloaf instance should be created");
7676

7777
sugarloaf.set_background_image(&sugarloaf::ImageProperties {
78-
path: String::from("resources/rio-colors.png"),
78+
path: String::from("resources/demo-sugarloaf-1.png"),
7979
width: Some(400.),
8080
height: Some(400.),
8181
x: 0.,
@@ -119,6 +119,7 @@ impl ApplicationHandler for Application {
119119
window.request_redraw();
120120
}
121121
WindowEvent::RedrawRequested => {
122+
// No rect() calls needed here, just rendering the background image
122123
sugarloaf.render();
123124
event_loop.set_control_flow(ControlFlow::Wait);
124125
}

sugarloaf/examples/layer.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rio_window::{
88
};
99
use std::error::Error;
1010
use sugarloaf::{
11-
layout::RootStyle, FragmentStyle, Sugarloaf, SugarloafWindow, SugarloafWindowSize,
11+
layout::RootStyle, SpanStyle, Sugarloaf, SugarloafWindow, SugarloafWindowSize,
1212
};
1313

1414
fn main() {
@@ -24,8 +24,6 @@ struct Application {
2424
window: Option<Window>,
2525
height: f32,
2626
width: f32,
27-
rich_text: usize,
28-
second_rich_text: usize,
2927
}
3028

3129
impl Application {
@@ -37,8 +35,6 @@ impl Application {
3735
window: None,
3836
width,
3937
height,
40-
rich_text: 0,
41-
second_rich_text: 0,
4238
}
4339
}
4440

@@ -81,8 +77,6 @@ impl ApplicationHandler for Application {
8177
.expect("Sugarloaf instance should be created");
8278

8379
sugarloaf.set_background_color(Some(wgpu::Color::RED));
84-
self.rich_text = sugarloaf.create_rich_text(None);
85-
self.second_rich_text = sugarloaf.create_rich_text(None);
8680
window.request_redraw();
8781

8882
// we will add three layers
@@ -123,44 +117,49 @@ impl ApplicationHandler for Application {
123117
window.request_redraw();
124118
}
125119
WindowEvent::RedrawRequested => {
126-
let content = sugarloaf.content();
127-
content.sel(self.rich_text).clear();
128-
content
120+
const TEXT_ID_0: usize = 0;
121+
const TEXT_ID_1: usize = 1;
122+
123+
sugarloaf
124+
.text(TEXT_ID_0)
125+
.clear()
129126
.new_line()
130-
.add_text(
127+
.add_span(
131128
"First Layer",
132-
FragmentStyle {
129+
SpanStyle {
133130
color: [1.0, 1.0, 1.0, 1.0],
134131
background_color: Some([0.0, 0.0, 0.0, 1.0]),
135-
..FragmentStyle::default()
132+
..SpanStyle::default()
136133
},
137134
)
138-
.new_line()
139-
.build();
135+
.new_line();
136+
sugarloaf.build_text_by_id(TEXT_ID_0);
140137

141-
content.sel(self.second_rich_text).clear();
142-
content
138+
sugarloaf
139+
.text(TEXT_ID_1)
140+
.clear()
143141
.new_line()
144-
.add_text(
142+
.add_span(
145143
"Second Layer",
146-
FragmentStyle {
144+
SpanStyle {
147145
color: [1.0, 1.0, 1.0, 1.0],
148146
background_color: Some([0.0, 0.0, 0.0, 1.0]),
149-
..FragmentStyle::default()
147+
..SpanStyle::default()
150148
},
151149
)
152-
.new_line()
153-
.build();
150+
.new_line();
151+
sugarloaf.build_text_by_id(TEXT_ID_1);
154152

155153
// Add rectangles directly
156-
sugarloaf.rect(10., 10., 120., 100., [1.0, 1.0, 1.0, 1.0], 0.0);
157-
sugarloaf.rect(10., 80., 120., 100., [0.0, 0.0, 0.0, 1.0], 0.0);
158-
sugarloaf.rect(95., 30., 20., 100., [1.0, 1.0, 1.0, 1.0], 0.0);
154+
sugarloaf.rect(None, 10., 10., 120., 100., [1.0, 1.0, 1.0, 1.0], 0.0);
155+
sugarloaf.rect(None, 10., 80., 120., 100., [0.0, 0.0, 0.0, 1.0], 0.0);
156+
sugarloaf.rect(None, 95., 30., 20., 100., [1.0, 1.0, 1.0, 1.0], 0.0);
159157

160158
// Show rich text
161-
sugarloaf.show_rich_text(self.rich_text, 10., 10.);
162-
sugarloaf.show_rich_text(self.second_rich_text, 10., 60.);
163-
sugarloaf.show_rich_text(self.rich_text, 100., 100.);
159+
sugarloaf.set_position(TEXT_ID_0, 10., 10.);
160+
sugarloaf.set_visibility(TEXT_ID_0, true);
161+
sugarloaf.set_position(TEXT_ID_1, 10., 60.);
162+
sugarloaf.set_visibility(TEXT_ID_1, true);
164163

165164
sugarloaf.render();
166165
event_loop.set_control_flow(ControlFlow::Wait);

0 commit comments

Comments
 (0)