-
Hi, thanks for this amazing library. I'm am new to Rust and egui too. I am trying to make a small widget for Linux. The app is combination of a couple of sliders. I am done with the functionalities, but I am kind of stuck with the look of the app. Here's how it looks as of now: I am trying to:
The code is totally derived from the awesome starter guide use eframe::{egui, epi};
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "persistence", serde(default))] // if we add new fields, give them default values when deserializing old state
pub struct GuiApp {
label: String,
#[cfg_attr(feature = "persistence", serde(skip))]
value: f32,
}
impl Default for GuiApp {
fn default() -> Self {
Self {
label: "Hello World!".to_owned(),
value: 2.7,
}
}
}
impl epi::App for GuiApp {
fn name(&self) -> &str {
"Adjust Brightness"
}
#[cfg(feature = "persistence")]
fn load(&mut self, storage: &dyn epi::Storage) {
*self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
}
#[cfg(feature = "persistence")]
fn save(&mut self, storage: &mut dyn epi::Storage) {
epi::set_value(storage, epi::APP_KEY, self);
}
fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
let Self { label, value } = self;
egui::CentralPanel::default().show(ctx, |ui| {
let highest_val = 1.0;
let response = ui.add(
egui::Slider::new(
value, 0.0..=highest_val
).text("A a").clamp_to_range(true).show_value(false)
);
// to mark the area during development. Will be removed later
ui.painter().rect_stroke(response.rect, 0.0, (1.0, egui::Color32::WHITE));
if response.changed(){
println!(">>>{:?}", value);
// the actions are taken here
}
});
if false {
egui::Window::new("Window").show(ctx, |ui| {
ui.label("Windows can be moved by dragging them.");
ui.label("They are automatically sized based on contents.");
ui.label("You can turn on resizing and scrolling if you like.");
ui.label("You would normally chose either panels OR windows.");
});
}
}
}
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can set the window size in If you want to put the slider between the two letters, you need to move one to the left side. Probably something like this: ui.horizontal(|ui| {
ui.label("A");
let response = ui.add(
egui::Slider::new(
value, 0.0..=highest_val
).text("a").clamp_to_range(true).show_value(false)
);
// etc.
}); |
Beta Was this translation helpful? Give feedback.
You can set the window size in
eframe::NativeOptions
: https://docs.rs/eframe/0.12.0/eframe/struct.NativeOptions.html#structfield.initial_window_sizeIf you want to put the slider between the two letters, you need to move one to the left side. Probably something like this: