fmt
This commit is contained in:
parent
0264258f03
commit
b6377aa995
|
@ -0,0 +1 @@
|
|||
max_width = 110
|
|
@ -17,11 +17,7 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn window(
|
||||
mut self,
|
||||
title: impl ToString,
|
||||
background_color: webrender::api::ColorF,
|
||||
) -> Self {
|
||||
pub fn window(mut self, title: impl ToString, background_color: webrender::api::ColorF) -> Self {
|
||||
let win = Window::new(title.to_string(), background_color, &self.events_loop);
|
||||
self.windows.insert(win.id(), win);
|
||||
self
|
||||
|
|
|
@ -12,10 +12,8 @@ impl Button {
|
|||
pub fn event(&mut self, event: &glutin::WindowEvent, context: &RenderContext) -> bool {
|
||||
match event {
|
||||
glutin::WindowEvent::CursorMoved { position, .. } => {
|
||||
let new_is_hovered = context.hit_test(
|
||||
WorldPoint::new(position.x as f32, position.y as f32),
|
||||
self.tag,
|
||||
);
|
||||
let new_is_hovered =
|
||||
context.hit_test(WorldPoint::new(position.x as f32, position.y as f32), self.tag);
|
||||
|
||||
if self.is_hovered != new_is_hovered {
|
||||
self.is_hovered = new_is_hovered;
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -15,7 +15,9 @@ type UiSize = euclid::TypedSize2D<f32, LayoutPixel>;
|
|||
|
||||
trait Ui {
|
||||
fn render(&self, rend_ctxt: RenderContext) {}
|
||||
fn measure(&mut self) -> UiSize {UiSize::default()}
|
||||
fn measure(&mut self) -> UiSize {
|
||||
UiSize::default()
|
||||
}
|
||||
fn arrange(&mut self, final_size: UiSize) {}
|
||||
}
|
||||
|
||||
|
@ -31,19 +33,25 @@ pub struct RenderContext<'b> {
|
|||
|
||||
impl<'b> RenderContext<'b> {
|
||||
pub fn new(pipeline_id: PipelineId, dl_builder: &'b mut DisplayListBuilder, window_size: UiSize) -> Self {
|
||||
RenderContext{
|
||||
RenderContext {
|
||||
final_size: window_size,
|
||||
dl_builder,
|
||||
spatial_id: SpatialId::root_reference_frame(pipeline_id)
|
||||
spatial_id: SpatialId::root_reference_frame(pipeline_id),
|
||||
}
|
||||
}
|
||||
|
||||
fn child_context(&'b mut self, final_rect: &LayoutRect) -> Self {
|
||||
let spatial_id = self.dl_builder.push_reference_frame(final_rect, self.spatial_id, TransformStyle::Flat, PropertyBinding::Value(LayoutTransform::default()), ReferenceFrameKind::Transform);
|
||||
RenderContext{
|
||||
|
||||
fn child_context(&'b mut self, final_rect: &LayoutRect) -> Self {
|
||||
let spatial_id = self.dl_builder.push_reference_frame(
|
||||
final_rect,
|
||||
self.spatial_id,
|
||||
TransformStyle::Flat,
|
||||
PropertyBinding::Value(LayoutTransform::default()),
|
||||
ReferenceFrameKind::Transform,
|
||||
);
|
||||
RenderContext {
|
||||
final_size: final_rect.size,
|
||||
dl_builder: self.dl_builder,
|
||||
spatial_id: spatial_id
|
||||
spatial_id: spatial_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,8 +89,7 @@ impl Window {
|
|||
DeviceIntSize::new(size.width as i32, size.height as i32)
|
||||
};
|
||||
let notifier = Box::new(Notifier);
|
||||
let (renderer, sender) =
|
||||
webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
|
||||
let (renderer, sender) = webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
|
||||
let api = sender.create_api();
|
||||
let document_id = api.add_document(device_size, 0);
|
||||
|
||||
|
@ -162,13 +161,7 @@ impl Window {
|
|||
let mut builder = DisplayListBuilder::new(render_context.pipeline_id, layout_size);
|
||||
self.button.render(render_context.pipeline_id, &mut builder);
|
||||
|
||||
txn.set_display_list(
|
||||
render_context.epoch,
|
||||
None,
|
||||
layout_size,
|
||||
builder.finalize(),
|
||||
true,
|
||||
);
|
||||
txn.set_display_list(render_context.epoch, None, layout_size, builder.finalize(), true);
|
||||
txn.set_root_pipeline(render_context.pipeline_id);
|
||||
txn.generate_frame();
|
||||
render_context
|
||||
|
|
Loading…
Reference in New Issue