Merge pull request #49 from hecrj/feature/control-window-title
Allow applications to control the window title
This commit is contained in:
commit
839e039dbf
5 changed files with 64 additions and 18 deletions
|
|
@ -25,6 +25,10 @@ pub enum Message {
|
||||||
impl Application for Example {
|
impl Application for Example {
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
String::from("Scroll - Iced")
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
Message::AddItem => {
|
Message::AddItem => {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ pub enum Message {
|
||||||
impl Application for Todos {
|
impl Application for Todos {
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
String::from("Todos - Iced")
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
Message::InputChanged(value) => {
|
Message::InputChanged(value) => {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@ use iced::{
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let tour = Tour::new();
|
Tour::new().run()
|
||||||
|
|
||||||
tour.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Tour {
|
pub struct Tour {
|
||||||
|
|
@ -35,6 +33,10 @@ impl Tour {
|
||||||
impl Application for Tour {
|
impl Application for Tour {
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
format!("{} - Iced", self.steps.title())
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, event: Message) {
|
fn update(&mut self, event: Message) {
|
||||||
match event {
|
match event {
|
||||||
Message::BackPressed => {
|
Message::BackPressed => {
|
||||||
|
|
@ -52,6 +54,7 @@ impl Application for Tour {
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&mut self) -> Element<Message> {
|
||||||
let Tour {
|
let Tour {
|
||||||
steps,
|
steps,
|
||||||
|
scroll,
|
||||||
back_button,
|
back_button,
|
||||||
next_button,
|
next_button,
|
||||||
..
|
..
|
||||||
|
|
@ -93,7 +96,7 @@ impl Application for Tour {
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.justify_content(Justify::Center)
|
.justify_content(Justify::Center)
|
||||||
.push(
|
.push(
|
||||||
Scrollable::new(&mut self.scroll)
|
Scrollable::new(scroll)
|
||||||
.align_items(Align::Center)
|
.align_items(Align::Center)
|
||||||
.push(element),
|
.push(element),
|
||||||
)
|
)
|
||||||
|
|
@ -178,6 +181,10 @@ impl Steps {
|
||||||
self.current + 1 < self.steps.len()
|
self.current + 1 < self.steps.len()
|
||||||
&& self.steps[self.current].can_continue()
|
&& self.steps[self.current].can_continue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn title(&self) -> &str {
|
||||||
|
self.steps[self.current].title()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Step {
|
enum Step {
|
||||||
|
|
@ -277,6 +284,21 @@ impl<'a> Step {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn title(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Step::Welcome => "Welcome",
|
||||||
|
Step::Radio { .. } => "Radio button",
|
||||||
|
Step::Slider { .. } => "Slider",
|
||||||
|
Step::Text { .. } => "Text",
|
||||||
|
Step::Image { .. } => "Image",
|
||||||
|
Step::RowsAndColumns { .. } => "Rows and columns",
|
||||||
|
Step::Scrollable => "Scrollable",
|
||||||
|
Step::TextInput { .. } => "Text input",
|
||||||
|
Step::Debugger => "Debugger",
|
||||||
|
Step::End => "End",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn can_continue(&self) -> bool {
|
fn can_continue(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Step::Welcome => true,
|
Step::Welcome => true,
|
||||||
|
|
@ -294,30 +316,27 @@ impl<'a> Step {
|
||||||
|
|
||||||
fn view(&mut self, debug: bool) -> Element<StepMessage> {
|
fn view(&mut self, debug: bool) -> Element<StepMessage> {
|
||||||
match self {
|
match self {
|
||||||
Step::Welcome => Self::welcome().into(),
|
Step::Welcome => Self::welcome(),
|
||||||
Step::Radio { selection } => Self::radio(*selection).into(),
|
Step::Radio { selection } => Self::radio(*selection),
|
||||||
Step::Slider { state, value } => Self::slider(state, *value).into(),
|
Step::Slider { state, value } => Self::slider(state, *value),
|
||||||
Step::Text {
|
Step::Text {
|
||||||
size_slider,
|
size_slider,
|
||||||
size,
|
size,
|
||||||
color_sliders,
|
color_sliders,
|
||||||
color,
|
color,
|
||||||
} => Self::text(size_slider, *size, color_sliders, *color).into(),
|
} => Self::text(size_slider, *size, color_sliders, *color),
|
||||||
Step::Image { width, slider } => Self::image(*width, slider).into(),
|
Step::Image { width, slider } => Self::image(*width, slider),
|
||||||
Step::RowsAndColumns {
|
Step::RowsAndColumns {
|
||||||
layout,
|
layout,
|
||||||
spacing_slider,
|
spacing_slider,
|
||||||
spacing,
|
spacing,
|
||||||
} => {
|
} => Self::rows_and_columns(*layout, spacing_slider, *spacing),
|
||||||
Self::rows_and_columns(*layout, spacing_slider, *spacing).into()
|
Step::Scrollable => Self::scrollable(),
|
||||||
}
|
Step::TextInput { value, state } => Self::text_input(value, state),
|
||||||
Step::Scrollable => Self::scrollable().into(),
|
Step::Debugger => Self::debugger(debug),
|
||||||
Step::TextInput { value, state } => {
|
Step::End => Self::end(),
|
||||||
Self::text_input(value, state).into()
|
|
||||||
}
|
|
||||||
Step::Debugger => Self::debugger(debug).into(),
|
|
||||||
Step::End => Self::end().into(),
|
|
||||||
}
|
}
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn container(title: &str) -> Column<'a, StepMessage> {
|
fn container(title: &str) -> Column<'a, StepMessage> {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ pub use platform::*;
|
||||||
pub trait Application {
|
pub trait Application {
|
||||||
type Message: std::fmt::Debug;
|
type Message: std::fmt::Debug;
|
||||||
|
|
||||||
|
fn title(&self) -> String;
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message);
|
fn update(&mut self, message: Self::Message);
|
||||||
|
|
||||||
fn view(&mut self) -> Element<Self::Message>;
|
fn view(&mut self) -> Element<Self::Message>;
|
||||||
|
|
@ -33,6 +35,10 @@ where
|
||||||
type Renderer = Renderer;
|
type Renderer = Renderer;
|
||||||
type Message = A::Message;
|
type Message = A::Message;
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
self.0.title()
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message) {
|
fn update(&mut self, message: Self::Message) {
|
||||||
self.0.update(message);
|
self.0.update(message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ pub trait Application {
|
||||||
|
|
||||||
type Message: std::fmt::Debug;
|
type Message: std::fmt::Debug;
|
||||||
|
|
||||||
|
fn title(&self) -> String;
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message);
|
fn update(&mut self, message: Self::Message);
|
||||||
|
|
||||||
fn view(&mut self) -> Element<Self::Message, Self::Renderer>;
|
fn view(&mut self) -> Element<Self::Message, Self::Renderer>;
|
||||||
|
|
@ -25,12 +27,14 @@ pub trait Application {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
|
let mut title = self.title();
|
||||||
|
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
// TODO: Ask for window settings and configure this properly
|
// TODO: Ask for window settings and configure this properly
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
|
.with_title(&title)
|
||||||
.with_inner_size(winit::dpi::LogicalSize {
|
.with_inner_size(winit::dpi::LogicalSize {
|
||||||
width: 1280.0,
|
width: 1280.0,
|
||||||
height: 1024.0,
|
height: 1024.0,
|
||||||
|
|
@ -112,6 +116,15 @@ pub trait Application {
|
||||||
debug.update_finished();
|
debug.update_finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update window title
|
||||||
|
let new_title = self.title();
|
||||||
|
|
||||||
|
if title != new_title {
|
||||||
|
window.set_title(&new_title);
|
||||||
|
|
||||||
|
title = new_title;
|
||||||
|
}
|
||||||
|
|
||||||
debug.layout_started();
|
debug.layout_started();
|
||||||
let user_interface = UserInterface::build(
|
let user_interface = UserInterface::build(
|
||||||
document(&mut self, size, &mut debug),
|
document(&mut self, size, &mut debug),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue