Struct pushrod::widget::config::Configurable
source · pub struct Configurable { /* private fields */ }Expand description
Structure containing the configuration HashMap.
Implementations§
source§impl Configurable
impl Configurable
sourcepub fn set(&mut self, config: u8, config_value: Config)
pub fn set(&mut self, config: u8, config_value: Config)
Setter master method - use convenience methods instead.
sourcepub fn get(&self, config: u8) -> Option<&Config>
pub fn get(&self, config: u8) -> Option<&Config>
Getter master method - use convenience methods instead.
sourcepub fn set_numeric(&mut self, config: u8, value: u64)
pub fn set_numeric(&mut self, config: u8, value: u64)
Sets a numeric value for a configuration key.
sourcepub fn set_text(&mut self, config: u8, text: String)
pub fn set_text(&mut self, config: u8, text: String)
Sets a text value for a configuration key.
sourcepub fn set_toggle(&mut self, config: u8, flag: bool)
pub fn set_toggle(&mut self, config: u8, flag: bool)
Sets a toggle for a configuration key.
sourcepub fn get_point(&self, config: u8) -> Point
pub fn get_point(&self, config: u8) -> Point
Retrieves a Point for a configuration key. Returns Point::default if not set.
Examples found in repository?
examples/simple.rs (line 269)
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
fn mouse_entered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
// When a mouse enters a widget, the ID will get modified; modify the debug widget
// with the ID that was specified.
let widget_name = String::from(widget_store.get_name_for_widget_id(widget_id));
let widget_point = widget_store
.get_widget_for_id(widget_id)
.borrow_mut()
.config()
.get_point(CONFIG_ORIGIN);
let widget_size = widget_store
.get_widget_for_id(widget_id)
.borrow_mut()
.config()
.get_size(CONFIG_BODY_SIZE);
widget_store
.get_widget_for_name("DebugText1")
.borrow_mut()
.set_config(
CONFIG_DISPLAY_TEXT,
Config::Text(format!("Current Widget: {} ({})", widget_id, widget_name)).clone(),
);
widget_store
.get_widget_for_name("DebugText2")
.borrow_mut()
.set_config(
CONFIG_DISPLAY_TEXT,
Config::Text(format!(
"Dimensions: x={} y={} w={} h={}",
widget_point.x, widget_point.y, widget_size.w, widget_size.h
))
.clone(),
);
}
fn widget_selected(
&mut self,
widget_id: i32,
_button: Button,
selected: bool,
widget_store: &mut WidgetStore,
) {
match widget_store.get_name_for_widget_id(widget_id) {
"AnimateButton1" => {
self.animated = selected;
}
"DebugCheck1" => {
widget_store
.get_widget_for_name("DebugText1")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
widget_store
.get_widget_for_name("DebugText2")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
}
_ => (),
}
}
fn widget_moved(&mut self, widget_id: i32, point: Point, widget_store: &mut WidgetStore) {
match widget_store.get_name_for_widget_id(widget_id) {
"BoxInLayoutWidget3" => {
eprintln!("Reposition text inside BoxInLayoutWidget1");
widget_store
.get_widget_for_name("LeftJustifiedText")
.borrow_mut()
.set_point(CONFIG_ORIGIN, point.x + 16, point.y + 10);
widget_store
.get_widget_for_name("CenterJustifiedText")
.borrow_mut()
.set_point(CONFIG_ORIGIN, point.x + 16, point.y + 100 - 24);
widget_store
.get_widget_for_name("RightJustifiedText")
.borrow_mut()
.set_point(CONFIG_ORIGIN, point.x + 16, point.y + 200 - 54);
let layout_size2 = widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.config()
.get_size(CONFIG_BODY_SIZE);
eprintln!("Reposition text inside BoxInLayoutWidget2");
let box2_point = widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.config()
.get_point(CONFIG_ORIGIN);
widget_store
.get_widget_for_name("MiniBox1")
.borrow_mut()
.set_point(CONFIG_ORIGIN, box2_point.x + 10, box2_point.y + 10);
widget_store
.get_widget_for_name("MiniBox2")
.borrow_mut()
.set_point(
CONFIG_ORIGIN,
box2_point.x + (layout_size2.w / 2) + 4,
box2_point.y + 10,
);
widget_store
.get_widget_for_name("MiniBox3")
.borrow_mut()
.set_point(
CONFIG_ORIGIN,
box2_point.x + 10,
box2_point.y + (layout_size2.h / 2) + 4,
);
widget_store
.get_widget_for_name("MiniBox4")
.borrow_mut()
.set_point(
CONFIG_ORIGIN,
box2_point.x + (layout_size2.w / 2) + 4,
box2_point.y + (layout_size2.h / 2) + 4,
);
}
_ => (),
}
}sourcepub fn get_size(&self, config: u8) -> Size
pub fn get_size(&self, config: u8) -> Size
Retrieves a Size for a configuration key. Returns a Size::default if not set.
Examples found in repository?
examples/simple.rs (line 274)
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
fn mouse_entered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
// When a mouse enters a widget, the ID will get modified; modify the debug widget
// with the ID that was specified.
let widget_name = String::from(widget_store.get_name_for_widget_id(widget_id));
let widget_point = widget_store
.get_widget_for_id(widget_id)
.borrow_mut()
.config()
.get_point(CONFIG_ORIGIN);
let widget_size = widget_store
.get_widget_for_id(widget_id)
.borrow_mut()
.config()
.get_size(CONFIG_BODY_SIZE);
widget_store
.get_widget_for_name("DebugText1")
.borrow_mut()
.set_config(
CONFIG_DISPLAY_TEXT,
Config::Text(format!("Current Widget: {} ({})", widget_id, widget_name)).clone(),
);
widget_store
.get_widget_for_name("DebugText2")
.borrow_mut()
.set_config(
CONFIG_DISPLAY_TEXT,
Config::Text(format!(
"Dimensions: x={} y={} w={} h={}",
widget_point.x, widget_point.y, widget_size.w, widget_size.h
))
.clone(),
);
}
fn widget_selected(
&mut self,
widget_id: i32,
_button: Button,
selected: bool,
widget_store: &mut WidgetStore,
) {
match widget_store.get_name_for_widget_id(widget_id) {
"AnimateButton1" => {
self.animated = selected;
}
"DebugCheck1" => {
widget_store
.get_widget_for_name("DebugText1")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
widget_store
.get_widget_for_name("DebugText2")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
}
_ => (),
}
}
fn widget_moved(&mut self, widget_id: i32, point: Point, widget_store: &mut WidgetStore) {
match widget_store.get_name_for_widget_id(widget_id) {
"BoxInLayoutWidget3" => {
eprintln!("Reposition text inside BoxInLayoutWidget1");
widget_store
.get_widget_for_name("LeftJustifiedText")
.borrow_mut()
.set_point(CONFIG_ORIGIN, point.x + 16, point.y + 10);
widget_store
.get_widget_for_name("CenterJustifiedText")
.borrow_mut()
.set_point(CONFIG_ORIGIN, point.x + 16, point.y + 100 - 24);
widget_store
.get_widget_for_name("RightJustifiedText")
.borrow_mut()
.set_point(CONFIG_ORIGIN, point.x + 16, point.y + 200 - 54);
let layout_size2 = widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.config()
.get_size(CONFIG_BODY_SIZE);
eprintln!("Reposition text inside BoxInLayoutWidget2");
let box2_point = widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.config()
.get_point(CONFIG_ORIGIN);
widget_store
.get_widget_for_name("MiniBox1")
.borrow_mut()
.set_point(CONFIG_ORIGIN, box2_point.x + 10, box2_point.y + 10);
widget_store
.get_widget_for_name("MiniBox2")
.borrow_mut()
.set_point(
CONFIG_ORIGIN,
box2_point.x + (layout_size2.w / 2) + 4,
box2_point.y + 10,
);
widget_store
.get_widget_for_name("MiniBox3")
.borrow_mut()
.set_point(
CONFIG_ORIGIN,
box2_point.x + 10,
box2_point.y + (layout_size2.h / 2) + 4,
);
widget_store
.get_widget_for_name("MiniBox4")
.borrow_mut()
.set_point(
CONFIG_ORIGIN,
box2_point.x + (layout_size2.w / 2) + 4,
box2_point.y + (layout_size2.h / 2) + 4,
);
}
_ => (),
}
}
fn widget_resized(&mut self, widget_id: i32, _size: Size, widget_store: &mut WidgetStore) {
match widget_store.get_name_for_widget_id(widget_id) {
"BoxInLayoutWidget3" => {
let layout_size = widget_store
.get_widget_for_name("BoxInLayoutWidget1")
.borrow_mut()
.config()
.get_size(CONFIG_BODY_SIZE);
eprintln!("Resize text inside BoxInLayoutWidget1");
widget_store
.get_widget_for_name("LeftJustifiedText")
.borrow_mut()
.set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);
widget_store
.get_widget_for_name("CenterJustifiedText")
.borrow_mut()
.set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);
widget_store
.get_widget_for_name("RightJustifiedText")
.borrow_mut()
.set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);
let layout_size2 = widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.config()
.get_size(CONFIG_BODY_SIZE);
eprintln!("Resize boxes inside BoxInLayoutWidget2: {:?}", layout_size2);
widget_store
.get_widget_for_name("MiniBox1")
.borrow_mut()
.set_size(
CONFIG_BODY_SIZE,
(layout_size2.w / 2) - 12,
(layout_size2.h / 2) - 12,
);
widget_store
.get_widget_for_name("MiniBox2")
.borrow_mut()
.set_size(
CONFIG_BODY_SIZE,
(layout_size2.w / 2) - 12,
(layout_size2.h / 2) - 12,
);
widget_store
.get_widget_for_name("MiniBox3")
.borrow_mut()
.set_size(
CONFIG_BODY_SIZE,
(layout_size2.w / 2) - 12,
(layout_size2.h / 2) - 12,
);
widget_store
.get_widget_for_name("MiniBox4")
.borrow_mut()
.set_size(
CONFIG_BODY_SIZE,
(layout_size2.w / 2) - 12,
(layout_size2.h / 2) - 12,
);
}
_ => (),
}
}sourcepub fn get_color(&self, config: u8) -> Color
pub fn get_color(&self, config: u8) -> Color
Retrieves a Color for a configuration key. Returns white if not set.
sourcepub fn get_numeric(&self, config: u8) -> u64
pub fn get_numeric(&self, config: u8) -> u64
Retrieves a numeric value for a configuration key. Returns 0 if not set.
sourcepub fn get_text(&self, config: u8) -> String
pub fn get_text(&self, config: u8) -> String
Retrieves text for a configuration key. Returns a blank string if not set.
sourcepub fn get_toggle(&self, config: u8) -> bool
pub fn get_toggle(&self, config: u8) -> bool
Retrieves a boolean toggle for a configuration key. Returns false if not set.
Examples found in repository?
examples/simple.rs (line 75)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn widget_clicked(&mut self, widget_id: i32, button: Button, widget_store: &mut WidgetStore) {
match button {
Button::Mouse(mouse_button) => {
if mouse_button != MouseButton::Left {
return;
}
}
_ => (),
}
match widget_store.get_name_for_widget_id(widget_id) {
"BoxInLayoutWidgetButton1" => {
let state = widget_store
.get_widget_for_name("BoxInLayoutWidget1")
.borrow_mut()
.config()
.get_toggle(CONFIG_WIDGET_HIDDEN);
let button_text = if state == true {
String::from("Hide")
} else {
String::from("Show")
};
widget_store
.get_widget_for_name("BoxInLayoutWidgetButton1")
.borrow_mut()
.set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));
widget_store
.get_widget_for_name("BoxInLayoutWidget1")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_HIDDEN, !state);
widget_store.invalidate_all_widgets();
}
"BoxInLayoutWidgetButton2" => {
let state = widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.config()
.get_toggle(CONFIG_WIDGET_DISABLED);
let button_text = if state == true {
String::from("Disable")
} else {
String::from("Enable")
};
widget_store
.get_widget_for_name("BoxInLayoutWidgetButton2")
.borrow_mut()
.set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));
widget_store
.get_widget_for_name("BoxInLayoutWidget2")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_DISABLED, !state);
widget_store
.get_widget_for_name("MiniBox1")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_DISABLED, !state);
widget_store
.get_widget_for_name("MiniBox2")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_DISABLED, !state);
widget_store
.get_widget_for_name("MiniBox3")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_DISABLED, !state);
widget_store
.get_widget_for_name("MiniBox4")
.borrow_mut()
.set_toggle(CONFIG_WIDGET_DISABLED, !state);
widget_store.invalidate_all_widgets();
}
"BoxInLayoutWidgetButton3" => {
widget_store
.get_widget_for_name("BoxInLayoutWidget3")
.borrow_mut()
.set_config(
CONFIG_MAIN_COLOR,
Config::Color([
(rand::random::<u8>() as f32 / 255.0),
(rand::random::<u8>() as f32 / 255.0),
(rand::random::<u8>() as f32 / 255.0),
1.0,
]),
);
}
"RandomColorButton2" => match button {
Button::Mouse(mouse_button) => {
if mouse_button == MouseButton::Left {
widget_store
.get_widget_for_name("ProgressWidget")
.borrow_mut()
.set_config(
CONFIG_SECONDARY_COLOR,
Config::Color([
(rand::random::<u8>() as f32 / 255.0),
(rand::random::<u8>() as f32 / 255.0),
(rand::random::<u8>() as f32 / 255.0),
1.0,
]),
);
}
}
_ => (),
},
_ => (),
}
}Auto Trait Implementations§
impl Freeze for Configurable
impl RefUnwindSafe for Configurable
impl Send for Configurable
impl Sync for Configurable
impl Unpin for Configurable
impl UnwindSafe for Configurable
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more