[refactor] minor code cleanup
This commit is contained in:
parent
19cbe6bd6e
commit
7d0a16d0e8
7 changed files with 24 additions and 31 deletions
|
@ -78,8 +78,9 @@ Add extremely quick animations for some things, maybe 2-3 frames. For instance:
|
||||||
|
|
||||||
### Input
|
### Input
|
||||||
* [x] Distinguish between clicks and drags
|
* [x] Distinguish between clicks and drags
|
||||||
* [ ] Double-click
|
* [x] Double-click
|
||||||
* [x] Text
|
* [x] Text
|
||||||
|
* [ ] Support all mouse buttons
|
||||||
|
|
||||||
### Debugability / Inspection
|
### Debugability / Inspection
|
||||||
* [x] Widget debug rectangles
|
* [x] Widget debug rectangles
|
||||||
|
|
|
@ -11,13 +11,3 @@ pub use {
|
||||||
area::Area, collapsing_header::CollapsingHeader, frame::Frame, popup::*, resize::Resize,
|
area::Area, collapsing_header::CollapsingHeader, frame::Frame, popup::*, resize::Resize,
|
||||||
scroll_area::ScrollArea, window::Window,
|
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);
|
|
||||||
// }
|
|
||||||
|
|
|
@ -335,7 +335,7 @@ fn paint_resize_corner(ui: &mut Ui, interact: &InteractInfo) {
|
||||||
let color = ui.style().interact(interact).stroke_color;
|
let color = ui.style().interact(interact).stroke_color;
|
||||||
let width = ui.style().interact(interact).stroke_width;
|
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;
|
let mut w = 2.0;
|
||||||
|
|
||||||
while w < 12.0 {
|
while w < 12.0 {
|
||||||
|
|
|
@ -204,19 +204,6 @@ impl<'open> Window<'open> {
|
||||||
let outer_rect = frame.end(&mut area.content_ui);
|
let outer_rect = frame.end(&mut area.content_ui);
|
||||||
// END FRAME --------------------------------
|
// 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 {
|
let interaction = if possible.movable || possible.resizable {
|
||||||
interact(
|
interact(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -230,6 +217,20 @@ impl<'open> Window<'open> {
|
||||||
} else {
|
} else {
|
||||||
None
|
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 {
|
if let Some(interaction) = interaction {
|
||||||
paint_frame_interaction(
|
paint_frame_interaction(
|
||||||
|
@ -239,8 +240,7 @@ impl<'open> Window<'open> {
|
||||||
ctx.style().interact.active,
|
ctx.style().interact.active,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if let Some(hover_interaction) = resize_hover(ctx, possible, area_layer, outer_rect)
|
if let Some(hover_interaction) = hover_interaction {
|
||||||
{
|
|
||||||
paint_frame_interaction(
|
paint_frame_interaction(
|
||||||
&mut area.content_ui,
|
&mut area.content_ui,
|
||||||
outer_rect,
|
outer_rect,
|
||||||
|
@ -290,6 +290,10 @@ impl WindowInteraction {
|
||||||
pub fn is_resize(&self) -> bool {
|
pub fn is_resize(&self) -> bool {
|
||||||
self.left || self.right || self.top || self.bottom
|
self.left || self.right || self.top || self.bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_pure_move(&self) -> bool {
|
||||||
|
!self.is_resize()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interact(
|
fn interact(
|
||||||
|
|
|
@ -86,7 +86,7 @@ impl Memory {
|
||||||
|
|
||||||
let window_interaction = self.window_interaction.take();
|
let window_interaction = self.window_interaction.take();
|
||||||
if let Some(window_interaction) = window_interaction {
|
if let Some(window_interaction) = window_interaction {
|
||||||
if !window_interaction.is_resize() {
|
if window_interaction.is_pure_move() {
|
||||||
// Throw windows because it is fun:
|
// Throw windows because it is fun:
|
||||||
let area_layer = window_interaction.area_layer;
|
let area_layer = window_interaction.area_layer;
|
||||||
let area_state = self.areas.get(area_layer.id).clone();
|
let area_state = self.areas.get(area_layer.id).clone();
|
||||||
|
|
|
@ -50,7 +50,6 @@ impl PaintCmd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename LineStyle
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
pub struct LineStyle {
|
pub struct LineStyle {
|
||||||
pub width: f32,
|
pub width: f32,
|
||||||
|
|
|
@ -434,7 +434,6 @@ impl Ui {
|
||||||
self.debug_text_at(self.cursor, text);
|
self.debug_text_at(self.cursor, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: AsRef<str>
|
|
||||||
pub fn debug_text_at(&self, pos: Pos2, text: impl Into<String>) {
|
pub fn debug_text_at(&self, pos: Pos2, text: impl Into<String>) {
|
||||||
self.ctx.debug_text(pos, text);
|
self.ctx.debug_text(pos, text);
|
||||||
}
|
}
|
||||||
|
@ -565,7 +564,7 @@ impl Ui {
|
||||||
|
|
||||||
// draw a grey line on the left to mark the indented section
|
// draw a grey line on the left to mark the indented section
|
||||||
let line_start = child_rect.min - indent * 0.5;
|
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);
|
let line_end = pos2(line_start.x, line_start.y + size.y - 2.0);
|
||||||
self.add_paint_cmd(PaintCmd::line_segment(
|
self.add_paint_cmd(PaintCmd::line_segment(
|
||||||
[line_start, line_end],
|
[line_start, line_end],
|
||||||
|
|
Loading…
Reference in a new issue