[refactor] minor code cleanup

This commit is contained in:
Emil Ernerfeldt 2020-05-23 22:10:08 +02:00
parent 19cbe6bd6e
commit 7d0a16d0e8
7 changed files with 24 additions and 31 deletions

View file

@ -78,8 +78,9 @@ Add extremely quick animations for some things, maybe 2-3 frames. For instance:
### Input
* [x] Distinguish between clicks and drags
* [ ] Double-click
* [x] Double-click
* [x] Text
* [ ] Support all mouse buttons
### Debugability / Inspection
* [x] Widget debug rectangles

View file

@ -11,13 +11,3 @@ pub use {
area::Area, collapsing_header::CollapsingHeader, frame::Frame, popup::*, resize::Resize,
scroll_area::ScrollArea, window::Window,
};
// TODO
// pub trait Container {
// fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui));
// }
// pub trait Container {
// fn begin(&mut self, parent: &mut Ui) -> Ui;
// fn end(self, parent: &mut Ui, content: Ui);
// }

View file

@ -335,7 +335,7 @@ fn paint_resize_corner(ui: &mut Ui, interact: &InteractInfo) {
let color = ui.style().interact(interact).stroke_color;
let width = ui.style().interact(interact).stroke_width;
let corner = interact.rect.right_bottom().round(); // TODO: round to pixels
let corner = ui.round_pos_to_pixels(interact.rect.right_bottom());
let mut w = 2.0;
while w < 12.0 {

View file

@ -204,19 +204,6 @@ impl<'open> Window<'open> {
let outer_rect = frame.end(&mut area.content_ui);
// END FRAME --------------------------------
title_bar.ui(
&mut area.content_ui,
outer_rect,
content_rect,
open,
&mut collapsing,
);
area.content_ui
.memory()
.collapsing_headers
.insert(collapsing_id, collapsing);
let interaction = if possible.movable || possible.resizable {
interact(
ctx,
@ -230,6 +217,20 @@ impl<'open> Window<'open> {
} else {
None
};
let hover_interaction = resize_hover(ctx, possible, area_layer, outer_rect);
title_bar.ui(
&mut area.content_ui,
outer_rect,
content_rect,
open,
&mut collapsing,
);
area.content_ui
.memory()
.collapsing_headers
.insert(collapsing_id, collapsing);
if let Some(interaction) = interaction {
paint_frame_interaction(
@ -239,8 +240,7 @@ impl<'open> Window<'open> {
ctx.style().interact.active,
);
} else {
if let Some(hover_interaction) = resize_hover(ctx, possible, area_layer, outer_rect)
{
if let Some(hover_interaction) = hover_interaction {
paint_frame_interaction(
&mut area.content_ui,
outer_rect,
@ -290,6 +290,10 @@ impl WindowInteraction {
pub fn is_resize(&self) -> bool {
self.left || self.right || self.top || self.bottom
}
pub fn is_pure_move(&self) -> bool {
!self.is_resize()
}
}
fn interact(

View file

@ -86,7 +86,7 @@ impl Memory {
let window_interaction = self.window_interaction.take();
if let Some(window_interaction) = window_interaction {
if !window_interaction.is_resize() {
if window_interaction.is_pure_move() {
// Throw windows because it is fun:
let area_layer = window_interaction.area_layer;
let area_state = self.areas.get(area_layer.id).clone();

View file

@ -50,7 +50,6 @@ impl PaintCmd {
}
}
// TODO: rename LineStyle
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct LineStyle {
pub width: f32,

View file

@ -434,7 +434,6 @@ impl Ui {
self.debug_text_at(self.cursor, text);
}
// TODO: AsRef<str>
pub fn debug_text_at(&self, pos: Pos2, text: impl Into<String>) {
self.ctx.debug_text(pos, text);
}
@ -565,7 +564,7 @@ impl Ui {
// draw a grey line on the left to mark the indented section
let line_start = child_rect.min - indent * 0.5;
let line_start = line_start.round(); // TODO: round to pixel instead
let line_start = self.round_pos_to_pixels(line_start);
let line_end = pos2(line_start.x, line_start.y + size.y - 2.0);
self.add_paint_cmd(PaintCmd::line_segment(
[line_start, line_end],