1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 05:10:03 -04:00

Small tweaks

This commit is contained in:
Emil Ernerfeldt
2019-01-19 10:09:00 -06:00
parent 391abda3d5
commit cd8ca47e76
8 changed files with 625 additions and 13 deletions

View File

@@ -28,6 +28,7 @@ fn show_options(options: &mut LayoutOptions, gui: &mut Region) {
gui.add(Slider::new(&mut options.indent, 0.0, 100.0).text("indent"));
gui.add(Slider::new(&mut options.button_padding.x, 0.0, 20.0).text("button_padding.x"));
gui.add(Slider::new(&mut options.button_padding.y, 0.0, 20.0).text("button_padding.y"));
gui.add(Slider::new(&mut options.clickable_diameter, 0.0, 60.0).text("clickable_diameter"));
gui.add(Slider::new(&mut options.start_icon_width, 0.0, 60.0).text("start_icon_width"));
}
@@ -175,10 +176,10 @@ impl Emigui {
});
region.foldable("Fonts", |gui| {
show_font_texture(self.texture(), gui);
let old_font_sizes = self.data.fonts.sizes();
let mut new_font_sizes = old_font_sizes.clone();
show_font_sizes(&mut new_font_sizes, gui);
show_font_texture(self.texture(), gui);
if *old_font_sizes != new_font_sizes {
let mut new_data = (*self.data).clone();
let fonts = Fonts::from_sizes(new_font_sizes);

View File

@@ -31,7 +31,7 @@ impl Fonts {
let mut sizes = FontSizes::new();
sizes.insert(TextStyle::Body, 18.0);
sizes.insert(TextStyle::Button, 22.0);
sizes.insert(TextStyle::Heading, 30.0);
sizes.insert(TextStyle::Heading, 28.0);
Fonts::from_sizes(sizes)
}

View File

@@ -31,7 +31,7 @@ pub struct LayoutOptions {
/// Anything clickable is (at least) this wide.
pub clickable_diameter: f32,
/// Checkboxed, radio button and foldables have an icon at the start.
/// Checkboxes, radio button and foldables have an icon at the start.
/// The text starts after this many pixels.
pub start_icon_width: f32,
}
@@ -43,7 +43,7 @@ impl Default for LayoutOptions {
button_padding: vec2(5.0, 3.0),
item_spacing: vec2(8.0, 4.0),
indent: 21.0,
clickable_diameter: 38.0,
clickable_diameter: 34.0,
start_icon_width: 20.0,
}
}
@@ -239,7 +239,7 @@ where
align: Align::Min,
cursor: window_pos + window_padding,
bounding_size: vec2(0.0, 0.0),
available_space: vec2(400.0, std::f32::INFINITY), // TODO: popup/tooltip width
available_space: vec2(data.input.screen_size.x.min(350.0), std::f32::INFINITY), // TODO: popup/tooltip width
};
add_contents(&mut popup_region);

View File

@@ -90,6 +90,8 @@ pub fn vec2(x: f32, y: f32) -> Vec2 {
Vec2 { x, y }
}
// ----------------------------------------------------------------------------
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
pub struct Rect {
pub pos: Vec2,
@@ -132,8 +134,36 @@ impl Rect {
pub fn size(&self) -> Vec2 {
self.size
}
// Convenience functions:
pub fn left_top(&self) -> Vec2 {
vec2(self.min().x, self.min().y)
}
pub fn center_top(&self) -> Vec2 {
vec2(self.center().x, self.min().y)
}
pub fn right_top(&self) -> Vec2 {
vec2(self.max().x, self.min().y)
}
pub fn left_center(&self) -> Vec2 {
vec2(self.min().x, self.center().y)
}
pub fn right_center(&self) -> Vec2 {
vec2(self.max().x, self.center().y)
}
pub fn left_bottom(&self) -> Vec2 {
vec2(self.min().x, self.max().y)
}
pub fn center_bottom(&self) -> Vec2 {
vec2(self.center().x, self.max().y)
}
pub fn right_bottom(&self) -> Vec2 {
vec2(self.max().x, self.max().y)
}
}
// ----------------------------------------------------------------------------
pub fn lerp(min: f32, max: f32, t: f32) -> f32 {
(1.0 - t) * min + t * max
}

View File

@@ -81,9 +81,11 @@ impl Widget for Button {
let text_style = TextStyle::Button;
let font = &region.fonts()[text_style];
let (text, text_size) = font.layout_multiline(&self.text, region.width());
let interact =
region.reserve_space(text_size + 2.0 * region.options().button_padding, Some(id));
let text_cursor = interact.rect.min() + region.options().button_padding;
let padding = region.options().button_padding;
let mut size = text_size + 2.0 * padding;
size.y = size.y.max(region.options().clickable_diameter);
let interact = region.reserve_space(size, Some(id));
let text_cursor = interact.rect.left_center() + vec2(padding.x, -0.5 * text_size.y);
region.add_graphic(GuiCmd::Button { interact });
region.add_text(text_cursor, text_style, text, self.text_color);
region.response(interact)