Add justification buttons to editor-libcosmic
This commit is contained in:
parent
59e89bdbaa
commit
2442422762
5 changed files with 42 additions and 5 deletions
|
|
@ -15,7 +15,7 @@ log = "0.4"
|
|||
|
||||
[dependencies.libcosmic]
|
||||
git = "https://github.com/pop-os/libcosmic"
|
||||
rev = "5fe44511"
|
||||
rev = "2dde95ee"
|
||||
default-features = false
|
||||
features = ["wgpu", "winit"]
|
||||
#path = "../../../libcosmic"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use cosmic::{
|
|||
Element,
|
||||
};
|
||||
use cosmic_text::{
|
||||
Attrs, AttrsList, Buffer, Edit, FontSystem, Metrics, SyntaxEditor, SyntaxSystem, Wrap,
|
||||
Align, Attrs, AttrsList, Buffer, Edit, FontSystem, Metrics, SyntaxEditor, SyntaxSystem, Wrap,
|
||||
};
|
||||
use std::{env, fs, path::PathBuf, sync::Mutex};
|
||||
|
||||
|
|
@ -66,6 +66,7 @@ pub enum Message {
|
|||
Monospaced(bool),
|
||||
MetricsChanged(Metrics),
|
||||
WrapChanged(Wrap),
|
||||
AlignmentChanged(Align),
|
||||
ThemeChanged(&'static str),
|
||||
}
|
||||
|
||||
|
|
@ -202,6 +203,10 @@ impl Application for Window {
|
|||
let mut editor = self.editor.lock().unwrap();
|
||||
editor.buffer_mut().set_wrap(wrap);
|
||||
}
|
||||
Message::AlignmentChanged(align) => {
|
||||
let mut editor = self.editor.lock().unwrap();
|
||||
editor.buffer_mut().set_align(align);
|
||||
}
|
||||
Message::ThemeChanged(theme) => {
|
||||
self.theme = match theme {
|
||||
"Dark" => Theme::Dark,
|
||||
|
|
@ -282,8 +287,24 @@ impl Application for Window {
|
|||
theme_picker,
|
||||
text("Font Size:"),
|
||||
font_size_picker,
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(8),
|
||||
row![
|
||||
text("Wrap:"),
|
||||
wrap_picker,
|
||||
button(theme::Button::Text)
|
||||
.icon(theme::Svg::Default, "format-justify-left", 20)
|
||||
.on_press(Message::AlignmentChanged(Align::Left)),
|
||||
button(theme::Button::Text)
|
||||
.icon(theme::Svg::Symbolic, "format-justify-center", 20)
|
||||
.on_press(Message::AlignmentChanged(Align::Center)),
|
||||
button(theme::Button::Text)
|
||||
.icon(theme::Svg::Symbolic, "format-justify-right", 20)
|
||||
.on_press(Message::AlignmentChanged(Align::Right)),
|
||||
button(theme::Button::Text)
|
||||
.icon(theme::Svg::SymbolicLink, "format-justify-fill", 20)
|
||||
.on_press(Message::AlignmentChanged(Align::Justified)),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(8),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use cosmic::{
|
|||
widget::{self, tree, Widget},
|
||||
{Color, Element, Length, Point, Rectangle, Size},
|
||||
},
|
||||
iced_winit::renderer::BorderRadius,
|
||||
theme::Theme,
|
||||
};
|
||||
use cosmic_text::{Attrs, AttrsList, BufferLine, Metrics, SwashCache};
|
||||
|
|
@ -140,7 +141,7 @@ where
|
|||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds: layout.bounds(),
|
||||
border_radius: 0.0,
|
||||
border_radius: BorderRadius::default(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use cosmic::{
|
|||
widget::{self, tree, Widget},
|
||||
Padding, {Color, Element, Length, Point, Rectangle, Shell, Size},
|
||||
},
|
||||
iced_winit::renderer::BorderRadius,
|
||||
theme::Theme,
|
||||
};
|
||||
use cosmic_text::{Action, Edit, SwashCache};
|
||||
|
|
@ -142,7 +143,7 @@ where
|
|||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds: layout.bounds(),
|
||||
border_radius: 0.0,
|
||||
border_radius: BorderRadius::default(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
|
|
@ -190,7 +191,7 @@ where
|
|||
+ [self.padding.left as f32, self.padding.top as f32].into(),
|
||||
Size::new(w as f32, h as f32),
|
||||
),
|
||||
border_radius: 0.0,
|
||||
border_radius: BorderRadius::default(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -522,6 +522,20 @@ impl<'a> Buffer<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the current [`Align`]
|
||||
pub fn align(&self) -> Align {
|
||||
self.align
|
||||
}
|
||||
|
||||
/// Set the current [`Wrap`]
|
||||
pub fn set_align(&mut self, align: Align) {
|
||||
if align != self.align {
|
||||
self.align = align;
|
||||
self.relayout();
|
||||
self.shape_until_scroll();
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the current buffer dimensions (width, height)
|
||||
pub fn size(&self) -> (i32, i32) {
|
||||
(self.width, self.height)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue