This commit is contained in:
TimUntersberger 2021-06-25 17:16:44 +02:00
parent 52d44769a3
commit 5c45d36d1a
4 changed files with 27 additions and 13 deletions

View file

@ -6,4 +6,4 @@ edition = "2018"
publish = false
[dependencies]
iced_winit = { path = "../../winit" }
iced = { path = "../.." }

View file

@ -1,7 +1,15 @@
use iced_winit::{button, Align, Button, Column, Element, Application, Settings, Text, Renderer, Program, Command};
use iced::{button, Align, Button, Column, Element, Sandbox, Settings, window::Settings as WindowSettings, Text};
pub fn main() {
Counter::run(Settings::default()).unwrap()
let settings = Settings {
window: WindowSettings {
size: (400, 200),
position: (100, 100),
..Default::default()
},
..Default::default()
};
Counter::run(settings).unwrap()
}
#[derive(Default)]
@ -17,21 +25,16 @@ enum Message {
DecrementPressed,
}
impl Application for Counter {
type Flags = ();
impl Sandbox for Counter {
type Message = Message;
fn new(flags: Self::Flags) -> (Self, Command<Message>) {
(Self::default(), Command::none())
fn new() -> Self {
Self::default()
}
fn title(&self) -> String {
String::from("Counter with winit - Iced")
}
}
impl Program for Counter {
type Renderer = Renderer;
type Message = Message;
fn update(&mut self, message: Message) {
match message {
@ -44,7 +47,7 @@ impl Program for Counter {
}
}
fn view(&mut self) -> Element<Message, Self::Renderer> {
fn view(&mut self) -> Element<Message> {
Column::new()
.padding(20)
.align_items(Align::Center)

View file

@ -6,6 +6,11 @@ pub struct Settings {
/// The initial size of the window.
pub size: (u32, u32),
/// The initial position of the window.
///
/// Note: this gets ignored on the web
pub position: (u32, u32),
/// The minimum size of the window.
pub min_size: Option<(u32, u32)>,
@ -32,6 +37,7 @@ impl Default for Settings {
fn default() -> Settings {
Settings {
size: (1024, 768),
position: (100, 100),
min_size: None,
max_size: None,
resizable: true,
@ -48,6 +54,7 @@ impl From<Settings> for iced_winit::settings::Window {
fn from(settings: Settings) -> Self {
Self {
size: settings.size,
position: settings.position,
min_size: settings.min_size,
max_size: settings.max_size,
resizable: settings.resizable,

View file

@ -35,6 +35,9 @@ pub struct Window {
/// The size of the window.
pub size: (u32, u32),
/// The position of the window.
pub position: (u32, u32),
/// The minimum size of the window.
pub min_size: Option<(u32, u32)>,
@ -75,6 +78,7 @@ impl Window {
window_builder = window_builder
.with_title(title)
.with_inner_size(winit::dpi::LogicalSize { width, height })
.with_outer_position(self.position)
.with_resizable(self.resizable)
.with_decorations(self.decorations)
.with_transparent(self.transparent)