mirror of
https://gitlab.com/erkanisik/yali-rs.git
synced 2026-09-28 07:53:43 +00:00
fix: make language selector combobox and dropdown theme-aware (dark/light)
This commit is contained in:
+12
-2
@@ -1,5 +1,5 @@
|
|||||||
use eframe::egui::{self, Rect, Vec2};
|
use eframe::egui::{self, Rect, Vec2};
|
||||||
use super::combobox_stil::{draw_gradient_bg, DROPDOWN_TEXT_COLOR};
|
use super::combobox_stil::draw_gradient_bg;
|
||||||
|
|
||||||
/// Stil uygulanmış ComboBox oluşturur (genişlik ayarı yapılmaz, Grid içinde kullanım için).
|
/// Stil uygulanmış ComboBox oluşturur (genişlik ayarı yapılmaz, Grid içinde kullanım için).
|
||||||
pub fn combo_box(
|
pub fn combo_box(
|
||||||
@@ -48,13 +48,14 @@ pub fn selectable_value<T: PartialEq>(
|
|||||||
|
|
||||||
draw_gradient_bg(ui, rect);
|
draw_gradient_bg(ui, rect);
|
||||||
|
|
||||||
|
let text_color = combobox_stil_text_color(ui);
|
||||||
let painter = ui.painter();
|
let painter = ui.painter();
|
||||||
painter.text(
|
painter.text(
|
||||||
egui::pos2(rect.left() + 6.0, rect.center().y),
|
egui::pos2(rect.left() + 6.0, rect.center().y),
|
||||||
egui::Align2::LEFT_CENTER,
|
egui::Align2::LEFT_CENTER,
|
||||||
label,
|
label,
|
||||||
egui::FontId::proportional(14.0),
|
egui::FontId::proportional(14.0),
|
||||||
DROPDOWN_TEXT_COLOR,
|
text_color,
|
||||||
);
|
);
|
||||||
|
|
||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
@@ -63,6 +64,15 @@ pub fn selectable_value<T: PartialEq>(
|
|||||||
response.on_hover_cursor(egui::CursorIcon::PointingHand)
|
response.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn combobox_stil_text_color(ui: &egui::Ui) -> egui::Color32 {
|
||||||
|
let bg = ui.visuals().panel_fill;
|
||||||
|
if bg.r() < 128 && bg.g() < 128 && bg.b() < 128 {
|
||||||
|
egui::Color32::from_rgb(230, 230, 240)
|
||||||
|
} else {
|
||||||
|
egui::Color32::from_rgb(50, 50, 50)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// ComboBox dropdown öğesi — özel içerik çizmek için (ör. bayrak + metin).
|
/// ComboBox dropdown öğesi — özel içerik çizmek için (ör. bayrak + metin).
|
||||||
/// `add_contents` callback'i verilen `Rect` içine içerik ekler.
|
/// `add_contents` callback'i verilen `Rect` içine içerik ekler.
|
||||||
pub fn selectable_value_custom<R>(
|
pub fn selectable_value_custom<R>(
|
||||||
|
|||||||
+35
-32
@@ -1,64 +1,67 @@
|
|||||||
use eframe::egui::{self, Color32, Rect, Stroke};
|
use eframe::egui::{self, Color32, Rect, Stroke};
|
||||||
use egui::epaint::Mesh;
|
use egui::epaint::Mesh;
|
||||||
|
|
||||||
// ─── ComboBox Popup Renk Sabitleri ──────────────────────────
|
|
||||||
pub const WEAK_BG_INACTIVE: Color32 = Color32::from_rgb(224, 224, 224);
|
|
||||||
pub const WEAK_BG_HOVERED: Color32 = Color32::from_rgb(200, 200, 200);
|
|
||||||
pub const WEAK_BG_ACTIVE: Color32 = Color32::from_rgb(180, 180, 180);
|
|
||||||
|
|
||||||
// ─── Gradient Dropdown Öğesi Renkleri ───────────────────────
|
|
||||||
pub const GRADIENT_TOP: Color32 = Color32::from_rgb(249, 249, 249);
|
|
||||||
pub const GRADIENT_BOT: Color32 = Color32::from_rgb(233, 233, 233);
|
|
||||||
|
|
||||||
// ─── ComboBox Metin Renkleri ────────────────────────────────
|
|
||||||
/// Seçili metin rengi (ComboBox kapalıyken widget üzerinde görünen metin)
|
|
||||||
pub const COMBO_TEXT_COLOR: Color32 = Color32::from_rgb(50, 50, 50);
|
|
||||||
/// Açılır listedeki öğelerin metin rengi
|
|
||||||
pub const DROPDOWN_TEXT_COLOR: Color32 = Color32::from_rgb(50, 50, 50);
|
|
||||||
|
|
||||||
// ─── ComboBox Kenarlık (border) Renkleri ────────────────────
|
|
||||||
/// Üzerine gelindiğinde / tıklanınca kenarlık rengi
|
|
||||||
pub const COMBO_BORDER_ACCENT: Color32 = Color32::from_rgb(155, 155, 155);
|
|
||||||
|
|
||||||
/// Verilen `Visuals` yapısına ComboBox stillerini uygular.
|
/// Verilen `Visuals` yapısına ComboBox stillerini uygular.
|
||||||
pub fn apply_visuals(v: &mut egui::Visuals) {
|
pub fn apply_visuals(v: &mut egui::Visuals) {
|
||||||
v.widgets.inactive.weak_bg_fill = WEAK_BG_INACTIVE;
|
v.widgets.inactive.weak_bg_fill = Color32::from_rgb(224, 224, 224);
|
||||||
v.widgets.hovered.weak_bg_fill = WEAK_BG_HOVERED;
|
v.widgets.hovered.weak_bg_fill = Color32::from_rgb(200, 200, 200);
|
||||||
v.widgets.active.weak_bg_fill = WEAK_BG_ACTIVE;
|
v.widgets.active.weak_bg_fill = Color32::from_rgb(180, 180, 180);
|
||||||
|
|
||||||
v.widgets.inactive.fg_stroke = Stroke::new(1.0, COMBO_TEXT_COLOR);
|
v.widgets.inactive.fg_stroke = Stroke::new(1.0, Color32::from_rgb(50, 50, 50));
|
||||||
v.widgets.hovered.fg_stroke = Stroke::new(1.5, Color32::WHITE);
|
v.widgets.hovered.fg_stroke = Stroke::new(1.5, Color32::WHITE);
|
||||||
v.widgets.active.fg_stroke = Stroke::new(2.0, Color32::WHITE);
|
v.widgets.active.fg_stroke = Stroke::new(2.0, Color32::WHITE);
|
||||||
|
|
||||||
// Kenarlıklar
|
v.widgets.inactive.bg_stroke = Stroke::new(1.0, Color32::from_rgb(155, 155, 155));
|
||||||
v.widgets.inactive.bg_stroke = Stroke::new(1.0, COMBO_BORDER_ACCENT);
|
v.widgets.hovered.bg_stroke = Stroke::new(1.0, Color32::from_rgb(155, 155, 155));
|
||||||
v.widgets.hovered.bg_stroke = Stroke::new(1.0, COMBO_BORDER_ACCENT);
|
v.widgets.active.bg_stroke = Stroke::new(1.0, Color32::from_rgb(155, 155, 155));
|
||||||
v.widgets.active.bg_stroke = Stroke::new(1.0, COMBO_BORDER_ACCENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Açık gri gradyan mesh arkaplanı çizer (dropdown öğeleri için).
|
fn is_dark_ui(ui: &egui::Ui) -> bool {
|
||||||
|
let bg = ui.visuals().panel_fill;
|
||||||
|
bg.r() < 128 && bg.g() < 128 && bg.b() < 128
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gradient_top(ui: &egui::Ui) -> Color32 {
|
||||||
|
if is_dark_ui(ui) {
|
||||||
|
Color32::from_rgb(40, 40, 45)
|
||||||
|
} else {
|
||||||
|
Color32::from_rgb(249, 249, 249)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gradient_bot(ui: &egui::Ui) -> Color32 {
|
||||||
|
if is_dark_ui(ui) {
|
||||||
|
Color32::from_rgb(30, 30, 35)
|
||||||
|
} else {
|
||||||
|
Color32::from_rgb(233, 233, 233)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Açık/koyu temaya uygun gradyan mesh arkaplanı çizer (dropdown öğeleri için).
|
||||||
pub fn draw_gradient_bg(ui: &mut egui::Ui, rect: Rect) {
|
pub fn draw_gradient_bg(ui: &mut egui::Ui, rect: Rect) {
|
||||||
|
let top = gradient_top(ui);
|
||||||
|
let bot = gradient_bot(ui);
|
||||||
let mut mesh = Mesh::default();
|
let mut mesh = Mesh::default();
|
||||||
let idx = mesh.vertices.len() as u32;
|
let idx = mesh.vertices.len() as u32;
|
||||||
mesh.vertices.push(egui::epaint::Vertex {
|
mesh.vertices.push(egui::epaint::Vertex {
|
||||||
pos: egui::pos2(rect.left(), rect.top()),
|
pos: egui::pos2(rect.left(), rect.top()),
|
||||||
uv: egui::pos2(0.0, 0.0),
|
uv: egui::pos2(0.0, 0.0),
|
||||||
color: GRADIENT_TOP,
|
color: top,
|
||||||
});
|
});
|
||||||
mesh.vertices.push(egui::epaint::Vertex {
|
mesh.vertices.push(egui::epaint::Vertex {
|
||||||
pos: egui::pos2(rect.right(), rect.top()),
|
pos: egui::pos2(rect.right(), rect.top()),
|
||||||
uv: egui::pos2(0.0, 0.0),
|
uv: egui::pos2(0.0, 0.0),
|
||||||
color: GRADIENT_TOP,
|
color: top,
|
||||||
});
|
});
|
||||||
mesh.vertices.push(egui::epaint::Vertex {
|
mesh.vertices.push(egui::epaint::Vertex {
|
||||||
pos: egui::pos2(rect.right(), rect.bottom()),
|
pos: egui::pos2(rect.right(), rect.bottom()),
|
||||||
uv: egui::pos2(0.0, 0.0),
|
uv: egui::pos2(0.0, 0.0),
|
||||||
color: GRADIENT_BOT,
|
color: bot,
|
||||||
});
|
});
|
||||||
mesh.vertices.push(egui::epaint::Vertex {
|
mesh.vertices.push(egui::epaint::Vertex {
|
||||||
pos: egui::pos2(rect.left(), rect.bottom()),
|
pos: egui::pos2(rect.left(), rect.bottom()),
|
||||||
uv: egui::pos2(0.0, 0.0),
|
uv: egui::pos2(0.0, 0.0),
|
||||||
color: GRADIENT_BOT,
|
color: bot,
|
||||||
});
|
});
|
||||||
mesh.indices.extend_from_slice(&[idx, idx + 1, idx + 2, idx + 2, idx + 3, idx]);
|
mesh.indices.extend_from_slice(&[idx, idx + 1, idx + 2, idx + 2, idx + 3, idx]);
|
||||||
ui.painter().add(egui::Shape::mesh(mesh));
|
ui.painter().add(egui::Shape::mesh(mesh));
|
||||||
|
|||||||
Reference in New Issue
Block a user