Compare commits
2 Commits
0d52eb4a9f
...
995c544149
| Author | SHA1 | Date |
|---|---|---|
|
|
995c544149 | |
|
|
5a78a5fa65 |
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "focus"
|
name = "stiletto"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Enrico Lumetti <enrico.lumetti@gmail.com>"]
|
authors = ["Enrico Lumetti <enrico.lumetti@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
@ -12,10 +12,10 @@ udev = "0.2"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
errno = "0.2"
|
errno = "0.2"
|
||||||
csv = "1.1"
|
csv = "1.1"
|
||||||
druid = "0.6"
|
druid = { git = "https://github.com/doppioandante/druid", branch = "stylus_events" }
|
||||||
|
|
||||||
[dependencies.gtk]
|
[dependencies.gtk]
|
||||||
version = "0.8.1"
|
version = "0.9.2"
|
||||||
features = ["v3_24"]
|
features = ["v3_24"]
|
||||||
|
|
||||||
[dependencies.gio]
|
[dependencies.gio]
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ fn main() {
|
||||||
gtk::Inhibit(false)
|
gtk::Inhibit(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
let save_button = Button::new_from_icon_name(Some("document-save-symbolic"), gtk::IconSize::Menu);
|
let save_button = Button::from_icon_name(Some("document-save-symbolic"), gtk::IconSize::Menu);
|
||||||
let clear_button = Button::new_from_icon_name(Some("edit-clear-all-symbolic"), gtk::IconSize::Menu);
|
let clear_button = Button::from_icon_name(Some("edit-clear-all-symbolic"), gtk::IconSize::Menu);
|
||||||
let check_button = CheckButton::new_with_label("Join Points");
|
let check_button = CheckButton::with_label("Join Points");
|
||||||
|
|
||||||
let header = HeaderBar::new();
|
let header = HeaderBar::new();
|
||||||
header.pack_start(&save_button);
|
header.pack_start(&save_button);
|
||||||
|
|
@ -142,11 +142,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::println!("{:#?}\n", event.get_device_tool().map(|tool| tool.get_tool_type()));
|
||||||
gtk::Inhibit(capture_event)
|
gtk::Inhibit(capture_event)
|
||||||
//std::println!("{:#?}",event.get_event_type());
|
//std::println!("{:#?}",event.get_event_type());
|
||||||
//std::println!("{:#?}", event.get_source_device().and_then(|d| d.get_property_tool()).map(|t| t.get_tool_type()));
|
//std::println!("{:#?}", event.get_source_device().and_then(|d| d.get_property_tool()).map(|t| t.get_tool_type()));
|
||||||
//std::println!("{:#?}", event.get_device().and_then(|d| d.get_property_tool()).map(|t| t.get_tool_type()));
|
//std::println!("{:#?}", event.get_device().and_then(|d| d.get_property_tool()).map(|t| t.get_tool_type()));
|
||||||
//std::println!("{:#?}\n", event.get_device_tool().map(|tool| tool.get_tool_type()));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
149
src/main.rs
149
src/main.rs
|
|
@ -1,22 +1,137 @@
|
||||||
use druid::widget::{Button, Flex, Label};
|
// Copyright 2019 The Druid Authors.
|
||||||
use druid::{AppLauncher, LocalizedString, PlatformError, Widget, WidgetExt, WindowDesc};
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
fn main() -> Result<(), PlatformError> {
|
//! An example of a custom drawing widget.
|
||||||
let main_window = WindowDesc::new(ui_builder);
|
|
||||||
let data = 0_u32;
|
use druid::kurbo::BezPath;
|
||||||
AppLauncher::with_window(main_window)
|
use druid::piet::{FontFamily, ImageFormat, InterpolationMode};
|
||||||
|
use druid::widget::prelude::*;
|
||||||
|
use druid::{
|
||||||
|
Affine, AppLauncher, ArcStr, Color, FontDescriptor, LocalizedString, Point, Rect, TextLayout,
|
||||||
|
WindowDesc,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CustomWidget;
|
||||||
|
|
||||||
|
impl Widget<String> for CustomWidget {
|
||||||
|
fn event(&mut self, _ctx: &mut EventCtx, event: &Event, _data: &mut String, _env: &Env) {
|
||||||
|
println!("{:?}", event);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lifecycle(
|
||||||
|
&mut self,
|
||||||
|
_ctx: &mut LifeCycleCtx,
|
||||||
|
_event: &LifeCycle,
|
||||||
|
_data: &String,
|
||||||
|
_env: &Env,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, _ctx: &mut UpdateCtx, _old_data: &String, _data: &String, _env: &Env) {}
|
||||||
|
|
||||||
|
fn layout(
|
||||||
|
&mut self,
|
||||||
|
_layout_ctx: &mut LayoutCtx,
|
||||||
|
bc: &BoxConstraints,
|
||||||
|
_data: &String,
|
||||||
|
_env: &Env,
|
||||||
|
) -> Size {
|
||||||
|
// BoxConstraints are passed by the parent widget.
|
||||||
|
// This method can return any Size within those constraints:
|
||||||
|
// bc.constrain(my_size)
|
||||||
|
//
|
||||||
|
// To check if a dimension is infinite or not (e.g. scrolling):
|
||||||
|
// bc.is_width_bounded() / bc.is_height_bounded()
|
||||||
|
bc.max()
|
||||||
|
}
|
||||||
|
|
||||||
|
// The paint method gets called last, after an event flow.
|
||||||
|
// It goes event -> update -> layout -> paint, and each method can influence the next.
|
||||||
|
// Basically, anything that changes the appearance of a widget causes a paint.
|
||||||
|
fn paint(&mut self, ctx: &mut PaintCtx, data: &String, env: &Env) {
|
||||||
|
// Let's draw a picture with Piet!
|
||||||
|
|
||||||
|
// Clear the whole widget with the color of your choice
|
||||||
|
// (ctx.size() returns the size of the layout rect we're painting in)
|
||||||
|
let size = ctx.size();
|
||||||
|
let rect = size.to_rect();
|
||||||
|
ctx.fill(rect, &Color::WHITE);
|
||||||
|
|
||||||
|
// Note: ctx also has a `clear` method, but that clears the whole context,
|
||||||
|
// and we only want to clear this widget's area.
|
||||||
|
|
||||||
|
// Create an arbitrary bezier path
|
||||||
|
let mut path = BezPath::new();
|
||||||
|
path.move_to(Point::ORIGIN);
|
||||||
|
path.quad_to((80.0, 90.0), (size.width, size.height));
|
||||||
|
// Create a color
|
||||||
|
let stroke_color = Color::rgb8(0, 128, 0);
|
||||||
|
// Stroke the path with thickness 1.0
|
||||||
|
ctx.stroke(path, &stroke_color, 1.0);
|
||||||
|
|
||||||
|
// Rectangles: the path for practical people
|
||||||
|
let rect = Rect::from_origin_size((10., 10.), (100., 100.));
|
||||||
|
// Note the Color:rgba8 which includes an alpha channel (7F in this case)
|
||||||
|
let fill_color = Color::rgba8(0x00, 0x00, 0x00, 0x7F);
|
||||||
|
ctx.fill(rect, &fill_color);
|
||||||
|
|
||||||
|
// Text is easy; in real use TextLayout should be stored in the widget
|
||||||
|
// and reused.
|
||||||
|
let mut layout = TextLayout::<ArcStr>::from_text(data.to_owned());
|
||||||
|
layout.set_font(FontDescriptor::new(FontFamily::SERIF).with_size(24.0));
|
||||||
|
layout.set_text_color(fill_color);
|
||||||
|
layout.rebuild_if_needed(ctx.text(), env);
|
||||||
|
|
||||||
|
// Let's rotate our text slightly. First we save our current (default) context:
|
||||||
|
ctx.with_save(|ctx| {
|
||||||
|
// Now we can rotate the context (or set a clip path, for instance):
|
||||||
|
ctx.transform(Affine::rotate(0.1));
|
||||||
|
layout.draw(ctx, (80.0, 40.0));
|
||||||
|
});
|
||||||
|
// When we exit with_save, the original context's rotation is restored
|
||||||
|
|
||||||
|
// Let's burn some CPU to make a (partially transparent) image buffer
|
||||||
|
let image_data = make_image_data(256, 256);
|
||||||
|
let image = ctx
|
||||||
|
.make_image(256, 256, &image_data, ImageFormat::RgbaSeparate)
|
||||||
|
.unwrap();
|
||||||
|
// The image is automatically scaled to fit the rect you pass to draw_image
|
||||||
|
ctx.draw_image(&image, size.to_rect(), InterpolationMode::Bilinear);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let window = WindowDesc::new(|| CustomWidget {}).title(
|
||||||
|
LocalizedString::new("custom-widget-demo-window-title").with_placeholder("Fancy Colors"),
|
||||||
|
);
|
||||||
|
AppLauncher::with_window(window)
|
||||||
.use_simple_logger()
|
.use_simple_logger()
|
||||||
.launch(data)
|
.launch("Druid + Piet".to_string())
|
||||||
|
.expect("launch failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ui_builder() -> impl Widget<u32> {
|
fn make_image_data(width: usize, height: usize) -> Vec<u8> {
|
||||||
// The label text will be computed dynamically based on the current locale and count
|
let mut result = vec![0; width * height * 4];
|
||||||
let text =
|
for y in 0..height {
|
||||||
LocalizedString::new("hello-counter").with_arg("count", |data: &u32, _env| (*data).into());
|
for x in 0..width {
|
||||||
let label = Label::new(text).padding(5.0).center();
|
let ix = (y * width + x) * 4;
|
||||||
let button = Button::new("increment")
|
result[ix] = x as u8;
|
||||||
.on_click(|_ctx, data, _env| *data += 1)
|
result[ix + 1] = y as u8;
|
||||||
.padding(5.0);
|
result[ix + 2] = !(x as u8);
|
||||||
|
result[ix + 3] = 127;
|
||||||
Flex::column().with_child(label).with_child(button)
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue