Skip to content

Instantly share code, notes, and snippets.

@IronOxidizer
Created December 20, 2020 16:25
Show Gist options
  • Save IronOxidizer/e3191f29a8d725e09cc255ab92e2a91b to your computer and use it in GitHub Desktop.
Save IronOxidizer/e3191f29a8d725e09cc255ab92e2a91b to your computer and use it in GitHub Desktop.
Lensing a non-AppState type causes an error
use druid::{AppLauncher, Widget, WidgetExt, WindowDesc, UnitPoint,
Lens, Data, ExtEventSink, widget::{Flex, Label}};
use std::sync::Arc;
use std::rc::Rc;
#[derive(Clone, Data, Lens)]
struct AppState {
pub event_sink: Arc<ExtEventSink>,
pub current_avatar: Rc<Avatar>
}
#[derive(Clone, Default, Data, Lens)]
struct Avatar {
accountId: u32,
pub displayName: String,
internalName: String,
nameChangeFlag: bool,
percentCompleteForNextLevel: u8,
profileIconId: u32,
puuid: String,
rerollPoints: RerollPoints,
unnamed: bool,
xpSinceLastLevel: u32,
xpUntilNextLevel: u32
}
#[derive(Clone, Default, Debug, Data)]
struct RerollPoints {
currentPoints: u32,
maxRolls: u32,
numberOfRolls: u32,
pointsCostToRoll: u32,
pointsToReroll: u32
}
fn main() {
let root_window = WindowDesc::new(build_root_widget);
let launcher = AppLauncher::with_window(root_window);
let app_state = AppState {
event_sink: Arc::new(launcher.get_external_handle()),
current_avatar: Rc::new(Avatar::default())
};
launcher
.launch(app_state)
.expect("launch failed");
}
fn build_root_widget() -> impl Widget<AppState> {
let label = Label::raw()
.lens(Avatar::displayName)
.padding(4.);
Flex::column()
.with_child(label)
.align_vertical(UnitPoint::CENTER)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment