enforce and fix a bunch of clippy issues
This commit is contained in:
parent
077cc3d8d1
commit
87e3aacf35
25 changed files with 90 additions and 67 deletions
|
@ -3,6 +3,6 @@ set -eu
|
||||||
|
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
cargo check --all-features
|
cargo check --all-features
|
||||||
cargo clippy
|
cargo clean -p emigui && cargo clippy
|
||||||
|
|
||||||
cargo run --bin example_glium --release
|
cargo run --bin example_glium --release
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/// 0-255 sRGBA
|
/// 0-255 `sRGBA`. TODO: rename `sRGBA` for clarity.
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, serde_derive::Serialize)]
|
||||||
pub struct Color {
|
pub struct Color {
|
||||||
pub r: u8,
|
pub r: u8,
|
||||||
pub g: u8,
|
pub g: u8,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{layout::Direction, *};
|
use crate::{layout::Direction, *};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
open: bool,
|
open: bool,
|
||||||
|
@ -136,8 +136,8 @@ impl CollapsingHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_icon(region: &mut Region, state: &State, interact: &InteractInfo) {
|
fn paint_icon(region: &mut Region, state: &State, interact: &InteractInfo) {
|
||||||
let stroke_color = region.style().interact_stroke_color(&interact);
|
let stroke_color = region.style().interact_stroke_color(interact);
|
||||||
let stroke_width = region.style().interact_stroke_width(&interact);
|
let stroke_width = region.style().interact_stroke_width(interact);
|
||||||
|
|
||||||
let (mut small_icon_rect, _) = region.style().icon_rectangles(interact.rect);
|
let (mut small_icon_rect, _) = region.style().icon_rectangles(interact.rect);
|
||||||
small_icon_rect.set_center(pos2(
|
small_icon_rect.set_center(pos2(
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::{fmt::Debug, hash::Hash, sync::Arc};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
/// Last known pos
|
/// Last known pos
|
||||||
pub pos: Pos2,
|
pub pos: Pos2,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#![allow(unused_variables)] // TODO
|
#![allow(unused_variables)] // TODO
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
size: Vec2,
|
size: Vec2,
|
||||||
}
|
}
|
||||||
|
@ -142,7 +143,7 @@ impl Resize {
|
||||||
self.max_size = self.max_size.max(self.min_size);
|
self.max_size = self.max_size.max(self.min_size);
|
||||||
|
|
||||||
let (is_new, mut state) = match region.memory().resize.get(&id) {
|
let (is_new, mut state) = match region.memory().resize.get(&id) {
|
||||||
Some(state) => (false, state.clone()),
|
Some(state) => (false, *state),
|
||||||
None => {
|
None => {
|
||||||
let default_size = self.default_size.clamp(self.min_size..=self.max_size);
|
let default_size = self.default_size.clamp(self.min_size..=self.max_size);
|
||||||
(true, State { size: default_size })
|
(true, State { size: default_size })
|
||||||
|
@ -234,8 +235,8 @@ impl Resize {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_resize_corner(region: &mut Region, interact: &InteractInfo) {
|
fn paint_resize_corner(region: &mut Region, interact: &InteractInfo) {
|
||||||
let color = region.style().interact_stroke_color(&interact);
|
let color = region.style().interact_stroke_color(interact);
|
||||||
let width = region.style().interact_stroke_width(&interact);
|
let width = region.style().interact_stroke_width(interact);
|
||||||
|
|
||||||
let corner = interact.rect.right_bottom().round(); // TODO: round to pixels
|
let corner = interact.rect.right_bottom().round(); // TODO: round to pixels
|
||||||
let mut w = 2.0;
|
let mut w = 2.0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
/// Positive offset means scrolling down/right
|
/// Positive offset means scrolling down/right
|
||||||
|
|
|
@ -59,15 +59,15 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn memory(&self) -> parking_lot::MutexGuard<Memory> {
|
pub fn memory(&self) -> parking_lot::MutexGuard<'_, Memory> {
|
||||||
self.memory.lock()
|
self.memory.lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn graphics(&self) -> parking_lot::MutexGuard<GraphicLayers> {
|
pub fn graphics(&self) -> parking_lot::MutexGuard<'_, GraphicLayers> {
|
||||||
self.graphics.lock()
|
self.graphics.lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output(&self) -> parking_lot::MutexGuard<Output> {
|
pub fn output(&self) -> parking_lot::MutexGuard<'_, Output> {
|
||||||
self.output.lock()
|
self.output.lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,7 @@ impl Font {
|
||||||
let mut cursor_y = 0.0;
|
let mut cursor_y = 0.0;
|
||||||
let mut text_fragments = Vec::new();
|
let mut text_fragments = Vec::new();
|
||||||
for line in text.split('\n') {
|
for line in text.split('\n') {
|
||||||
let mut line_fragments = self.layout_paragraph_max_width(&line, max_width_in_points);
|
let mut line_fragments = self.layout_paragraph_max_width(line, max_width_in_points);
|
||||||
if let Some(last_word) = line_fragments.last() {
|
if let Some(last_word) = line_fragments.last() {
|
||||||
let line_height = last_word.y_offset + line_spacing;
|
let line_height = last_word.y_offset + line_spacing;
|
||||||
for fragment in &mut line_fragments {
|
for fragment in &mut line_fragments {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
use {parking_lot::Mutex, serde_derive::Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
font::Font,
|
font::Font,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
//! Emigui tracks widgets frame-to-frame using `Id`s.
|
//! Emigui tracks widgets frame-to-frame using `Id`s.
|
||||||
//!
|
//!
|
||||||
//! For instance, if you start dragging a slider one frame, emigui stores
|
//! For instance, if you start dragging a slider one frame, emigui stores
|
||||||
//! the sldiers Id as the current interact_id so that next frame when
|
//! the sldiers Id as the current `interact_id` so that next frame when
|
||||||
//! you move the mouse the same slider changes, even if the mouse has
|
//! you move the mouse the same slider changes, even if the mouse has
|
||||||
//! moved outside the slider.
|
//! moved outside the slider.
|
||||||
//!
|
//!
|
||||||
//! For some widgets `Id`s are also used to GUIpersist some state about the
|
//! For some widgets `Id`s are also used to persist some state about the
|
||||||
//! widgets, such as Window position or wether not a collapsing header region is open.
|
//! widgets, such as Window position or wether not a collapsing header region is open.
|
||||||
//!
|
//!
|
||||||
//! This implicated that the `Id`s must be unqiue.
|
//! This implicated that the `Id`s must be unqiue.
|
||||||
|
@ -24,14 +24,16 @@
|
||||||
//! Then there are widgets that need no identifiers at all, like labels,
|
//! Then there are widgets that need no identifiers at all, like labels,
|
||||||
//! because they have no state nor are interacted with.
|
//! because they have no state nor are interacted with.
|
||||||
//!
|
//!
|
||||||
//! So we have two type of Ids: PositionId and UniqueId.
|
//! So we have two type of Ids: `PositionId` and `UniqueId`.
|
||||||
//! TODO: have separate types for PositionId and UniqueId.
|
//! TODO: have separate types for `PositionId` and `UniqueId`.
|
||||||
|
|
||||||
use std::{collections::hash_map::DefaultHasher, hash::Hash};
|
use std::{collections::hash_map::DefaultHasher, hash::Hash};
|
||||||
|
|
||||||
use crate::math::Pos2;
|
use crate::math::Pos2;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(
|
||||||
|
Clone, Copy, Debug, Hash, Eq, PartialEq, serde_derive::Deserialize, serde_derive::Serialize,
|
||||||
|
)]
|
||||||
pub struct Id(u64);
|
pub struct Id(u64);
|
||||||
|
|
||||||
impl Id {
|
impl Id {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::math::*;
|
||||||
|
|
||||||
/// What the integration gives to the gui.
|
/// What the integration gives to the gui.
|
||||||
/// All coordinates in emigui is in point/logical coordinates.
|
/// All coordinates in emigui is in point/logical coordinates.
|
||||||
#[derive(Clone, Debug, Default, Deserialize)]
|
#[derive(Clone, Debug, Default, serde_derive::Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct RawInput {
|
pub struct RawInput {
|
||||||
/// Is the button currently down?
|
/// Is the button currently down?
|
||||||
|
@ -84,7 +84,7 @@ pub struct GuiInput {
|
||||||
pub events: Vec<Event>,
|
pub events: Vec<Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)]
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde_derive::Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Copy,
|
Copy,
|
||||||
|
@ -97,7 +97,7 @@ pub enum Event {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)]
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde_derive::Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum Key {
|
pub enum Key {
|
||||||
Alt,
|
Alt,
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub enum Layer {
|
||||||
Debug,
|
Debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Each PaintCmd is paired with a clip rectangle.
|
/// Each `PaintCmd` is paired with a clip rectangle.
|
||||||
type PaintList = Vec<(Rect, PaintCmd)>;
|
type PaintList = Vec<(Rect, PaintCmd)>;
|
||||||
|
|
||||||
/// TODO: improve this
|
/// TODO: improve this
|
||||||
|
|
|
@ -1,10 +1,26 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
#![warn(
|
||||||
extern crate rusttype;
|
clippy::all,
|
||||||
extern crate serde;
|
clippy::dbg_macro,
|
||||||
|
clippy::doc_markdown,
|
||||||
#[macro_use] // TODO: get rid of this
|
clippy::empty_enum,
|
||||||
extern crate serde_derive;
|
clippy::enum_glob_use,
|
||||||
|
clippy::filter_map_next,
|
||||||
|
clippy::fn_params_excessive_bools,
|
||||||
|
clippy::imprecise_flops,
|
||||||
|
clippy::lossy_float_literal,
|
||||||
|
clippy::mem_forget,
|
||||||
|
clippy::needless_borrow,
|
||||||
|
clippy::needless_continue,
|
||||||
|
clippy::pub_enum_variant_names,
|
||||||
|
clippy::rest_pat_in_fully_bound_structs,
|
||||||
|
// clippy::suboptimal_flops, // TODO
|
||||||
|
clippy::todo,
|
||||||
|
// clippy::use_self,
|
||||||
|
future_incompatible,
|
||||||
|
nonstandard_style,
|
||||||
|
rust_2018_idioms,
|
||||||
|
)]
|
||||||
|
|
||||||
pub mod color;
|
pub mod color;
|
||||||
pub mod containers;
|
pub mod containers;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign};
|
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign};
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Default, Deserialize, Serialize)]
|
||||||
pub struct Vec2 {
|
pub struct Vec2 {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
Id, Layer, Pos2, Rect,
|
Id, Layer, Pos2, Rect,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
/// The widget being interacted with (e.g. dragged, in case of a slider).
|
/// The widget being interacted with (e.g. dragged, in case of a slider).
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
|
|
||||||
const WHITE_UV: (u16, u16) = (1, 1);
|
const WHITE_UV: (u16, u16) = (1, 1);
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Serialize)]
|
#[derive(Clone, Copy, Debug, Default, serde_derive::Serialize)]
|
||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
/// Pixel coordinates
|
/// Pixel coordinates
|
||||||
pub pos: Pos2,
|
pub pos: Pos2,
|
||||||
|
@ -21,7 +21,7 @@ pub struct Vertex {
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize)]
|
#[derive(Clone, Debug, Default, serde_derive::Serialize)]
|
||||||
pub struct Mesh {
|
pub struct Mesh {
|
||||||
/// Draw as triangles (i.e. the length is a multiple of three)
|
/// Draw as triangles (i.e. the length is a multiple of three)
|
||||||
pub indices: Vec<u32>,
|
pub indices: Vec<u32>,
|
||||||
|
@ -238,7 +238,7 @@ pub enum PathType {
|
||||||
Open,
|
Open,
|
||||||
Closed,
|
Closed,
|
||||||
}
|
}
|
||||||
use self::PathType::*;
|
use self::PathType::{Closed, Open};
|
||||||
|
|
||||||
pub struct MesherOptions {
|
pub struct MesherOptions {
|
||||||
pub anti_alias: bool,
|
pub anti_alias: bool,
|
||||||
|
|
|
@ -50,7 +50,7 @@ where
|
||||||
self.flush(now);
|
self.flush(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mean time difference between values in this MovementTracker.
|
/// Mean time difference between values in this `MovementTracker`.
|
||||||
pub fn mean_time_interval(&self) -> Option<f32> {
|
pub fn mean_time_interval(&self) -> Option<f32> {
|
||||||
if let (Some(first), Some(last)) = (self.values.front(), self.values.back()) {
|
if let (Some(first), Some(last)) = (self.values.front(), self.values.back()) {
|
||||||
let n = self.len();
|
let n = self.len();
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{color::*, containers::*, font::TextFragment, layout::*, widgets::*,
|
||||||
|
|
||||||
/// Represents a region of the screen
|
/// Represents a region of the screen
|
||||||
/// with a type of layout (horizontal or vertical).
|
/// with a type of layout (horizontal or vertical).
|
||||||
/// TODO: make Region a trait so we can have type-safe HorizontalRegion etc?
|
/// TODO: make Region a trait so we can have type-safe `HorizontalRegion` etc?
|
||||||
pub struct Region {
|
pub struct Region {
|
||||||
/// How we access input, output and memory
|
/// How we access input, output and memory
|
||||||
ctx: Arc<Context>,
|
ctx: Arc<Context>,
|
||||||
|
@ -122,11 +122,11 @@ impl Region {
|
||||||
self.ctx.input()
|
self.ctx.input()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn memory(&self) -> parking_lot::MutexGuard<Memory> {
|
pub fn memory(&self) -> parking_lot::MutexGuard<'_, Memory> {
|
||||||
self.ctx.memory()
|
self.ctx.memory()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output(&self) -> parking_lot::MutexGuard<Output> {
|
pub fn output(&self) -> parking_lot::MutexGuard<'_, Output> {
|
||||||
self.ctx.output()
|
self.ctx.output()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ impl Region {
|
||||||
|
|
||||||
/// Will warn if the returned id is not guaranteed unique.
|
/// Will warn if the returned id is not guaranteed unique.
|
||||||
/// Use this to generate widget ids for widgets that have persistent state in Memory.
|
/// Use this to generate widget ids for widgets that have persistent state in Memory.
|
||||||
/// If the id_source is not unique within this region
|
/// If the `id_source` is not unique within this region
|
||||||
/// then an error will be printed at the current cursor position.
|
/// then an error will be printed at the current cursor position.
|
||||||
pub fn make_unique_id<IdSource>(&self, id_source: &IdSource) -> Id
|
pub fn make_unique_id<IdSource>(&self, id_source: &IdSource) -> Id
|
||||||
where
|
where
|
||||||
|
@ -304,7 +304,7 @@ impl Region {
|
||||||
/// # How sizes are negotiated
|
/// # How sizes are negotiated
|
||||||
/// Each widget should have a *minimum desired size* and a *desired size*.
|
/// Each widget should have a *minimum desired size* and a *desired size*.
|
||||||
/// When asking for space, ask AT LEAST for you minimum, and don't ask for more than you need.
|
/// When asking for space, ask AT LEAST for you minimum, and don't ask for more than you need.
|
||||||
/// If you want to fill the space, ask about available_space() and use that.
|
/// If you want to fill the space, ask about `available_space()` and use that.
|
||||||
/// NOTE: we always get the size we ask for (at the moment).
|
/// NOTE: we always get the size we ask for (at the moment).
|
||||||
pub fn reserve_space(&mut self, child_size: Vec2, interaction_id: Option<Id>) -> InteractInfo {
|
pub fn reserve_space(&mut self, child_size: Vec2, interaction_id: Option<Id>) -> InteractInfo {
|
||||||
let child_size = self.round_vec_to_pixels(child_size);
|
let child_size = self.round_vec_to_pixels(child_size);
|
||||||
|
@ -431,7 +431,7 @@ impl Region {
|
||||||
/// Show some text anywhere in the region.
|
/// Show some text anywhere in the region.
|
||||||
/// To center the text at the given position, use `align: (Center, Center)`.
|
/// To center the text at the given position, use `align: (Center, Center)`.
|
||||||
/// If you want to draw text floating on top of everything,
|
/// If you want to draw text floating on top of everything,
|
||||||
/// consider using Context.floating_text instead.
|
/// consider using `Context.floating_text` instead.
|
||||||
pub fn floating_text(
|
pub fn floating_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
pos: Pos2,
|
pos: Pos2,
|
||||||
|
@ -584,10 +584,10 @@ impl Region {
|
||||||
&mut self,
|
&mut self,
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
align: Align,
|
align: Align,
|
||||||
add_contents: impl FnOnce(&mut Region),
|
add_contents: impl FnOnce(&mut Self),
|
||||||
) {
|
) {
|
||||||
let child_rect = Rect::from_min_max(self.cursor, self.bottom_right());
|
let child_rect = Rect::from_min_max(self.cursor, self.bottom_right());
|
||||||
let mut child_region = Region {
|
let mut child_region = Self {
|
||||||
dir,
|
dir,
|
||||||
align,
|
align,
|
||||||
..self.child_region(child_rect)
|
..self.child_region(child_rect)
|
||||||
|
@ -599,26 +599,28 @@ impl Region {
|
||||||
|
|
||||||
/// Temporarily split split a vertical layout into several columns.
|
/// Temporarily split split a vertical layout into several columns.
|
||||||
///
|
///
|
||||||
|
/// ``` ignore
|
||||||
/// region.columns(2, |columns| {
|
/// region.columns(2, |columns| {
|
||||||
/// columns[0].add(emigui::widgets::label!("First column"));
|
/// columns[0].add(emigui::widgets::label!("First column"));
|
||||||
/// columns[1].add(emigui::widgets::label!("Second column"));
|
/// columns[1].add(emigui::widgets::label!("Second column"));
|
||||||
/// });
|
/// });
|
||||||
|
/// ```
|
||||||
pub fn columns<F, R>(&mut self, num_columns: usize, add_contents: F) -> R
|
pub fn columns<F, R>(&mut self, num_columns: usize, add_contents: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [Region]) -> R,
|
F: FnOnce(&mut [Self]) -> R,
|
||||||
{
|
{
|
||||||
// TODO: ensure there is space
|
// TODO: ensure there is space
|
||||||
let spacing = self.style.item_spacing.x;
|
let spacing = self.style.item_spacing.x;
|
||||||
let total_spacing = spacing * (num_columns as f32 - 1.0);
|
let total_spacing = spacing * (num_columns as f32 - 1.0);
|
||||||
let column_width = (self.available_width() - total_spacing) / (num_columns as f32);
|
let column_width = (self.available_width() - total_spacing) / (num_columns as f32);
|
||||||
|
|
||||||
let mut columns: Vec<Region> = (0..num_columns)
|
let mut columns: Vec<Self> = (0..num_columns)
|
||||||
.map(|col_idx| {
|
.map(|col_idx| {
|
||||||
let pos = self.cursor + vec2((col_idx as f32) * (column_width + spacing), 0.0);
|
let pos = self.cursor + vec2((col_idx as f32) * (column_width + spacing), 0.0);
|
||||||
let child_rect =
|
let child_rect =
|
||||||
Rect::from_min_max(pos, pos2(pos.x + column_width, self.bottom_right().y));
|
Rect::from_min_max(pos, pos2(pos.x + column_width, self.bottom_right().y));
|
||||||
|
|
||||||
Region {
|
Self {
|
||||||
id: self.make_child_id(&("column", col_idx)),
|
id: self.make_child_id(&("column", col_idx)),
|
||||||
dir: Direction::Vertical,
|
dir: Direction::Vertical,
|
||||||
..self.child_region(child_rect)
|
..self.child_region(child_rect)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#![allow(clippy::if_same_then_else)]
|
#![allow(clippy::if_same_then_else)]
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{color::*, math::*, types::*};
|
use crate::{color::*, math::*, types::*};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
/// Horizontal and vertical padding within a window frame.
|
/// Horizontal and vertical padding within a window frame.
|
||||||
pub window_padding: Vec2,
|
pub window_padding: Vec2,
|
||||||
|
@ -45,14 +47,14 @@ pub struct Style {
|
||||||
pub debug_regions: bool,
|
pub debug_regions: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
pub corner_radius: f32,
|
pub corner_radius: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Style {
|
impl Default for Style {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Style {
|
Self {
|
||||||
window_padding: vec2(6.0, 6.0),
|
window_padding: vec2(6.0, 6.0),
|
||||||
button_padding: vec2(5.0, 3.0),
|
button_padding: vec2(5.0, 3.0),
|
||||||
item_spacing: vec2(8.0, 4.0),
|
item_spacing: vec2(8.0, 4.0),
|
||||||
|
@ -72,7 +74,7 @@ impl Default for Style {
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Window {
|
Self {
|
||||||
corner_radius: 10.0,
|
corner_radius: 10.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub struct TextureAtlas {
|
||||||
|
|
||||||
impl TextureAtlas {
|
impl TextureAtlas {
|
||||||
pub fn new(width: usize, height: usize) -> Self {
|
pub fn new(width: usize, height: usize) -> Self {
|
||||||
TextureAtlas {
|
Self {
|
||||||
texture: Texture {
|
texture: Texture {
|
||||||
id: 0,
|
id: 0,
|
||||||
width,
|
width,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
color::Color,
|
color::Color,
|
||||||
fonts::TextStyle,
|
fonts::TextStyle,
|
||||||
|
@ -30,7 +32,7 @@ pub enum CursorIcon {
|
||||||
|
|
||||||
impl Default for CursorIcon {
|
impl Default for CursorIcon {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
CursorIcon::Default
|
Self::Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub use {slider::*, text_edit::*};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Anything implementing Widget can be added to a Region with Region::add
|
/// Anything implementing Widget can be added to a Region with `Region::add`
|
||||||
pub trait Widget {
|
pub trait Widget {
|
||||||
fn ui(self, region: &mut Region) -> GuiResponse;
|
fn ui(self, region: &mut Region) -> GuiResponse;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ pub struct Label {
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
pub fn new(text: impl Into<String>) -> Self {
|
pub fn new(text: impl Into<String>) -> Self {
|
||||||
Label {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
text_style: TextStyle::Body,
|
text_style: TextStyle::Body,
|
||||||
|
@ -138,7 +138,7 @@ pub struct Button {
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
pub fn new(text: impl Into<String>) -> Self {
|
pub fn new(text: impl Into<String>) -> Self {
|
||||||
Button {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
text_color: None,
|
text_color: None,
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ pub struct RadioButton {
|
||||||
|
|
||||||
impl RadioButton {
|
impl RadioButton {
|
||||||
pub fn new(checked: bool, text: impl Into<String>) -> Self {
|
pub fn new(checked: bool, text: impl Into<String>) -> Self {
|
||||||
RadioButton {
|
Self {
|
||||||
checked,
|
checked,
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
text_color: None,
|
text_color: None,
|
||||||
|
@ -328,8 +328,8 @@ pub struct Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Separator {
|
impl Separator {
|
||||||
pub fn new() -> Separator {
|
pub fn new() -> Self {
|
||||||
Separator {
|
Self {
|
||||||
line_width: 2.0,
|
line_width: 2.0,
|
||||||
min_length: 6.0,
|
min_length: 6.0,
|
||||||
extra: 0.0,
|
extra: 0.0,
|
||||||
|
|
|
@ -67,12 +67,9 @@ impl<'t> Widget for TextEdit<'t> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Key { key, pressed: true } => {
|
Event::Key { key, pressed: true } => {
|
||||||
match key {
|
if *key == Key::Backspace {
|
||||||
Key::Backspace => {
|
|
||||||
self.text.pop(); // TODO: unicode aware
|
self.text.pop(); // TODO: unicode aware
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
#![allow(clippy::single_match)]
|
||||||
mod painter;
|
mod painter;
|
||||||
|
|
||||||
pub use painter::Painter;
|
pub use painter::Painter;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#[allow(clippy::single_match)]
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
|
|
Loading…
Reference in a new issue