Mercurial > core / rust/ui/alik/src/lib.rs
changeset 452: |
957915316dea |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Sun, 16 Jun 2024 19:46:56 -0400 |
permissions: |
-rw-r--r-- |
description: |
alik/ui building |
1 //! alik/src/lib.rs --- Alik UI library 7 // We derive Deserialize/Serialize so we can persist app state on shutdown. 8 #[derive(serde::Deserialize, serde::Serialize)] 9 #[serde(default)] // if we add new fields, give them default values when deserializing old state 14 #[serde(skip)] // This how you opt-out of serialization of a field 18 impl Default for AlikApp { 19 fn default() -> Self { 22 label: "Hello World!".to_owned(), 29 /// Called once before the first frame. 30 pub fn new(cc: &eframe::CreationContext<'_>) -> Self { 31 // This is also where you can customize the look and feel of egui using 32 // `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`. 34 // Load previous app state (if any). 35 // Note that you must enable the `persistence` feature for this to work. 36 if let Some(storage) = cc.storage { 37 return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default(); 44 impl eframe::App for AlikApp { 45 /// Called by the frame work to save state before shutdown. 46 fn save(&mut self, storage: &mut dyn eframe::Storage) { 47 eframe::set_value(storage, eframe::APP_KEY, self); 50 /// Called each time the UI needs repainting, which may be many times per 52 fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { 53 // Put your widgets into a `SidePanel`, `TopBottomPanel`, `CentralPanel`, 54 // `Window` or `Area`. For inspiration and more examples, go to https://emilk.github.io/egui 56 egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { 57 // The top panel is often a good place for a menu bar: 59 egui::menu::bar(ui, |ui| { 60 // NOTE: no File->Quit on web pages! 61 let is_web = cfg!(target_arch = "wasm32"); 63 ui.menu_button("File", |ui| { 64 if ui.button("Quit").clicked() { 65 ctx.send_viewport_cmd(egui::ViewportCommand::Close); 71 egui::widgets::global_dark_light_mode_buttons(ui); 75 egui::CentralPanel::default().show(ctx, |ui| { 76 // The central panel the region left after adding TopPanel's and 82 ui.text_edit_singleline(&mut self.label); 85 ui.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("val")); 86 if ui.button("inc").clicked() { 92 ui.add(egui::github_link_file!( 93 "https://vc.compiler.company/comp/core/-/blob/branch/default/rust/", 97 ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { 98 egui::warn_if_debug_build(ui);